CC2530————Control LED1 to flash periodically through the timer T1 query mode (free counting mode)

/ ************************ /
/ * CC2530 routines /
/ Routine Name: Timer (query) /
/ Description: by timer T1 query mode controls LED1 to flash periodically
/
#include <ioCC2530.h>
#define uint unsigned int
#define uchar unsigned char
#define LED1 P1_0 //Define LED1 as P1_0 port control
//Function declaration
void InitLed(void); // P1 port initialization
void InitT1 (); // initialize the timer Tl
// initialization program
/
/
void InitLed (void)
{ P1DIR | = 0x01; // P1_0 defined as output LED1 = 0; // LED1 lights off initialization } // Timer initialization void InitT1() //When the system does not configure the working clock, the internal RC oscillator is used by default, that is, 16MHz { T1CTL = 0x0d; //128 frequency division, automatic reload 0X0000-0XFFFF







}
/

  • Function name: main
  • Function: main function entrance
  • Entry parameters: none
  • Export parameters: none
  • Return value: None
    *****************************/
    void main(void)
    { uchar count; InitLed(); //Call the initialization function InitT1(); while(1) { if((T1STAT&0x20)==0x20) { T1STAT&=~0x20; //Clear the overflow flag ++count; } if(count == 3) //If the number of overflows reaches 3, it means that it has passed 1.5 seconds have passed { LED1 = 1; //Turn on LED1 } if(count == 4) //If the overflow count reaches 4, 2 seconds have passed { LED1 = 0; //Turn off LED1 count=0; } } }




















Guess you like

Origin blog.csdn.net/News53231323/article/details/113186958