#include <iocc2540.h>
#include "timer.h"
void timer1_init(void)
{
T1CTL &= ~((3<<0)|(3<<2));
T1CTL |= ((1<<0)|(1<<2));//自由模式 8分频
}
#include "led.h"
#include "timer.h"
void main(void)
{
unsigned int count=0;
led_init();
timer1_init();
while(1)
{
if (IRCON &(1<<1))//系统时钟32MHZ,8分频后为4MHZ,0xffff*1S/4MHZ=16384us 500ms/16384us=30.517578125
{
count++;
if (count>32)
{
count = 0;
LED1 = !LED1;
}
IRCON &= ~(1<<1);
}
}
}
网友评论