APPLICATION NOTE R8C/10 GROUP SAMPLE PROGRAM THREE MINUTES TIMER 1. REJ05B0272-0100Z Rev.1.00 Sep 09, 2003 Abstract Three minutes timer uses below functions. · Timer X ( Timer mode ) · Timer Z ( Programmable waveform generation mode ) · Stop mode · INT0 interrupt 2. Introduction Operation (1) Three minutes timer is divided by three mode. · Standby mode · Three minutes timer mode · Power down mode SW2(KI0) Reset cancellation Standby mode Press key 10 seconds key SW3(INT0) without input Press key Three minutes timer mode Power down mode (2) After the reset cancellation, the microcomputer changes to standby mode. (3) When pressing SW2(K10) in standby mode, the microcomputer changes to three minutes timer mode. (4) The microcomputer executes three minutes count operation in three minutes timer mode. (5) When the microcomputer completes three minutes count operation, buzzer sounds two times and the microcomputer places in standby mode. ( Buzzer detailed operation is described as following ) (6) When the microcomputer can not confirm the SW2 (K10) or SW3 (INT0) key press for 10 seconds and changes to power down mode. (7) The microcomputer stops all clock oscillations in power down mode. (change to stop mode ). (8) When the microcomputer acknowledges SW3 (INT0) in power down mode, it places in standby mode. (9) The key input samples by 10ms periods and confirms by three times match (chattering removal ) (10) When the microcomputer places in standby mode by INT0 interrupt in power down mode, it samples key input by 10ms periods after return and confirms the SW3 (INT0) key press by three times match. When it can not confirm the key press, it changes to power down mode. (11) The input key, SW2 (KI0) is L active (L: with pressing H: without pressing ) Rev.1.00 Sep 09, 2003 Page 1 of 22 Sample Program R8C/10 Group Three Minutes Timer (12) In three minutes timer mode, the LED indicates as below. LED indication for elapsed time : LED1(Red) LED2(Green) LED3(Green) More than 2 minutes Turn off 500ms Period 500msPeriod left blinking blinking More than 1 minute left Turn off 500ms Period 500msPeriod blinking blinking More than 10 seconds Turn off 500ms Period Turn off left blinking Less than 10 seconds Turn off 250ms Period Turn off left blinking 0 second left ( during Turn on Turn off Turn off LED4(Green) 500ms Period blinking Turn off Turn off Turn off Turn off buzzer sounds ) (13) In standby mode and power down mode, the LED indicates as below. LED indication for each mode : LED1(Red) In standby mode Turn on In power down mode Turn off LED2(Green) Turn off Turn off LED3(Green) Turn off Turn off LED4(Green) Turn off Turn off (14) LED1, LED2, LED3 and LED4 are L active ( L: turn on H: Turn off ) (15) The buzzer output uses the timer Z programmable waveform mode and outputs from P31 (TZOUT) (16) Waveform outputs in 1 kHz (50% Duty) and the buzzer output timing repeats ON and OFF twice by 200ms periods. Finally again, it turns OFF for 200ms once. Buzzer output timing sequence : Sequence NO 1 Buzzer status ON(Operation) Output time , stop time 200ms Rev.1.00 Sep 09, 2003 Page 2 of 23 2 OFF(Stop) 200ms 3 ON(Operation) 200ms 4 OFF(Stop) 400ms Sample Program 3. 3.1 R8C/10 Group Three Minutes Timer Program Reference Timer X (Timer mode) This sample program uses the timer X (timer mode) and stabilizes the main LOOP period. The setting value of the timer X shows as below. Prescaler X 1/8 16Mhz Timer X 100us Main LOOP 10ms Setting value=(100-1) Setting value=(200-1) Timer X mode register setting b7 b0 0 0 0 01 0 0 0 Timer X mode register [008B16 address] TXMR Timer mode selection INT0/CNTR0 polarity switching bit Timer X count start flag Set to "0" in timer mode set to "1" when count starts Except pulse measurement mode Set to "0" in timer mode Set timer count source setting register b7 b0 0 0 0 10 0 0 1 Timer count source setting register [008E16 address] Timer X count source TCSS Set 01:1/8 Timer Y count source Timer Z count source Reserved bit When setting as above, the timer X interrupt request bit is set to "1" by 10 ms periods. Before this sample program executes process, it confirms to pass 10 ms by the timer X interrupt request bit. When it confirms to pass 10 ms, it sets the timer X interrupt request bit to "0" and executes main process. When it doesn’t confirm to pass 10 ms, it waits for the timer X interrupt request bit to be set to "1". Rev.1.00 Sep 09, 2003 Page 3 of 23 Sample Program 3.2 R8C/10 Group Three Minutes Timer Timer Z (Programmable waveform generation mode) The buzzer makes sounds using the timer Z (programmable waveform generation mode). When setting as below, 1 KHz (50% Duty) is enabled to output. This program sets output level in the timer Y and the timer Z output level latch (TZOPL) of the Z waveform output control register (PUM). Setting the timer Z output level latch to "0" causes outputs "H" for primary period, output "L" for secondary period and outputs "L" when the timer is stopped. Timer Y, Z waveform output control register setting b7 b0 0 0 0 00 0 0 0 Timer Y, Z waveform output control register [008416 address] PUM Set reserved bit to "0" Timer Y related bit Timer Z output level latch outputs "H" for primary periods, outputs "L" for secondary, period, outputs "L" when the timer is stopped INT0 pin one-shot trigger control register INT0 pin one-shot trigger polarity select bit When this function starts counting, it outputs "H" for primary period and "L" for secondary period from P31 (TZOUT). When this function stops counting, it outputs "L" from P31 (TZOUT). The setting value of the timer Z shows as below. PrescalerZ 1/8 16Mhz 12.5us Timer Z primary Buzzer H 500us Setting value=(40-1) Setting value=(25-1) Timer Z secondary Buzzer L 500us Setting value=(40-1) Setting of timer count source setting register b7 b0 Timer count source setting register 0 0 0 10 0 0 1 [008E16 address] Timer X count source Timer Y count source Timer Z count source Set 01:1/8 Reserved bit Timer Y, Z mode register setting b7 b0 0101 Timer Y, Z mode register [008016 address] Timer Y related bit 01:Programmable waveform generation mode Programmable waveform generation mode=1 Timer Z count start flag Rev.1.00 Sep 09, 2003 Page 4 of 23 TYZMR TCSS Sample Program R8C/10 Group Three Minutes Timer 3.3 Stop Mode The microcomputer operates in high-speed mode for three minutes timer. When the microcomputer can not confirm the key pressing for ten seconds, SW2 (K10) or SW3 (INT0) in standby mode, it changes to stop mode. It uses INT0 interrupt by SW3 key pressing to get out of stop mode. When users set all clocks stop bit (CM10) of the system clock control register 1 (CM1) to "1:stop", all clocks are stopped (= changing to stop mode ). Because the microcomputer changes to medium-speed mode (divided by 8) at the rising edge from stop mode, this program executes to change to high-speed mode for three minutes timer. After it changes the main clock dividing select bit 1 (CM16, CM17), it changes the main clock dividing select bit 0 (CM06) This program sets the main clock dividing select bit 1(CM16, CM17) to "00: without division" and sets the main clock dividing select bit 0 (CM06) to "0: the main clock dividing select bit 1 enabled". cm16 = 0 cm17 = 0 cm10 = 1 High-speed mode Medium-speed (divided by 8) Stop mode All clocks stop Interrupt generation cm06 = 0 mode High-speed mode Division change System clock control register 0 setting b7 b0 0 0 0 01 0 0 0 System clock control register 0 [000616 address] CM0 Reserved bit Peripheral function clock stop bit in "WAIT" Reserved but Reserved bit Main clock stop bit Main clock dividing select bit 0 0:CM16, 17 enabled (after setting select bit 1) Reserved bit System clock control register 1 setting b7 b0 0 0 1 00 0 0 0 System clock control register1 All clocks stop bit [000716 address] CM1 1:All clocks stop (after determining to change to stop mode) Reserved bit Port Xin-Xout switching bit Ring oscillation stop bit Xin-Xout drive capability select bit Main clock dividing select bit 1 00:without dividing (after getting out of stop mode) Rev.1.00 Sep 09, 2003 Page 5 of 23 Sample Program 3.4 R8C/10 Group Three Minutes Timer INT0 Interrupt (getting out of stop mode) The three minutes timer program uses INT0 interrupt by the SW3 key pressing to get out of stop mode. It enables INT0 interrupt before changing to stop mode. Setting contents show as below. Setting of external input enabled register b7 b0 External input enable register 0 0 0 00 0 0 1 INT0 input enable bit [009616 address] INTEN 1: set enable INT0 input polarity select bit 0: set one edge Reserved bit INT0 input filter select register b7 b0 INT0 input filter select register × × × ×× 0 0 0 INT0 input filter select bit [001E16 address] INT0F 00: Set without filter Reserved bit Nothing is assigned INT0 interrupt Control Register Setting b7 b0 INT0 interrupt control register × × 0 00 1 1 1 Interrupt priority level select bit Interrupt request bit Polarity switching bit [005D16 address] INT01C 111:set level 7 0: set without interrupt request 0:select falling edge Reserved bit Nothing is assigned Setting above causes to judge input from INT0, detect one falling edge and generates interrupt. Rev.1.00 Sep 09, 2003 Page 6 of 23 Sample Program R8C/10 Group Three Minutes Timer 3.5 Chattering Removal To confirm the level match needs to read the input port (SW2, SW3) a few times for the countmeasure against noise. The three minutes timer samples by 10ms periods and confirms the SW press three times matching. 4. 4.1 Flow Chart Initial Operation and Main LOOP Reset asm("FCLR I"); ; Interrupt disabled prcr = 1; ; System control register protect cancellation ocd2 = 0; ; Main clock = Ceramic oscillation cm1 = 0x20; ; Main clock without division asm("nop"); ; Wait for stability asm("nop"); ; Wait for stability cm06 = 0; prcr = 0; SFR INITIAL SETTING ; Main clock division CM16, CM17 enabled ; System control register protect ; SFR initial setting (port initial setting, timer setting) SFR_INITIAL ; Interrupt enable asm("FSET I"); No Main period process Yes ; Timer X wait for request ; Timer X request flag clear ir txic = 0; SFR reset ; Port direction register refresh SFR_REF Port output ; Port output (LED, buzzer) PORT_OUT Port input ; Port input (key input process) PORT_IN Mode process ; Mode process (mode refresh inside mode process) MODE_FUNC Soft timer process STIMER Rev.1.00 Sep 09, 2003 Page 7 of 23 ; Soft timer (timer value subtract based on 10ms) Sample Program R8C/10 Group Three Minutes Timer 4.2 SFR Initial Setting sfr_init p0 = 0; ; Port 0 initial setting p1 = 0x1E; ; Port 1 initial setting p3 = 0; ; Port 3 initial setting p4 = 0; tcss = 0x11; ; Port 4 initial setting ; Timer X=divided by 1/8, Timer Z=divided by 1/8 prex = 200-1; ; Prescaler X=200 tx ; Timer X=100 = 100-1; txs = 1; ; Timer X count start prez = 25-1; ; Prescaler Z=25 tzsc = 40-1; ; Timer Z secondary=40 tzpr = 40-1; ; Timer Z primary=40 tyzmr = 0x50; pum tzs = 0; = 0; sfr_ref ; Timer Z mode=programmable waveform generation mode ; "H" for primary period, "L" for secondary period, "L" when the timer is stopped ; Timer Z count stop ; SFR refresh pd0 = 0; ; Port 0 direction register initial setting, refresh pd1 = 0x1e; ; Port 1 direction register initial setting, refresh pd3 = 0x02; ; Port 3 direction register initial setting refresh pd4 = 0x0; ; Port 4 direction register initial setting, refresh RTS Rev.1.00 Sep 09, 2003 Page 8 of 23 Sample Program 4.3 R8C/10 Group Three Minutes Timer Port Output port_out No mode = 1 p1 = 0x0E; Yes No ; Buzzer OFF tzs = 0; tm_ledon <= 0 ; Turn on only red LEd RTS Yes No cnt3min > 1000 ; Turning on time setting Yes tm_ledon = 25; tm_ledon = 50; No ; LED switch ON and OFF led_on = 0 Yes led_on = 0; led_on = 1; Yes led_on = 1 ; LED turning on hourly process No cnt3min > 12000 No cnt3min > 6000 No cnt3min > 0 No Yes p1 = 0x10; Yes p1 = 0x12; Yes p1 = 0x16; p1 = 0x0E; cnt3min = 0 Yes No ; During buzzer output p1 = 0x0E; 1 Rev.1.00 Sep 09, 2003 Page 9 of 23 ; LED turning off process p1 = 0x1E; Sample Program R8C/10 Group Three Minutes Timer 1 cnt3min = 0 & mode = 1 No Yes tm_buzzer <= 0 ; Buzzer output determination tm_buzzer = 20; No ; During buzzer output and stop RTS Yes tm_buzzer = 20; md_buzzer = 0 Yes No md_buzzer = 2 Yes tzs = 1; No md_buzzer + 1; ; Timer Z count start ; Buzzer mode set RTS md buzzer = 1 Yes No md_buzzer = 3 Yes No md_buzzer = 4 No Yes tzs = 0; ; Timer Z count stop md_buzzer + 1; ; Buzzer mode set RTS md_buzzer = 0; cnt10sec = 1000; mode = 0; RTS Rev.1.00 Sep 09, 2003 Page 10 of 23 ; Buzzer mode initial setting ; Stop mode intergradations time setting ; Mode=standby mode Sample Program 4.4 R8C/10 Group Three Minutes Timer Port Input port_in i = 1; SW2 = SW_ON No Yes i = 0; sw2_bit << 1; sw2_bit | i; sw2_bit & 7; No ; Keep input data saved space ; Input data saved ; Delete upper 5 bits sw2_bit = 0 | sw2_bit = 7 Yes sw2_bit = 0 Yes fixsw2 = 1; No ; Confirmed data=L fixsw2 = 0; No ; Confirmed data=H mode = 0 Yes ; mode change ; Three minutes timer set mode = 1; cnt3min = 18000; ; Start from LED OFF led_on = 0; i = 1; SW3 = SW_ON No Yes i = 0; sw3_bit << 1; sw3_bit | i; sw3_bit & 7; 2 Rev.1.00 Sep 09, 2003 Page 11 of 23 ; Keep input data saved space ; Input data ; Delete upper 5 bits Sample Program R8C/10 Group Three Minutes Timer 2 No Sw3_bit = 0 | sw3_bit = 7 Yes Sw3_bit = 0 No ; Confirmed data=H Yes fixsw3 = 0; mode = 0 ; Confirmed data=L No Yes cnt10sec = 1000; RTS Rev.1.00 Sep 09, 2003 Page 12 of 23 mode = 0; cnt3min = 0; fixsw3 = 1; Sample Program R8C/10 Group Three Minutes Timer 4.5 Mode Process mode_func mode = 0 No mode = 1 Yes cnt10sec = 0 Yes Yes No No mode = 0; mode = 1; RTS p1 = 0x1E; ; LED OFF process asm("FCLR I "); ; Interrupt disabled int0ic = 7; ir_int0ic = 0; pol_int0ic = 0; asm("FSET I "); ; INT0 interrupt level 7 ; INT0 interrupt request flag OFF ; Select falling edge ; Interrupt enabled int0en = 1; ; INT0 input enabled int0pl = 0; ; INT0 input polarity select one edge prcr0 = 1; ; Cancel system clock control protect cm10 = 1; ; All clocks stop asm("FCLR I "); ; Interrupt disabled int0ic = 0; ; INT0 interrupt disabled inten = 0; ; INT0 input disabled asm("FSET I "); txs = 0; prcr0 = 1; cm16 = 0; ; Interrupt enabled ; Timer X count stop ; Cancel system clock control protect ; Switch without division (high-speed mode) cm17 = 0; cm06 = 0; prcr0 = 0; txs = 1; cnt10sec = 10; mode = 0; RTS Rev.1.00 Sep 09, 2003 Page 13 of 23 ; Main clock division CM16, CM17 enabled ; System clock control protect ; Timer X count start ; Ten seconds timer set ; Mode refresh Sample Program 4.6 R8C/10 Group Three Minutes Timer Soft Timer Process stimer mode = 0 No ; Mode=standby mode Yes cnt10sec != 0 No Yes ; Power down mode changing time subtract cnt10sec - 1; mode = 1 ; Under flow check No ; Mode=three minutes timer mode Yes cnt3min != 0 No ; Under flow check Yes ; Three minutes measuring timer subtract cnt3min - 1; tm_ledon != 0 No ; Under flow check Yes ; LED operating time subtract tm_ledon - 1; tm_buzzer != 0 No ; Under flow check Yes tm_buzzer - 1; RTS Rev.1.00 Sep 09, 2003 Page 14 of 23 ; Buzzer operating time subtract Sample Program 5. R8C/10 Group Three Minutes Timer Program /************************************************************************ * * * File Name : timer3min.h * * Contents : definition of R8C/11 Group SFR * * Copyright, 2003 RENESAS TECHNOLOGY CORPORATION * * AND RENESAS SOLUTIONS CORPORATION * * Version : 1.00 * * note : * * * ************************************************************************/ /* Definition of RAM area */ char char char char char mode sw2_bit fixsw2 sw3_bit fixsw3 = = = = = 0; 0; 1; 0; 1; char md_buzzer; char led_on; unsigned int tm_ledon; unsigned int tm_buzzer; unsigned long int cnt3min; unsigned long int cnt10sec = 1000; /* /* /* /* /* /* /* /* /* /* /* Mode number */ Input SW2 data */ Input SW2 Settlement data */ Input SW3 data */ Input SW3 Settlement data */ Buzzer control mode */ Display on-off */ LED control timer */ Buzzer control timer */ Counting area in the 3 minute timer */ Counting area in the 10 seconds timer */ /* Declaration of function prototype */ extern extern extern extern extern extern void void void void void void sfr_init(void); sfr_ref(void); port_out(void); port_in(void); mode_func(void); stimer(void); /* Definition of base section */ #define #define #define #define SW_ON SW_OFF LOW HIGH 0 1 0 1 /* Definition of port */ #define #define #define #define #define #define #define GREEN_LED2 GREEN_LED1 GREEN_LED0 RED_LED SW2 SW3 BUZZER p1_1 p1_2 p1_3 p1_4 p1_0 p4_5 p3_1 Rev.1.00 Sep 09, 2003 Page 15 of 23 /* /* /* /* /* /* Initial setting of SFR registers */ Refresh of SFR registers */ Port output */ Port input */ Mode processing */ Software timer */ Sample Program R8C/10 Group Three Minutes Timer /************************************************************************ * * * File Name : main.c * * Contents : definition of R8C/11 Group SFR * * Copyright, 2003 RENESAS TECHNOLOGY CORPORATION * * AND RENESAS SOLUTIONS CORPORATION * * Version : 1.00 * * note : * * * ************************************************************************/ #include "SFR_R811.h" /* Definition of the R8C/11 SFR */ #include "timer3min.h" /* Definition of processing for 3 minutes timer */ #include <stdio.h> #include <stdlib.h> main(){ asm("FCLR I"); prcr = 1; cm13 = 1; cm15 = 1; asm("nop"); asm("nop"); cm05 = 0; asm("nop"); asm("nop"); cm16 = 0; cm17 = 0; asm("nop"); asm("nop"); cm06 = 0; asm("nop"); asm("nop"); ocd2 = 0; prcr = 0; sfr_init(); while(1){ asm("FSET I"); while(ir_txic == 0){} ir_txic = 0; sfr_ref(); port_out(); port_in(); mode_func(); stimer(); } } Rev.1.00 Sep 09, 2003 Page 16 of 23 /* /* /* /* Interrupt enable */ Protect off */ X-in X-out */ XCIN-XCOUT drive capacity select bit : HIGH */ /* X-in on */ /* Main clock = No division mode */ /* CM16 and CM17 enable */ /* /* /* /* /* /* Main clock change */ Protect on */ Initial setting of SFR registers */ Main processing */ Interrupt disable */ Main cycle 10ms */ /* /* /* /* /* Refreshment of SFR registers */ Port output */ Port input */ Mode processing */ Software timer */ Sample Program R8C/10 Group Three Minutes Timer /**************************************************************************** Name: sfr_init Parameters: None Returns: None Description: Initial setting of SFR registers ****************************************************************************/ void sfr_init(void){ /* Setting port registers */ p0 = 0; p1 = 0x1E; /* p14-11 = H(Led 4.3.2.1) */ p3 = 0; /* p31 = L(Buzzer) */ p4 = 0; tcss = 0x11; /* division = X:1/8,Z:1/8 */ /* Setting main cycle timer */ /* 16Mhz* 1/8 * 200 * 100 =10ms */ prex = 200 - 1; /* Setting Prescaler X register */ tx = 100 - 1; /* Setting timer X register */ txs = 1; /* Timer X count start flag = start */ /* Setting Buzzer output timer */ /* the period of Timer Z primary = 16Mhz* 1/8 * 25 * 40 = 0.5ms */ /* the period of Timer Z secondary = 16Mhz* 1/8 * 25 * 40 = 0.5ms */ prez = 25 - 1; /* Setting Prescaler Z register */ tzsc = 40 - 1; /* Setting timer Z secondary register */ tzpr = 40 - 1; /* Setting timer Z Primary register */ tyzmr = 0x50; /* Timer Z mode = Programmable waveform generation mode */ pum = 0; /* Timer Y, Z waveform output control register */ tzs = 0; /* Timer Z count start flag = stop */ sfr_ref(); /* Refreshment of SFR registers */ } /**************************************************************************** Name: sfr_ref Parameters: None Returns: None Description: Refresh of SFR registers ****************************************************************************/ void sfr_ref(void){ /* Setting port direction registers */ pd0 = 0; pd1 = 0x1E; pd3 = 0x02; pd4 = 0x0; } Rev.1.00 Sep 09, 2003 Page 17 of 23 Sample Program R8C/10 Group Three Minutes Timer /****************************************************************************** Name: port_out Parameters: None Returns: None Description: Port output ******************************************************************************/ void port_out(void){ if (mode == 1){ /* LED output processing */ if (tm_ledon <= 0){ if (cnt3min > 1000){ /* Change of LED control timer */ tm_ledon = 50; /* Display during 500ms */ }else{ tm_ledon = 25; /* Display during 250ms */ } if (led_on == 0){ /* Change of display on-off */ led_on = 1; /* Display start */ }else{ led_on = 0; /* Display stoppage */ } } if (led_on == 1){ if (cnt3min > 12000){ /* The remainder time is more than 2 minutes */ p1 = 0x10; }else if (cnt3min > 6000){/* The remainder time is more than 1 minutes */ p1 = 0x12; }else if (cnt3min > 0){ /* The remainder time is less than 1 minutes */ p1 = 0x16; }else{ /* The remainder time is nothing */ p1 = 0x0E; } }else{ if (cnt3min == 0){ /* Counting end */ p1 = 0x0E; }else{ p1 = 0x1E; /* LED turn-off */ } } /* Buzzer output processing */ if (cnt3min == 0 && mode == 1){ if (tm_buzzer <= 0){ tm_buzzer = 20; /* Buzzer control timer = 200ms */ switch (md_buzzer){ case 0: case 2: tzs = 1; /* Counting start of timer Z */ md_buzzer = md_buzzer + 1; break; Rev.1.00 Sep 09, 2003 Page 18 of 23 Sample Program R8C/10 Group Three Minutes Timer case 1: case 3: case 4: tzs = 0; /* Counting stoppage of timer Z */ md_buzzer = md_buzzer + 1; break; default: mode = 0; /* Move to the standby mode */ md_buzzer = 0; cnt10sec = 1000; } } }else{ tm_buzzer = 20; } }else{ p1 = 0x0E; tzs = 0; } } Rev.1.00 Sep 09, 2003 Page 19 of 23 /* Buzzer output of 200ms */ /* Timer Z stops Counting */ Sample Program R8C/10 Group Three Minutes Timer /****************************************************************************** Name: port_in Parameters: None Returns: None Description: Port input ******************************************************************************/ void port_in(void){ unsigned char i; /* Determination of input level SW2 */ i = 1; if (SW2 == SW_ON)i = 0; sw2_bit = sw2_bit << 1; times */ sw2_bit = sw2_bit | i; sw2_bit = sw2_bit & 7; /* Now determination SW2 */ /* Check pulses matching a trigger input level 3 if (sw2_bit == 0 || sw2_bit == 7){ /* Determinate input SW2 */ if (sw2_bit == 0){ fixsw2 = 0; /* Input on */ /* Counting start of the 3 minutes timer */ if (mode == 0){ mode = 1; /* Setting the 3 minute timer mode */ cnt3min = 18000; /* Initialization of the 3 minutes timer */ led_on = 0; /* Display start */ } }else{ fixsw2 = 1; /* Input off */ } } /* Determination of input level SW3 */ i = 1; if (SW3 == SW_ON)i = 0; sw3_bit = sw3_bit << 1; times */ sw3_bit = sw3_bit | i; sw3_bit = sw3_bit & 7; /* Now determination SW3 */ /* Check pulses matching a trigger input level 3 if (sw3_bit == 0 || sw3_bit == 7){ /* Determinate input SW2 */ if (sw3_bit == 0){ fixsw3 = 0; /* Input on */ if (mode == 0){ cnt10sec = 1000; /* Initialization of the move time to the stop mode */ }else{ mode = 0; /* Setting the standby mode */ cnt3min = 0; } }else{ fixsw3 = 1; /* Input off */ } } } Rev.1.00 Sep 09, 2003 Page 20 of 23 Sample Program R8C/10 Group Three Minutes Timer /****************************************************************************** Name: mode_func Parameters: mode Returns: None Description: Mode processing ******************************************************************************/ void mode_func(void){ switch(mode){ case 0: /* Standby mode */ if (cnt10sec == 0){ /* To Sstop mode */ p1 = 0x1E; /* LED turn-off */ asm("FCLR I"); /* Interrupt enable */ int0ic = 7; /* INT0 interruption enable */ ir_int0ic = 0; pol_int0ic = 0; asm("FSET I"); /* Interrupt disable */ int0en = 1; int0pl = 0; prcr0 = 1; /* Protect off */ cm10 = 1; /* From Stop mode */ asm("FCLR I"); /* Interrupt enable */ int0ic = 0; /* INT0 interruption disable */ inten = 0; asm("FSET I"); /* Interrupt disable */ txs = 0; /* Timer X count start flag = stop */ prcr0 = 1; /* Protect off */ cm16 = 0; /* Main clock = No division mode */ cm17 = 0; cm06 = 0; /* CM16 and CM17 enable */ prcr0 = 0; /* Protect on */ txs = 1; /* Timer X count start flag = start */ cnt10sec = 10; /* Setting SW3 input settlement waiting time */ } mode = 0; /* Setting the standby mode */ break; case 1: /* The 3 minute timer mode */ mode = 1; /* Setting the 3 minutes timer mode */ break; default: mode = 0; /* Refresh of the mode */ break; } } Rev.1.00 Sep 09, 2003 Page 21 of 23 Sample Program R8C/10 Group Three Minutes Timer /****************************************************************************** Name: stimer Parameters: None Returns: None Description: Software timer ******************************************************************************/ void stimer(void){ /* Countdown of 10 seconds timer */ if (mode == 0){ if (cnt10sec != 0){ cnt10sec = cnt10sec - 1; } } /* Countdown of 3 minutes timer */ if (mode == 1){ if (cnt3min != 0){ cnt3min = cnt3min - 1; } } /* Countdown of LED control timer */ if (tm_ledon != 0){ tm_ledon = tm_ledon - 1; } /* Countdown of buzzer control timer */ if (tm_buzzer != 0){ tm_buzzer = tm_buzzer - 1; } } Rev.1.00 Sep 09, 2003 Page 22 of 23 Sample Program R8C/10 Group Three Minutes Timer 6. Reference Documents Hardware Manual R8C/Tiny Series Hardware Manual ( For the most current version, please visit Renesas Technology Home Page ) 7. Home Page and Support Information Window Renesas Technology Home Page http://www.renesas.com/ M16C Family MCU Technical Support Information Window [email protected] Rev.1.00 Sep 09, 2003 Page 23 of 23 DEVISION HISTORY Rev. Date R8C/10 Group Three minutes Program Application Note Description Page - Point Keep safety first in your circuit designs! • Renesas Technology Corporation puts the maximum effort into making semiconductor products better and more reliable, but there is always the possibility that trouble may occur with them. Trouble with semiconductors may lead to personal injury, fire or property damage. Remember to give due consideration to safety when making your circuit designs, with appropriate measures such as (i) placement of substitutive, auxiliary circuits, (ii) use of nonflammable material or (iii) prevention against any malfunction or mishap. Notes regarding these materials • These materials are intended as a reference to assist our customers in the selection of the Renesas • • • • • • • Technology Corporation product best suited to the customer's application; they do not convey any license under any intellectual property rights, or any other rights, belonging to Renesas Technology Corporation or a third party. Renesas Technology Corporation assumes no responsibility for any damage, or infringement of any third-party's rights, originating in the use of any product data, diagrams, charts, programs, algorithms, or circuit application examples contained in these materials. All information contained in these materials, including product data, diagrams, charts, programs and algorithms represents information on products at the time of publication of these materials, and are subject to change by Renesas Technology Corporation without notice due to product improvements or other reasons. It is therefore recommended that customers contact Renesas Technology Corporation or an authorized Renesas Technology Corporation product distributor for the latest product information before purchasing a product listed herein. The information described here may contain technical inaccuracies or typographical errors. Renesas Technology Corporation assumes no responsibility for any damage, liability, or other loss rising from these inaccuracies or errors. Please also pay attention to information published by Renesas Technology Corporation by various means, including the Renesas Technology Corporation Semiconductor home page (http://www.renesas.com). When using any or all of the information contained in these materials, including product data, diagrams, charts, programs, and algorithms, please be sure to evaluate all information as a total system before making a final decision on the applicability of the information and products. Renesas Technology Corporation assumes no responsibility for any damage, liability or other loss resulting from the information contained herein. Renesas Technology Corporation semiconductors are not designed or manufactured for use in a device or system that is used under circumstances in which human life is potentially at stake. Please contact Renesas Technology Corporation or an authorized Renesas Technology Corporation product distributor when considering the use of a product contained herein for any specific purposes, such as apparatus or systems for transportation, vehicular, medical, aerospace, nuclear, or undersea repeater use. The prior written approval of Renesas Technology Corporation is necessary to reprint or reproduce in whole or in part these materials. If these products or technologies are subject to the Japanese export control restrictions, they must be exported under a license from the Japanese government and cannot be imported into a country other than the approved destination. Any diversion or reexport contrary to the export control laws and regulations of Japan and/or the country of destination is prohibited. Please contact Renesas Technology Corporation for further details on these materials or the products contained therein.