ZIGBEE CC2430 使用Timer2定时器进行计数中断设置

#include 
#define uint unsigned int
#define uchar unsigned char

uint cnt = 0;
uchar tmpFlag;

void delay(uint n) {
  uint i, t;
  for (i = 0; i < 5; i++)
    for (t = 0; t < n; t++) ;
}

void init() {
  LED_ENALBLE();
  SET_TIMER_CAP_INT();
  SET_TIMER_CAP_COUNTER(0xff);
}

void main() {
  init();
  led1 = 0;
  led2 = 1;
  TIMER2_RUN();
  while (1) {
    if (tmpFlag) {
      led2 = !led2;
      tmpFlag = 0;
    }
  }
}

#pragma vector = T2_VECTOR

__interrupt void T2_ISR() {
  CLEAR_TIMER2_INT_FLAG();
  if (cnt < 200) cnt++;
  else {
    cnt = 0;
    tmpFlag = 1;
  }
}

你可能感兴趣的:(51单片机)