没有开发板,用慧净四驱的主控板四位数码管显示时间,运行准确,电路图大家可以搜一下。小数点隔一秒闪烁一下,按钮3和4分别调制时和分。附上源程序:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit KEY1=P2^5;//调制时
sbit KEY2=P2^4;//调制分
uchar num,fen,miao,shi,flag;
uint disnum;
uchar code table_du[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code table_we[]={0xfe,0xfd,0xfb,0xf7};//P2口,控制数码管的位选
delay(uchar x)
{
uchar a,b;
for(a=x;a>0;a--)
for(b=200;b>0;b--);
}
void display()
{
//P2=0xFF;
P0=table_du[shi/10];
P2=table_we[0];
delay(10);
P0=table_du[shi%10]-flag*(0x80);//小数点间隔1s闪烁
P2=table_we[1];
delay(10);
P0=table_du[fen/10];
P2=table_we[2];
delay(10);
P0=table_du[fen%10];
P2=table_we[3];
delay(10);
}
void revise()//调制时,分
{
if(KEY1==0)
{
delay(10);
if(KEY1==0)
{
shi++;
}
while(!KEY1);
delay(10);
while(!KEY1);
}
if(KEY2==0)
{
delay(10);
if(KEY2==0)
{
fen++;
}
while(!KEY2);
delay(10);
while(!KEY2);
}
}
void main()
{
EA=1;
ET0=1;
TMOD=0X01;
TH0=0xB8;
TL0=0x00;
TR0=1;
while(1)
{
revise();
display();
}
}
void time0() interrupt 1
{
TH0=0xB8; //对应11.0592M晶振计算得到,20ms
TL0=0x00;
num++;
if(num==50)
{
num=0;
miao++;
flag=miao%2;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
}
}
}
}