根据你的原理图,试一下这个程序,或许可以实现:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x0c,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar num1,num2,ge,shi;
sbit pnp4=P1^3;
sbit pnp3=P1^2;
void delay(uint xms)
{
uint a,b;
for(a=xms;a>0;a--)
for(b=110;b>0;b--);
}
void display()
{
pnp4=1;
P0=table[ge];
pnp4=0;
delay(5);
pnp3=1;
P0=table[shi];
pnp3=0;
delay(5);
}
void main()
{
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display();
}
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num++;
if(num==20)
{
num2++;
num=0;
if(num2==60)
{
num2=0;
}
}
ge=num2%10;
shi=num2/10;
}
|