本实例给流水灯加入状态机,实现4个LED逐个点亮,再逐个熄灭void ledtest(void)
{
unsigned char stat =0;
delay_init();
LED_Init();
while(1)
{
if(stat==0)
{
LED1_TOGGLE();
stat=1;
}
else if(stat==1)
{
LED2_TOGGLE();
stat=2;
}
else if(stat==2)
{
LED3_TOGGLE();
stat=3;
}
else if(stat==3)
{
LED4_TOGGLE();
stat=0;
}
delay_ms(1000);
}
//return 0;
}
|