宏定义
#include<iocc2530.h> #define uint unsigned int #define uchar unsigned char #define LED1 P1_0 uchar h = 1;
初始化
void InitLED(void) { P1SEL &=~0X01; P1DIR |=0X01; LED1 =0; }
void InitT1(void) { T1CTL |= 0X01;//一分频,自由计数模式,2-3为分频,0-1为计数模式 PERCFG = 0X40; P1SEL |= 0X01; T1CCTL2 |= 0X64; T1CC2L |=0XFF; T1CC2H |=h; }
主函数
main() { InitLED(); InitT1(); uchar flag=0; while(1) { if((T1STAT & 0X04) >0) { T1STAT &=0xfb; if(flag==1) h++;//变亮 else h--; //变弱 T1CC2L =0XFF; T1CC2H =h; if(h >=254) flag=0; if(h==0) flag =1; } } }