宏定义
/*********T3定时器为8位定时器**********/ #include<iocc2530.h> #define LED1 P1_5 #define LED2 P1_0 #define LED3 P1_3 #define LED4 P1_4 #define uchar unsigned char #define uint unsigned int uchar count=0;
初始化
void Initial(void) { P1SEL&=~0X39; P1DIR|=0X39; P1&=~0X39; } void InitT3(void) { T3CTL|=0XE0;//选择频率,对应8位中的高3位//(0.5/128/16)*1024*1024 T3CTL&=~0X03;//模式为自由模式,对应8位中的0和1位,65535*8/1024/1024=0.5s //65536/255=257 T3CTL|=0x10;//启动位//对应8位中的第4位 }
主函数
main() { Initial(); InitT3(); while(1) { if(IRCON>0) { IRCON=0; count++; } if(count>245)//245为一周期,为0.5s { count=0; LED2=LED3=LED4=0; LED1=!LED1; } } }