RENESAS JA2

Application Notes
M16C/26A Group
Sample Program (Message)
1.
Summary
This sample program receives the text data (message) input from the keyboard of a PC and shows the message on liquid crystal display
while at the same time writing it into the internal flash memory by using the Renesas Starter Kit for M16C/26A (R0K33026AS000BE).
(Straight type)
Received data
The extension board used here is a product
from PI System Co., Ltd.
2.
Introduction
The example described in this document applies to the microcomputers listed below:
Microcomputers: M16C26A
This sample program runs on the Renesas Starter Kit for M16C/26A (R0K33026AS000BE).
Prepare an extension board available for the Renesas Starter Kit or create a circuit similar to the one shown in the example circuit on page
14 and then connect it to the Starter Kit.
This program uses RSK_LIB. For details about RSK_LIB, see the RSK_LIB reference manual. (RSK_LIB is the library software provided
for use with the Renesas Starter Kit for M16C/26A.)
REJ05B0816-0110 Rev.1.10
2007.11
Page 1 of 17
M16C/26A Group
Sample Program (Message)
3.
Port Arrangement
The terminal reception serial port is the facility mounted on an extension board for the Renesas Starter Kit. To use this facility, con
LCD
Terminal data reception
10MHz
P71
Xin
P91
P90
P63
LCD E
P62
LCD D6
P61
P60
LCD D5
LCD RS
LCD D7
LCD D4
P83
M30260F8AGP
REJ05B0816-0110 Rev.1.10
2007.11
Page 2 of 17
M16C/26A Group
Sample Program (Message)
4.
Operational Outline
When a character is input to HyperTerminal (keyboard of a PC), the input character is shown on liquid crystal display and at the same time
stored in the internal flash memory.
Connect the serial port (RS-232C) of a PC and the D-sub connecter on the microcomputer side with a straight cable. When characters are
input to HyperTerminal, the input characters are shown on liquid crystal display on the microcomputer side. If while in this state SW1 is
depressed, the characters shown on liquid crystal display are written into the internal flash memory of the microcomputer. The result of a
write operation is shown on liquid crystal display, indicating whether the characters have been successfully written in.
Then, when the reset switch is depressed, the data written into memory immediately before that is redisplayed on liquid crystal display.
Up to 16 characters can be displayed, not including BS and TAB codes.
D-sub connector
Liquid crystal display (LCD)
Straight cable
Internal flash memory
A,B,C,D,E,F
A
B
C
D
E
F
ABCDEF
Personal computer (PC)
M16C26A
BLOCK A
0F800h
0F810h
SW1/BOOT
When SW1 is depressed, the data displayed
on LCD is saved in the internal flash memory.
The operation described above is accomplished using the following microcomputer facilities:
• Timer A0 (timer mode, main 2 ms cycle)
This timer counts 2 milliseconds using the main clock of the microcomputer as the count source.
It is used as the basic timer of RSK_LIB.
Time management and LCD display management are performed using this timer.
• UART2 (clock-asynchronous serial I/O mode, data reception)
It produces a transfer clock from the main clock of the microcomputer. The data transmitted via HyperTerminal is received using this
clock.
REJ05B0816-0110 Rev.1.10
2007.11
Page 3 of 17
M16C/26A Group
Sample Program (Message)
5.
Operational Specification
(1) Reset switch depressed
(1) Immediately after the reset switch is depressed, a message if any
saved in the data flash area is displayed. If no messages are
saved in the data flash area (data = 0xff), nothing is displayed.
(2) The data received from the terminal is displayed.
Communication format
Baud rate: 9,600 bps
(2) Character code received
(In microcomputer, set at 9,615 bps)
(3) SW1 depressed
Stop bit: 1
a
Parity: None
Number of characters received: 16
b
c
d
e
f
g
h
(data written)
i
(Only up to 16 characters are accepted)
Received character code (written in ASCII)
Control code
(4) Write result displayed
TAB (0x09): Clear the displayed data
Clear the entire received string
P
BS (0x08): Backspace
Delete one character
(3) Press SW1 to write the currently displayed message into the data
r
o
g
r
a
m
s u c c e
s
s
flash.
(4) The result of a write to the data flash is displayed for 1 second.
When successfully written: Displayed as “Program success”
(5) TAB code received
When erase error occurred: Displayed as “Erase error”
When program error occurred: Displayed as “Program error”
(5) TAB code is received, by which the display is cleared.
(6) After the reset switch is depressed, the saved data is displayed.
(6) Reset switch depressed
(saved data displayed)
a
b
c
d
e
f
g
h
i
REJ05B0816-0110 Rev.1.10
2007.11
Page 4 of 17
M16C/26A Group
Sample Program (Message)
6.
Definition of the RSK Functionality and the RSK_LIB APIs and Common Functions Used by
Message Operation
6.1 Definition of the RSK Functionality
RSKdefine.h file
In this application, the following functionalities (those shown in red) are set.
/*********************************************************
The boot information on CPU is defined
Usually, this mode is used
*********************************************************/
//#define _CPU_M16C26A_NORMAL_MOD
/* Use in low power mode can be performed. */
//#define _CPU_M16C26A_32KHZ_MOD
/* Use of access of a flash can be performed. */
#define _CPU_M16C26A_DATAFLASF_USE
/********************************************************
The hardware function which RSK supports is chosen
/********************************************************/
//#define _USE_KEY
//#define _USE_BUZZER
//#define _OPTION_USE_AD
#define _OPTION_USE_COM_RX
//#define _OPTION_USE_COM_TX
//#define _OPTION_USE_INFRAEDRX
//#define _OPTION_USE_INFRAEDTX
#define _OPTION_USE_SW
//#define _OPTION_USE_LED
//#define _OPTION_USE_IO
Individual definition of each selected functionality
#if defined _OPTION_USE_SW
#define _OPTION_USE_PUSHSW1
//#define _OPTION_USE_PUSHSW2
//#define _OPTION_USE_PUSHSW3
#endif
REJ05B0816-0110 Rev.1.10
2007.11
Page 5 of 17
M16C/26A Group
Sample Program (Message)
6.2 APIs and Common Functions Used
ApiStatusType RL_SetTimerReq( unsigned int TimerValue, char TimerMode, int *TimerNo, int *ERcode );
ApiStatusType RL_StartTimer( int TimerNo, int *ERcode );
ApiStatusType RL_CheckTimer( int TimerNo, int *ERcode );
ApiStatusType RL_CancelTimer( int TimerNo, int *ERcode );
ApiStatusType RL_Putc_Lcd( char Ylocation, char outc, int *ERcode );
ApiStatusType RL_Putc_LcdLoc( char Xlocation, char Ylocation, char RvTime, char outc, int *ERcode );
ApiStatusType RL_Open_Com( int bitlenght, int stopbit, int parity, int bps, int *ERcode );
ApiStatusType RL_Getc_Com( char *ComRxChar, int *ERcode );
ApiStatusType RL_GetSwPort( char PortNo, char *Indata, int *ERcode );
void RL_ErrorHook( int FuncNo, int ErrorNo );
For details about the APIs and common functions used by the sample program (message), see the Renesas Starter Kit Library V.1.00
Reference Manual.
REJ05B0816-0110 Rev.1.10
2007.11
Page 6 of 17
M16C/26A Group
Sample Program (Message)
7.
Flowchart
Message
Clear display on LCD
Initialize serial I/O
Load into flash
Show flash data
Wait for first character
received
Process received character
display
Wait for first character
received
Process received character
display
NO
SW1 detected?
YES
Write received character
into flash
REJ05B0816-0110 Rev.1.10
2007.11
Page 7 of 17
M16C/26A Group
Sample Program (Message)
8.
Tutorial
1
Launch the HEW by double-clicking its icon.
2
Change the session name from “default Session” to “SessionM16C_E8_System.”
REJ05B0816-0110 Rev.1.10
2007.11
Page 8 of 17
M16C/26A Group
Sample Program (Message)
3
Select “M30260F8A” for Device.
Select “Download emulator firmware” for Mode.
REJ05B0816-0110 Rev.1.10
2007.11
Page 9 of 17
M16C/26A Group
Sample Program (Message)
Check the box labeled “Power supply is carried out. (MAX 300mA)” and then select “5.0V.”
REJ05B0816-0110 Rev.1.10
2007.11
Page 10 of 17
M16C/26A Group
Sample Program (Message)
4
In the program and the work RAM text boxes of Firmware Location Address, enter “FA0” and “0B8” respectively.
Leave the box labeled “Debug a program using the WDT” unchecked.
REJ05B0816-0110 Rev.1.10
2007.11
Page 11 of 17
M16C/26A Group
Sample Program (Message)
5
Choose Download from the Debug tab and download a module.
The upper-side choices for Download show the location from which a project was downloaded.
REJ05B0816-0110 Rev.1.10
2007.11
Page 12 of 17
M16C/26A Group
Sample Program (Message)
6
7
Click “Start after Reset” to start program execution.
Please do "Cancellation" when "The file is opened" window opens.
REJ05B0816-0110 Rev.1.10
2007.11
Page 13 of 17
M16C/26A Group
Sample Program (Message)
9.
Example Circuit
10. Part List
Part name
Part No.
Q’ty
D-sub connector
J1
1
Manufacturer
Type number
Value
Remark
9pin
Male
RS232C driver
U3
1
Maxim
MAX3221ECAE
Ceramic
C2 - C6
5
Panasonic
ECJ-1VF1H104Z
Chip resistor
R3,R4
2
ROHM
MCR10EZHF103
10k
1/8W, 5%
PCB header
JA1,JA2
2
Molex
10-88-1261
26pin
Male, 2-row, vertical type
100n
capacitor
REJ05B0816-0110 Rev.1.10
2007.11
Page 14 of 17
M16C/26A Group
Sample Program (Message)
11.
Web Sitet
Renesas Technology Web site
http://www.renesas.com/
REJ05B0816-0110 Rev.1.10
2007.11
Page 15 of 17
M16C/26A Group
Sample Program (Message)
Revision History
Content of revision
Rev.
Date of issue
1.00
2006.06.30
-
First revision issued
1.10
2007.11.29
-
RSK_LIB APIs supported
REJ05B0816-0110 Rev.1.10
Page
Points
2007.11
Page 16 of 17
M16C/26A Group
Sample Program (Message)
REJ05B0816-0110 Rev.1.10
2007.11
Page 17 of 17