Application Notes M16C/26A Group Sample Program (Calendar) 1. Summary This sample program provides the functionality of a calendar by using the Renesas Starter Kit for M16C/26A (R0K33026AS000BE) and an extension board. Specifically, it creates a calendar that shows a date of the day on liquid crystal display. (Dates from January 1, 2000 to December 31, 2099, including leap years, are supported.) Switches on the extension board (SW1–SW16) are used to set a date (year, month and day) and a day of the week. Calendar display 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.) REJ05B0813-0120 Rev.1.20 2007.11 Page 1 of 17 M16C/26A Group Sample Program (Calendar) 3. Port Arrangement The key matrix is the facility mounted on an extension board for the Renesas Starter Kit. To use this facility, connect an extension board to the Starter Kit. LCD P74 KEY P75 P76 P77 P104 P91 LCD E P90 LCD_RS P63 LCD_D7 P62 LCD_D6 P61 LCD D5 P60 LCD_D4 - - - - - - - - - - - P105 P106 P107 10MHz Xin M30260F8AGP Figure 1 Port Assignment REJ05B0813-0120 Rev.1.20 2007.11 Page 2 of 17 M16C/26A Group Sample Program (Calendar) 4. Operational Outline A calendar is created that shows a date of the day on liquid crystal display. (Dates from January 1, 2000 to December 31, 2099, including leap years, are supported.) Press the decision switch (SW16) to enter the setup mode. First, fix a “year” using the UP switch (SW13), DOWN switch (SW14) and numeric switches 0 through 9. Next, change a “month” and “day” using the UP switch (SW13) and DOWN switch (SW14). When a “day” is fixed, a “day of the week” is automatically displayed, by which the setup mode is exited. Pressing the UP switch changes the date to a date of the next day. Pressing the DOWN switch reverts the date to a date of the preceding day. Pressing the CLR switch initializes the display and date. LCD SW1 7 SW2 4 SW3 1 SW4 SW5 8 SW6 5 SW7 2 SW8 0 SW9 SW13 9 UP SW10 SW14 6 DOWN SW11 SW15 3 SW12 SW16 CLR PRESS Note: In this program, pressing two or more switches at the same time has no effect (i.e., ignored). • 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, key scan, and LCD display management are performed using this timer. REJ05B0813-0120 Rev.1.20 2007.11 Page 3 of 17 M16C/26A Group Sample Program (Calendar) 5. Operational Specification (1) Reset switch depressed (1) Immediately after the reset switch is pressed, the upper row shows “----” and the lower row shows “----- --.” - - - - - - - - (2) Pressing the decision switch (SW16) puts the program into the “year” setup mode. - - - While setting is in progress, the “year” displayed on LCD flashes at 1 Hz. (2) Decision switch (3) The UP switch (SW13) increments by 1 and the DOWN switch depressed, with “year” (SW14) decrements by 1. The numeric switches input a numeral directly, which is shown on LCD. 2 0 00 00 The “year” is designated by only 2 lower digits of the calendar year. [Operational specification of the UP and DOWN switches] - - - - (3) UP/DOWN - - - and numeric When a maximum value is reached, a minimum value returns. (2099 - 2000) (4) Decision switch depressed, When a minimum value is reached, a maximum value with “month” setup mode returns. (2000 - 2099) If either switch is held down for 1 second or more, the 2 0 0 6 (5) UP/DOWN numeral continuously goes UP (or DOWN) every 100 ms. [Operational specification of the numeric switches] JJ aa nn - - - - switch The LCD display shifts to the left each time a switch is nput. Numerals can be input in the range 0 to 99. (6) Decision switch depressed, If any value is decided outside the input range, it reverts to with “day” setup mode entered the minimum value (2000). (4) Pressing the decision switch (SW16) fixes the “year,” by which 2 0 0 6 the program is placed into the “month” setup mode (7) UP/DOWN *While setting is in progress, the “month” displayed on LCD flashes at 1 Hz. A p r 00 11 (5) The UP switch (SW13) increments by 1 and the DOWN switch - - switch (8) Decision switch (SW14) decrements by 1. depressed, with calendar The numeric switches have no effect. The month is shown by Jan through Dec. (6) Pressing the decision switch (SW16) fixes the “month,” by which the program is placed into the “day” setup mode. d t d 2 0 0 6 (9) UP/DOWN A p r 0 1 S a switch *While setting is in progress, the “day” displayed on LCD flashes at 1. (10) CLR switch (7) The UP switch (SW13) increments by 1 and the DOWN switch (SW14) decrements by 1. The numeric switches have no effect. Numerals are displayed by 01 through 31. (8) Pressing the decision switch (SW16) fixes the “day” and at the - - - - - - - - - - - same time shows a day of the week on LCD. The program goes to calendar mode. (9) In calendar mode, the UP switch (SW13) increments the date by 1 and the DOWN switch (SW14) decrements the date by 1. (10) The CLR switch (SW12) moves the program to the initial setup screen. Note: The displayable range is January 1, 2000 to December 31, 2099. REJ05B0813-0120 Rev.1.20 2007.11 Page 4 of 17 M16C/26A Group Sample Program (Calendar) 6. Definition of the RSK Functionality and the RSK_LIB APIs and Common Functions Used by the Calendar 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 _USE_KEY /* A key matrix continues pushing and existence is defined.*/ /*When not using -USE_KEY_CONTINU is made a comment. */ #define _USE_KEY_CONTINU #if defined _USE_KEY_CONTINU #define _KEY_CONTEINU_ON (( char ) 1 ) #define _CONTINU_SW1 _KEY_CONTEINU_OFF #define _CONTINU_SW2 _KEY_CONTEINU_OFF #define _CONTINU_SW3 _KEY_CONTEINU_OFF #define _CONTINU_SW4 _KEY_CONTEINU_OFF #define _CONTINU_SW5 _KEY_CONTEINU_OFF #define _CONTINU_SW6 _KEY_CONTEINU_OFF #define _CONTINU_SW7 _KEY_CONTEINU_OFF #define _CONTINU_SW8 _KEY_CONTEINU_OFF #define _CONTINU_SW9 _KEY_CONTEINU_OFF #define _CONTINU_SW10 _KEY_CONTEINU_OFF #define _CONTINU_SW11 _KEY_CONTEINU_OFF #define _CONTINU_SW12 _KEY_CONTEINU_OFF #define _CONTINU_SW13 _KEY_CONTEINU_ON Continuous UP/DOWN key depressions are accepted. #define _CONTINU_SW14 _KEY_CONTEINU_ON #define _CONTINU_SW15 _KEY_CONTEINU_OFF #define _CONTINU_SW16 _KEY_CONTEINU_OFF #else REJ05B0813-0120 Rev.1.20 2007.11 Page 5 of 17 M16C/26A Group Sample Program (Calendar) 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_Get_Key( int *Inkey, int *ERcode ); ApiStatusType RL_Putc_Lcd( char Ylocation, char outc, int *ERcode ); ApiStatusType RL_Puts_LcdLoc( char Xlocation, char Ylocation, char RvTime, const char far* outc, int *ERcode ); void RL_ibytetoa( char Val, char *Str ); void RL_ErrorHook( int FuncNo, int ErrorNo ); For details about the APIs and common functions used by the sample program (calendar), see the Renesas Starter Kit Library V.1.00 Reference Manual. REJ05B0813-0120 Rev.1.20 2007.11 Page 6 of 17 M16C/26A Group Sample Program (Calendar) 7. Flowchart Calendar Clear display on LCD Request timer setup Start timers Show the initial screen Input keys Process date setup Function call by a state transition Process display REJ05B0813-0120 Rev.1.20 2007.11 Page 7 of 17 M16C/26A Group Sample Program (Calendar) 8. Tutorial 1 Launch the HEW by double-clicking its icon. 2 Change the session name from “default Session” to “SessionM16C_E8_System.” REJ05B0813-0120 Rev.1.20 2007.11 Page 8 of 17 M16C/26A Group Sample Program (Calendar) 3 Select “M30260F8A” for Device. Select “Download emulator firmware” for Mode. REJ05B0813-0120 Rev.1.20 2007.11 Page 9 of 17 M16C/26A Group Sample Program (Calendar) Check the box labeled “Power supply is carried out. (MAX 300mA)” and then select “5.0V.” REJ05B0813-0120 Rev.1.20 2007.11 Page 10 of 17 M16C/26A Group Sample Program (Calendar) 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. REJ05B0813-0120 Rev.1.20 2007.11 Page 11 of 17 M16C/26A Group Sample Program (Calendar) 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. REJ05B0813-0120 Rev.1.20 2007.11 Page 12 of 17 M16C/26A Group Sample Program (Calendar) 6 7 Click “Start after Reset” to start program execution. Please do "Cancellation" when "The file is opened" window opens. REJ05B0813-0120 Rev.1.20 2007.11 Page 13 of 17 M16C/26A Group Sample Program (Calendar) 9. Example Circuit 10. Part List Part name Part No. Q’ty Manufacturer Type number Tact switch SW1 - SW16 16 OMRON B3FS-1000P Switching diode D2 - D5 4 ROHM 1SS355TE-17 PCB header JA1,JA2 2 Molex 10-88-1261 REJ05B0813-0120 Rev.1.20 2007.11 Value Remark 26-pin Male, 2-row, vertical type Page 14 of 17 M16C/26A Group Sample Program (Calendar) 11. Web Sitet Renesas Technology Web site http://www.renesas.com/ REJ05B0813-0120 Rev.1.20 2007.11 Page 15 of 17 M16C/26A Group Sample Program (Calendar) Revision History Content of revision Rev. Date of issue 1.00 2006.06.30 1.10 2007.07.12 - Contents of presentation improved 1.20 2007.11.29 - RSK_LIB APIs supported REJ05B0813-0120 Rev.1.20 Page - Points First revision issued 2007.11 Page 16 of 17 M16C/26A Group Sample Program (Calendar) REJ05B0813-0120 Rev.1.20 2007.11 Page 17 of 17