基于STC89C52RC,使用定时器,1s流水一个灯
#include<reg52.h>
#define LED_PORT P2
void timer()
{
unsigned char count;
for(count=0;count<50;count++)
{
while(TF0==0) ;
TF0=0;
TH0=0XB1;
TL0=0XE0;
}
}
void main()
{
unsigned char i;
TMOD=0X01;
TR0=1;
LED_PORT=~0x01;
while(1)
{
for(i=0;i<8;i++)
{
LED_PORT=~(0X01<<i); //左移取反
timer();
}
for(i=0;i<8;i++)
{
LED_PORT=~(0x80>>i); //右移取反
timer();
}
}
}