原理图
源码
#include<reg52.h>
table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //共阳极
unsigned int count,i=0,j;
void delay (unsigned int ms) //延时函数
{unsigned char j; while(ms--);
for(j=0;j<120;j++); }
void main()
{ count=60;
TMOD=0x10;
TH1=(65536-50000)/256;
TH1=(65536-50000)/256;
EA=1;
TR1=1;
ET1=1;
P0=0xff;
P2=0;
while(1)
{ P0=0xff;
P2=0x01;
P0=table[count/10]; //十位
delay(5);
P0=0xff;
P0=table[count%10];// 个位
P2=0x02;
delay(5);
if(count==0)
{TR1=0;}
}
void Timer1() interrupt 3
{ TH1=(65536-50000)/256; // 50ms
TL1=(65536-50000)%256;
i++;
if(i>=20) //20次,1000ms=1s
{count--;
i=0;}
}