0
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心
发布
  • 发文章

  • 发资料

  • 发帖

  • 提问

  • 发视频

创作活动
R8C-3MT

R8C-3MT

  • 厂商:

    RENESAS(瑞萨)

  • 封装:

  • 描述:

    R8C-3MT - Sample Program: 3-Minute Timer - Renesas Technology Corp

  • 数据手册
  • 价格&库存
R8C-3MT 数据手册
APPLICATION NOTE R8C/Tiny Series Sample Program: 3-Minute Timer 1. Abstract The 3-minute timer uses the following functions: • Timer X (timer mode) • Timer Z (programmable waveform generation mode) 2. Introduction The example described in this application note is intended for use in the R8C/17 group of microcomputers. This program can also be used when operating other microcomputers within the R8C/Tiny, provided they have the same SFR (Special Function Registers) as the R8C/17 microcomputers. However, since it is possible that some functions of the R8C/Tiny series will have been altered for functional enhancements, etc., please be sure to obtain the SFR header file from the Renesas Web site shown below. http://www.renesas.com/en/r8ctiny Operation (1) The 3-minute timer has two separate modes: • Standby mode • 3-minute timer mode SW4(INT0) Key depressed After reset Standby mode 3-minute timer mode SW1(CNTR0) Key depressed (2) After reset, the microcomputer goes to standby mode. (3) If SW4 (INT0) is pressed during standby mode, the microcomputer goes to 3-minute timer mode. (4) In 3-minute timer mode, the microcomputer executes a 3-minute count operation. (5) When the microcomputer has finished counting 3 minutes, it sounds a buzzer two times and goes to standby mode. (Buzzer operation will be detailed later.) (6) If SW1 (CNTR0) is pressed during 3-minute timer mode, the microcomputer goes to standby mode. (7) Key input is sampled at 10 ms intervals, and is confirmed to have been entered when sampled low three times consecutively. (Chattering elimination) (8) The key inputs SW4 (INT0) and SW1 (CNTR0) are active-low. (When low, the key is pressed; when high, not pressed.) (9) During 3-minute timer mode, the status is indicated by LEDs according to the passage of time, as shown below. LED indications for the passage of time: LED1 (red) 2 minutes or more remaining time 1 minute or more remaining time 10 seconds or more remaining time 10 seconds or less remaining time 0 second remaining time (buzzer sounded) Off Off Off Off On LED2 (green) Off Off Off Off Off LED3 (green) On Flashes every 500 ms Flashes every 500 ms Flashes every 250 ms Off LED4 (green) On Flashes every 500 ms Off Off Off REJ05B0272-0200Z/Rev.2.00 July 2004 Page 1 of 21 R8C/Tiny Series Sample Program: 3-Minute Timer (10) During standby mode, the status is indicated by LEDs, as shown below. LED indications during standby mode: During standby mode LED1 (red) On LED2 (green) Off LED3 (green) Off LED4 (green) Off (11) The LED1, LED2, LED3 and LED4 are active-low. (When low, the LED lights; when high, the LED goes out.) (12) The buzzer on/off signal is output from P13 (TZOUT) using timer-Z programmable waveform mode. (13) The buzzer is output with 1 kHz (50% duty cycle), repeatedly turned on and off twice at 200 ms intervals, and at the end of the sequence, turned off again for another 200 ms. Buzzer output timing sequence: Sequence No. 1 Buzzer status ON (output) Output and stop time 200 ms 2 OFF (stop) 200 ms 3 ON (output) 200 ms 4 OFF (stop) 400 ms 3. About the Program 3.1 Timer X (Timer Mode) The timer X (timer mode) is used to maintain a constant main loop period. The set value of the timer X is shown below. 100µs Timer X Set value = (100 – 1) 20MHz 1/8 Prescaler X Set value = (250 – 1) Main loop, 10 ms Settings of the Timer X Mode Register b7 b0 00001000 Timer X Mode Register [address 008B16] TXMR Selects timer mode INT1/CNTR0 polarity select bit Timer X count start flag Set to “1” when count starts Set to “0” in timer mode Other than pulse period measurement mode Set to “0” in timer mode Settings of the Timer Count Source Setup Register b7 b0 00010001 Timer Count Source Setup Register [address 008E16] TCSS Timer X count source Set 01: 1/8 Reserved bit. Set to “0”. Timer Z count source Set 01: 1/8 Reserved bit. Set to “0”. When the respective registers are set up as shown above, the timer X interrupt request bit is cyclically set at 10 ms intervals. Before the main processing, the program checks the timer X interrupt request bit to see if 10 ms has elapsed. If 10 ms has elapsed, the program clears the timer X interrupt request bit and executes the main processing. If 10 ms has not elapsed yet, the program waits until the timer X interrupt request bit is set. REJ05B0272-0200Z/Rev.2.00 July 2004 Page 2 of 21 R8C/Tiny Series Sample Program: 3-Minute Timer 3.2 Timer Z (Programmable Waveform Generation Mode) The timer Z (programmable waveform generation mode) is used to sound a buzzer. Waveform generation with 1 kHz (50% duty cycle) is accomplished by setting up the registers as shown below. The output level is set by using the timer Z output level latch (TZOPL) in the Timer Z Waveform Output Control Register (PUM). Setting the timer Z output level latch (TZOPL) to “0” causes the device to output a high during the primary period, a low during the secondary period, and a low when the timer is inactive. Settings of the Timer Z Waveform Output Control Register b7 b0 00000000 Timer Z Waveform Output Control Register [address 008416] PUM Reserved bit. Set to “0”. Timer Z output level latch High during primary period, low during secondary period, and low when the timer is inactive INT0 pin one-shot trigger control bit INT0 pin one-shot trigger polarity select bit When the timer Z starts counting, the device outputs a high during the primary period and a low during the secondary period from P13 (TZOUT), and when the timer Z stops counting, the device outputs a low. The timer Z set values are shown below. 20MHz 1/8 Prescaler Z Set value = (25 – 1) 10µs Timer Z primary Set value = (50 – 1) Timer Z secondary Set value = (50 – 1) Buzzer output = high, 500 µs Buzzer output = low, 500 µs Settings of the Timer Count Source Setup Register b7 b0 00010001 Timer Count Source Setup Register [address 008E16] TCSS Timer X count source Set 01: 1/8 Reserved bit. Set to “0”. Timer Z count source Set 01: 1/8 Reserved bit. Set to “0”. Settings of the Timer Z Mode Register b7 b0 01010000 Timer Z Mode Register [address 008016] TZMR Reserved bit. Set to “0”. 01: Programmable waveform generation mode Set to “1” in programmable waveform generation mode. Timer Z count start flag REJ05B0272-0200Z/Rev.2.00 July 2004 Page 3 of 21 R8C/Tiny Series Sample Program: 3-Minute Timer 3.3 Chattering Elimination To protect the key input against chattering noise, SW1 and SW4 are read multiple times to confirm that the detected input levels are the same. For the 3-minute timer, key input is sampled at 10 ms intervals, and is confirmed to have been entered when sampled low three times consecutively. REJ05B0272-0200Z/Rev.2.00 July 2004 Page 4 of 21 R8C/Tiny Series Sample Program: 3-Minute Timer 4. Flowchart 4.1 Initial Settings and Main Loop Reset asm("FCLR I"); prcr = 1; cm13 = 1; cm15 = 1; cm05 = 0; cm16 = 0; cm17 = 0; cm06 = 0; asm("nop"); asm("nop"); asm("nop"); asm("nop"); ocd2 = 0; prcr = 0; ; Disables interrupts ; Removes protection of the system control registers ; XIN-XOUT pin ; Selects XIN-XOUT drive capability; set to HIGH ; Main clock oscillation ; Main clock not divided ; Enables main clock division CM16, CM17 ; Wait until stabilizes ; Wait until stabilizes ; Wait until stabilizes ; Wait until stabilizes ; Selects the main clock ; Protects the system control registers ; Initializes the SFR (port initialization and timer setup) Initialize SFR SFR_INITIAL asm("FSET I"); ; Enables interrupts No ; Wait for timer X request Main period elapsed (10 ms)? Yes ir txic = 0; ; Clears the timer X request flag ; Refreshes the port direction register ; Sets the port for output (LED and buzzer) ; Sets the port for input (key input processing) ; Soft timer (10 ms based timer value subtraction) Reset SFR SFR_REF Port output PORT_OUT Port intput PORT_IN Soft timer processing STIMER REJ05B0272-0200Z/Rev.2.00 July 2004 Page 5 of 21 R8C/Tiny Series Sample Program: 3-Minute Timer 4.2 SFR Initialization sfr_init p1 = 0x16; p4 = 0; tcss = 0x11; prex = 250-1 tx = 100-1; txs = 1; prez = 25-1; tzsc = 50-1; tzpr = 50-1; tzmr = 0x50; pum = 0; tzs = 0; ; Initializes port P1 ; Initializes port P4 ; Timer X = divided-by-8, timer Z = divided-by-8 ; Prescaler X = 250 –1 ; Timer X = 100 – 1 ; Timer X starts counting ; Prescaler Z = 25 – 1 ; Timer Z secondary register = 50 – 1 ; Timer Z primary register = 50 – 1 ; Timer Z mode = programmable waveform generation mode ; Timer Z waveform output control register = 0 ; Timer Z stops counting ; Refreshes the SFR Refresh SFR sfr_ref RTS 4.3 SFR Refresh sfr_ref pd1 = 0x1E; pd4 = 0; RTS ; Initializes/refreshes the port P1 direction register ; Initializes/refreshes the port P4 direction register REJ05B0272-0200Z/Rev.2.00 July 2004 Page 6 of 21 R8C/Tiny Series Sample Program: 3-Minute Timer 4.4 Port Output port_out mode = 1 Yes No No p1 = 0x06; tzs = 0; ; Turns only the red LED on ; Turns buzzer off tm_ledon 12000 No No Led_on = 1; cnt3min > 1000 Yes ; Sets LED-on time tm_ledon = 50; tm_ledon = 25; No led_on = 0 Yes ; Switches over LED on/off led_on = 1; Yes led_on = 0; led_on = 1 No ; LED turn-on processing by time cnt3min > 6000 No Yes p1 = 0x10; Yes cnt3min > 0 No p1 = 0x12; p1 = 0x06; No cnt3min = 0 Yes ; Buzzer output currently on ; LED turn-off processing p1 = 0x06; p1 = 0x16; 1 REJ05B0272-0200Z/Rev.2.00 July 2004 Page 7 of 21 R8C/Tiny Series Sample Program: 3-Minute Timer 1 cnt3min = 0 & mode = 1 Yes No ; Determines buzzer output tm_buzzer = 20; No tm_buzzer 0){ /* The remainder time is less than 1 minutes */ p1 = 0x12; }else{ /* The remainder time is nothing */ p1 = 0x06; } }else{ if (cnt3min == 0){ /* Counting end */ p1 = 0x06; }else{ p1 = 0x16; /* LED turn-off */ } } /* Buzzer output processing */ if (cnt3min == 0 && mode == 1){ if (tm_buzzer
R8C-3MT 价格&库存

很抱歉,暂时无法提供与“R8C-3MT”相匹配的价格&库存,您可以联系我们找货

免费人工找货