In this experiment, the CC2530 Timer 1 (16-bit) Query method is used to control the LED1 to 1S periodic flashing, this experiment uses three registers T1CTL (Timer 1 control register), T1stat (Timer 1 status register), IRCON.
For CC2530 Gpio Basics, General Gpio operation about registers, IAR Embedded Workbench IDE software use: TI CC2530 Basic Experiment (ordinary GPIO operation-Light LED)
schematic diagram of the circuit:
Register Analysis:
1, Timer 1 control register
mode analysis under the T1CTL Register of timer 1:【
Free Running mode": in free-running operation mode, the counter starts at 0x0000 and increments by 1 per active clock edge. When the counter reaches 0xFFFF (overflow), the counter is re-loaded into 0x0000 and continues to increment its value as shown in. When the final count value of 0xFFFF is reached, the flags ircon.t1if and T1STAT.OVFIF are set. If the corresponding interrupt shield bit Timif.ovfim and Ien1.t1en are set, an interrupt request is generated. Free-running mode can be used to generate independent time intervals, output signal frequency
【
die Mode】:
When the timer is running in modulo mode, the 16-bit counter starts at 0x0000 and increments by 1 for each active clock edge. When the counter reaches t1cc0 (overflow), the register t1cc0h:t1cc0l the final count value saved, the counter resets to 0x0000 and continues to increment. If the timer starts at a value above t1cc0, the flag ircon.t1if and T1CTL.OVFIF are set when the final count value (0xFFFF) is reached. If the corresponding interrupt shield bit Timif.ovfim and Ien1.t1en are set, an interrupt request is generated. Modulo mode can be used for applications that are not 0xFFFF in duration. The operation of the counter is shown as:
" positive count/Reverse Count mode ":
In the positive count/reverse count mode, the counter starts repeatedly from 0x0000 and is counted straight up to t1cc0h:t1cc0l saved value. The counter then counts backwards to guide the 0x0000 as shown in. This timer is used for applications where the cycle must be symmetrical output pulses rather than 0xFFF, so the implementation of the Center-aligned PWM output application is allowed. In positive count/reverse count mode, when the final count value is reached, the flags ircon.t1if and T1CTL.OVFIF are set. If the corresponding interrupt shield bit Timif.ovfim and Ien1.t1en are set, an interrupt request is generated.
2. Timer 1 Status Register
3. Interrupt Flag 4 Register
Program-Timer 1 uses free-running mode :
#include <iocc2530.h>/************************************ * Program Description: LED1 with 1S periodic flashing **************************** /#define LED1 p1_0/********************************************************* * Function Description: Initialize LED1 * Note: The system does not configure the working clock using the internal RC oscillator, i.e. 16MHz *********************************************************/void led1init (void) { P1sel &= ~0x01; function: normal I/O p1dir |= 0x01; Direction: Output LED1 = 1; Make it out of State}/*********************************** * Function Description: Timer 1 initialization * Settings: crossover, operating mode **********************************/void T1init (void) {T1ctl |= 0x0c; Set to 128 frequency T1ctl |= 0x01; Set to free run mode, from 0x0000 to 0xFFFF repeated count}void main () {unsigned char count = 0;//used to record timer overflow times led1init (); T1init (); for (;;) {#if 1 if ((T1stat & 0x20) > 0)//Judge T1stat's Bit5 {t1stat &= ~0x20; if (++count = = 1) {count = 0; LED1 =! LED1; }} #else if ((IRCON & 0x02) > 0)//determine IRCON bit1 {IRCON &= ~0x02;//clear Interrupt flag IRCON = 0; if (++count = = 1) {count = 0; LED1 =! LED1; }} #endif}}
The system does not configure
Operating FrequencyWhen the default is 2, that is, 32m/2=16m, so the timer each overflow t=1/(16/128) *65536≈0.5s, where 128 is set timer 1 division, 65536 is 0x0000~0xffff total increment, so the total time Ta=t*count =0.5*1=0.5s Switch 1 times, so it looks like 1S is deleted 1 times.
Note: Each creation of a new project will have to configure the IAR (to do the basic experiment), TI CC2530 Basic Experiment (ordinary GPIO operation-led light) also has IAR related configuration steps
Summarize:
Timer 1 in the use of free-running mode from the 0x0000 count, to 0xFFFF overflow, when the timer 1 with 128, at the default operating frequency, an overflow of about 0.5s.
Timer 1 Query method is to determine whether the timer overflow by T1STAT.OVFIF and ircon.t1if.
TI CC2530 Basic Experiment (Timer 1 query mode-free running mode)