不知道为什么数码管显示不完全。
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
void delay_ms(unsigned int);
uchar code xianshi[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code weixuan[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
int num=0;
int sec=22,secg=0,secs=0;
int min=5,ming=0,mins=0;
int hour=15,hourg=0,hours=0;
int i;
void zd1(){
TMOD=0X01;
TH0=(65536-50000)/256; //TH0=(65536-50000)/256;
TL0=(65536-50000)%256; //TL0=(65536-50000)%256;
ET0=1;
TR0=1;
}
void main(){
IT0=1;
EX0=1;
EA=1;
IT1=1;
EX1=1;
zd1();
while(1){
secg=sec%10;
secs=sec/10;
ming=min%10;
mins=min/10;
hourg=hour%10;
hours=hour/10;
P0= xianshi[hours];
P2=weixuan[0];
delay_ms(5);
P0= xianshi[hourg];
P2=weixuan[1];
delay_ms(5);
P0= xianshi[mins];
P2=weixuan[2];
delay_ms(5);
P0= xianshi[ming];
P2=weixuan[3];
delay_ms(5);
P0= xianshi[secs];
P2=weixuan[4];
delay_ms(5);
P0= xianshi[secg];
P2=weixuan[5];
delay_ms(5);
}
}
void time0() interrupt 1{
num++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(num==20){
num=0;
sec++;
}
if(sec==60){
sec=0;
min++;
}
if(min==60){
min=0;
hour++;
}
if(hour==24){
hour=0;
}
}
void delay_ms(unsigned int dt)//延时函数
{
register unsigned char bt,ct;
for (;dt;dt--)
for (ct=2;ct;ct--)
for (bt=250;--bt;);
}
|