第1个回答 2011-10-24
#include<reg51.h>
#include<stdlib.h>
unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x98};
unsigned char buffer[6];
bit flag;
unsigned int n;
unsigned char j =0;
void delay(int ms)
{ int i;
while(ms--)
for(i=0;i<200;i++);
}
handle(unsigned int n)
{
unsigned char i;
for(i=0;i<6;i++)
{
buffer[i]=n%10;
n=n/10;
}
}
void jinzhi()
{
if(n<100)
{ n++;
if(n==99)
{
n=0;
}
flag=0;
}
}
void xianshi()
{
unsigned char i,weixuan;
weixuan=0x80;
for(i=0;i<6;i++)
{
P2=weixuan;
P3=tab[buffer[i]];
delay(0);
weixuan>>=1;
}
}
void main()
{
TMOD=0X01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
n=0;
handle(n);
while(1)
{ handle(n);
xianshi();
if(flag==1)
jinzhi();
}
}
int0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
j++;
if(j==20)
{
j=0;
flag=1;
}
}