MSP430 定时器A和B 中断定时 1秒操作
TimerA0 1秒定时 TIMER B 1 秒定时溢出中断
:MCLK = 2MHz DCOCLK
LFXT1 = 32768Hz ACLK
***********************/
#include msp430x14x.h>
unsigned int i;
unsigned int times,times_b;
unsigned int sec;
/***** 定时器A 初使化 *******/
void TimerA_Init(void)
{
TACTL = TASSEL_1 + ID0 + TACLR ; //ACLK=32768Hz ,清除tar ,2分频
CCTL0 = CCIE; //
CCR0 = 819; // (1/32768)*819 =20 ms ??
TACTL |= MC0; //增计数
}
/**** 定时器B 初使化 *****/
void TimerB_Init (void)
{
TBCTL = TBSSEL_1 + ID0 + TBCLR ; //ID_2 + ID1 +
TBCCTL0 = CCIE; // INTERRUPT ENABLE
TBCCR0 = 819; //
TBCTL |= MC0;
}
/***** 秒测试 1秒响一下 ********/
void Sec_Beep(void)//beep every second
{
if(sec==1)
{
sec = 0;
P5OUT ^= 0x10;
}
}
void main( void )
{
times = 20;
times_b = 20;
WDTCTL = WDTPW + WDTHOLD;
// SYstem clock
DCOCTL = 0x60;
BCSCTL1 = 0x86;//XT20FF ,XTS=0 LOW FREQ , RESEL=6 DCOCLK=2MHz
// XT2on, XTS divA.1 divA.0 XT5V RSEL.2 RSEL.1 RSEL.0
// 1 0 0 0 0 1 1 0
BCSCTL2 = 0x00; //MCLK = DCOCLK, divM=0, SMCLK=CCOCLK ,divS =0
P1DIR |= 0x02; //p1.2 OUT
P5DIR |= 0x10; //P5.4 OUT
TimerA_Init(); //定时器初使化
TimerB_Init();
_EINT(); // interrupt enable
for(;;)
{
_BIS_SR(LPM3_bits);
_NOP();
}
}
/****** 定时器 A 中断 处理 ***********/
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
times--;
if(times == 0)
{
times = 20;
sec=1;
Sec_Beep();
}
}
/****** 定时器B 中断处理 ***********/
#pragma vector = TIMERB0_VECTOR
__interrupt void Timer_B0 (void)
{
times_b--;
if(times_b == 0)
{
times_b = 20;
P1OUT ^= 0x02;
}
}
MSP430定时器中断定 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)