用c语言编写程序,用于c51单片机四位共阴数码管显示,显示分秒的计时器。

如题所述



用proteus做的时钟
可以显示年月日时分秒
可调整时间
有图
*/
#includereg52.h>
#defineuchar unsigned char
#define uint unsigned int
#define timh 0xee
#define timl 0x00

sbit K1=P1^0;
sbit K2=P1^1;
sbit K3=P1^2;
sbit K4=P1^3;
sbit K5=P1^4;
sbit K6=P1^5;
sbit poit=P0^7;

uint year=2011,year0=0;
uchar mon=6,mon0=0,day=26,day0=0,hour=23,hour0=0,min=15,min0=0,sec=0,sec0=10,temp0=0;
uchar R;

uchar cod1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar temp[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

void delay(uint z)
{
uint x,y;
for(x=0;xz;x++)
for(y=0;y100;y++);
}
void exter_init()
{
IT0=1;
EX0=1;
}
void time_init()
{
TMOD=0x01;
TH0=timh;
TL0=timl;
ET0=1;
EA=1;
TR0=1;

}

void re_time(uchar a)
{
uchar i,j;
for(j=0;ja;j++)
{for(i=0;i14;i++)
{
P0=cod1[temp[i]];
if(i==3||i==5||i==9||i==11) poit=0;
P2=i;
delay(1);
P2=0x0f;
}
}
}
void syn()
{
if(sec!=sec0)
{sec0=sec;
temp[12]=sec0/10;
temp[13]=sec0%10;}
if(year!=year0)
{year0=year;
temp[0]=year0/1000;
temp[14]=year0%1000;
temp[1]=temp[14]/100;
temp[14]=temp[14]%100;
temp[2]=temp[14]/10;
temp[3]=temp[14]%10;}
if(mon!=mon0)
{mon0=mon;
temp[4]=mon0/10;
temp[5]=mon0%10;}
if(day!=day0)
{day0=day;
temp[6]=day0/10;
temp[7]=day0%10;}
if(hour!=hour0)
{hour0=hour;
temp[8]=hour0/10;
temp[9]=hour0%10;}
if(min!=min0)
{min0=min;
temp[10]=min0/10;
temp[11]=min0%10;}
}
main()
{
exter_init();
time_i......

采纳我为最佳把,呵呵。
温馨提示:答案为网友推荐,仅供参考