#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num=0,a=0;
//å
±é´æ°ç 管ä¸æ®µç
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77};
void Delay1ms(uint i) //1ms延æ¶ç¨åº
{
uint j;
for(;i>0;i--)
{
for(j=0;j<164;j++)
{;}
}
}
void main(void )//主ç¨åº
{
TMOD=0X01;
TH0=(65536-50000)/256;
TR0=(65536-50000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(a==20)//å¤ææ¯å¦å¤1ç§
{
a=0;
num++;
if(num==100)num=0;
}
display[num];
}
void timer0(void ) interrupt 1//å®æ¶å¨ä¸æåç¨åº
{
TH0=(65536-50000)/256;
TR0=(65536-50000)%256;
a++;
}
void display(uint n)//æ¾ç¤ºåç¨åºï¼ç¨éåå¨ï¼å¯æ¾ç¤º4ä½æ°
{
uchar a1,a2,a3,a4;
a1ï¼n/1000;
a2=n/100%10;
a3=n/10%10;
a4=n%10;
P0=table[a1]; //æ¾ç¤ºåä½
dula=1;
dula=0;
P0=0xfe;
wela=1;
wela=0;
Delay1ms(2);
P0=table[a2]; //æ¾ç¤ºç¾ä½
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
Delay1ms(2);
P0=table[a3]; //æ¾ç¤ºåä½
dula=1;
dula=0;
P0=0xfb;
wela=1;
wela=0;
Delay1ms(2);
P0=table[a4]; //æ¾ç¤ºä¸ªä½
dula=1;
dula=0;
P0=0xf7;
wela=1;
wela=0;
Delay1ms(2);
}
追é®è¿æ¯52
åçæºç
èä¸ä¹æé
ï¼
追ç15åçæºä¸å
¼å®¹51åçæºåï¼èªå·±ææçTL0åæäºTR0
display[num]åé¢åå¤å ä¸ä¸ªå¤§æ¬å·å°± 好äº
追é®æ²¡å®ä¹éåå¨å
ããããå¼èä¸ä¸æ ·ï¼å
·ä½ä¹ä¸ä¸æ ·
èä¸a==20è½å¸®å¿è§£éä¸ä¸ä¹
谢谢