宏定义
#include<iocc2530.h> #define uchar unsigned char #define uint unsigned int
初始化
void Initial(void) { P1SEL&=~0X39; P1DIR|=0X39; P1SEL&=~0X04; P1DIR&=~0X04; P1INP&=~0X04; P1&=~0X39; }
延迟
void Delay(uint time) { uint i; uchar j; for(i=0;i<time;i++) for(j=0;j<240;j++) { asm("NOP"); asm("NOP"); asm("NOP"); } }
主函数
main() { uchar count=0; uchar stat[]={0x20,0x01,0x10,0x08}; Initial(); while(1) { if(P1_2==0) { switch(count) { case 0:P1=stat[count];Delay(1200);break; case 1:P1=stat[count];Delay(1200);break; case 2:P1=stat[count];Delay(1200);break; case 3:P1=stat[count];Delay(1200);break; } if(count<=3) count++; else count=0; } else { P1=stat[count]; Delay(1200); } } }