数码管动态显示程序
#include<reg51.h>
unsigned char i,j;
unsigned char DuanMa[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned WeiMa[]={0x0e,0x0d,0x0b,0x07};
unsigned XianShi[]={0,2,3,4};
unsigned flag;
void main()
{
i=j=0;
TMOD=0x01;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(flag==1)
{
flag=0;
if(i==4)i=0;
P0=DuanMa[XianShi[i]];
i++;
if(j==4)j=0;
P2=WeiMa[j];
j++;
}
}
}
void timer0() interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
flag++;
}