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

/*

用proteus做的时钟

可以显示年月日时分秒

可调整时间

有图

*/

#include

#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;x

for(y=0;y<100;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;j

{for(i=0;i<14;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_init();

while(1)

{

re_time(10);

}

}

void txter() interrupt 0

{

uchar F;

F=1;

EA=0;

while(!K6);

delay(1);

do

{re_time(1);

if(!K1)

{

min++;

if(min>=60) min=0;

while(!K1);

}

syn();

re_time(1);

if(!K2)

{

hour++;

if(hour>=24) hour=0;

while(!K2);

}

syn();

re_time(1);

if(!K3)

{

day++;

R=(year%4==0)&&(year%100!=0);

R=(R&&(day>=29)&&(mon==2))||(!R&&(day>=30)&&(mon==2))||((mon!=2)&&(day>=31));

if(R) day=1;

while(!K3);

}

syn();

re_time(1);

if(!K4)

{

mon++;

if(mon>12) mon=1;

while(!K4);

}

syn();

re_time(1);

if(!K5)

{

year++;

if(year>9999) year=2000;

while(!K5);

}

syn();

re_time(1);

if(!K6)

{

F=!F;

while(!K6);

}

re_time(1);

syn();

re_time(1);

}while(F);

sec=0;

EA=1;

}

/*****************************************************

************定时器0函数

*******************************************************/

void timer() interrupt 1

{

temp0++;

if(temp0>=200)

{

temp0=0;

sec++;

if(sec>=60)

{

sec=0;

min++;

if(min>=60)

{

min=0;

hour++;

if(hour>=24)

{

hour=0;

day++;

R=(year%4==0)&&(year%100!=0);

R=(R&&(day>=29)&&(mon==2))||(!R&&(day>=30)&&(mon==2))||((mon!=2)&&(day>=31));

if(R)

{

day=0;

mon++;

if(mon>=13)

{

mon=1;

year++;

}

}

}

}

}

}

syn();

TH0=timh;

TL0=timl;

}

19ff269d9ad151886f0aece25fdfcec4.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值