就图7-7编写程序,实现间隔0.5s循环流水显示数字0-9.例如,开始显示1 2,0.5s后变为“2 3”,再过0.5s变为“3 4”……
#include<reg51.h>
unsigned char segment[2]={0x7f,0xbf};
unsigned char led[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char count=0;
unsigned char k=1;
unsigned char i=0;
int main(void)
{
TMOD=0x01;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TF1=0;
TR1=1;
EA=1;
ET1=1;
while(1)
{
if(TF1==1)
{
count++;
if(count%10==0)
{
k++;
if(k%2==0)
{
P2=segment[1];
P0=led[i];
i++;
}
if(k%2==1)
{
P2=segment[0];
P0=led[i];
i++;
}
if(i==10)
{
i=0;
}
}
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TF1=0;
}
}
return 0;
}