This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc2540的TIMER1

 

想用timer1实现一个小灯取反,程序能进入中断 但是进入一次以后就不进第二次了 小灯一直是亮着状态  ;还有T1IF,T1IE有什么区别,不写T1IF=1程序不会进中断?

#include<ioCC2540.h>

#define uint unsigned int
#define uchar unsigned char

//定义控制LED灯的端口
#define LED1 P1_1         //定义LED1为P10口控制

//函数声明
void Delayms(uint xms);   //延时函数
void InitLed(void);       //初始化P1口
void InitT1();            //初始化定时器T3

uint count;               //用于定时器计数

/****************************
//延时函数
*****************************/
void Delayms(uint xms)   //i=xms 即延时i毫秒
{
  uint i,j;
  for(i=xms;i>0;i--)
    for(j=587;j>0;j--);
}
/****************************
//初始化程序
*****************************/
void InitLed(void)
{
  P1DIR |= 0x02;          //P1_0义为输出
  LED1 = 0;               //LED1灯熄灭
}
//定时器初始化
void InitT1()
{     
  
  //T1STAT|=0X20; //开溢出中断
  T1OVFIM=1;    //启动
  T1IE=1;       //开T1中断
  T1IF=1;       //开T1中断
  EA=1;         //开总中断
 
  T1CTL|=0X0e;            //128分频,128/16000000*N=0.5S,N=62500
  
}

/***************************
// 主函数
***************************/
void main(void)
{  
  InitLed();               //调用初始化函数
  InitT1();
  while(1);
}

#pragma vector = T1_VECTOR //定时器T1

 __interrupt void T1_ISR(void)
{
  IRCON = 0x00;             //清中断标志, 

   EA=0;
/*  LED1=1;
  Delayms(500) ;
  LED1=0;
  Delayms(500) ;*/


  if(++count>=1)
  {count=0;  LED1=~LED1;}
     EA=1;
   T1IF=1;
}