CC2530 bare metal programming series notes 3--Timer Timer1 free mode program

Publisher:闪耀的星空Latest update time:2019-09-04 Source: eefocusKeywords:cc2530 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Timer 1 is a 16-bit timer with timer/counter/pulse width modulation functions. It has 3 individually programmable input capture/output comparison channels, each of which can be used as a PWM output or to capture the edge time of the input signal (for more information on what input capture/output comparison is and how to implement PWM output, readers can refer to the CC2530 Chinese manual). The timer has a very important concept: operating mode. The operating modes include: free-running mode, modulo mode, and up-down mode. The design of the free-mode program for timer Timer1 is as follows:


#include

#define uint unsigned int

#define uchar unsigned char

#define RLED P1_0

#define YLED P1_1

uint counter=0; //Count the number of overflows

uint TempFlag; //Used to mark whether to flash

void Initial(void);

void Delay(uint);

/****************************

//Normal delay program

***************************/

void Delay(uint n)

{

uchar i;

while(n--)

{

for(i=200;i>0;i--);

}

}

/****************************

// Initialization program

***************************/

void Initial(void)

{

// Initialize P1

P1DIR = 0x03; //P10 P11 is output

RLED = 1;

YLED = 1; // Turn off LED

T1CTL = 0x05; //00001101 8-frequency automatic reload

}

/*******************************

//Main function

***************************/

void main(void)

{

static unsigned char cnt = 0;

Initial(); //Call the initialization function

RLED = 0; // Turn on the red LED

while(1) //Query overflow

{

if(IRCON > 0)

{

IRCON = 0; // Clear overflow flag

cnt++;

if(cnt == 15)

{

cnt = 0;

RLED = !RLED;

}

}

}

}

      The main registers used in this program are: T1CTL, IRCON. The value set in the T1CTL register is 0x05. According to the manual, this register configures the frequency division to 8, that is, f/8, and the mode is set to free mode and Free-running. The count value will be counted from 0x0000-0xFFFF. The second bit in IRCON is the interrupt flag bit of timer 1.

Keywords:cc2530 Reference address:CC2530 bare metal programming series notes 3--Timer Timer1 free mode program

Previous article:CC2530 Bare Metal Programming Series Notes 5--Interrupts
Next article:CC2530 bare metal programming series notes 2--Timer Timer1 mode program interrupt mode

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号