资源描述:
《51单片机数码管电子时钟c程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//**单片机stc89c52,6位共阴数码管11.059M晶振**////*******P0借口,双74HC573驱动*******//#include#defineucharunsignedchar#defineuintunsignedintucharcodetab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0xff,0x80};ucharn;ucharhh,mm,ss;ucharnhh,nmm,nss;
2、uintyear;ucharday,mon,week;ucharhhs,hhg,mms,mmg,sss,ssg;uchardays,dayg,mons,mong;ucharnhhs,nhhg,nmms,nmmg,nsss,nssg;ucharset1=1,set2=1;sbitdula=P2^6;sbitfm=P3^7;//蜂鸣器借口和K4借口重复sbitwela=P2^7;sbitk1=P3^4;sbitk2=P3^5;sbitk3=P3^6;sbitk4=P3^7;uchartable1[]={
3、31,31,29,31,30,31,30,31,31,30,31,30,31};//闰年uchartable2[]={31,31,28,31,30,31,30,31,31,30,31,30,31};//非闰年voidjishi();voidbaoshi();voidalarm();voidset_time();voidset_alarm();voidset_mdw();voidkey_change();voidkey_set();voiddelay(intm)//延时程序,延时m*0.5ms{uin
4、ti;uintj;for(i=0;i5、0;//时分秒hhg=hh%10;mms=mm/10%10;mmg=mm%10;sss=ss/10%10;ssg=ss%10;nhhs=nhh/10%10;//闹钟nhhg=nhh%10;nmms=nmm/10%10;nmmg=nmm%10;nsss=nss/10%10;nssg=nss%10;days=day/10%10;//月日dayg=day%10;mons=mon/10%10;mong=mon%10;key_change();//k1按键扫描key_set();//k2按键扫描set_tim
6、e();//设置时间set_mdw();//设置月日星期set_alarm();//设置闹钟if(set1==1)//正常走时显示{dula=1;P0=tab[hhs];dula=0;P0=0xff;wela=1;P0=0xfe;delay(1);wela=0;P0=0xff;//时十位dula=1;P0=tab[hhg];dula=0;P0=0xff;wela=1;P0=0xfd;delay(1);wela=0;P0=0xff;//时个位dula=1;P0=tab[mms];dula=0;P0=0
7、xff;wela=1;P0=0xfb;delay(1);wela=0;P0=0xff;//分十位dula=1;P0=tab[mmg];dula=0;P0=0xff;wela=1;P0=0xf7;delay(1);wela=0;P0=0xff;//分个位dula=1;P0=tab[sss];dula=0;P0=0xff;wela=1;P0=0xef;delay(1);wela=0;P0=0xff;//秒十位dula=1;P0=tab[ssg];dula=0;P0=0xff;wela=1;P0=0xdf
8、;delay(1);wela=0;P0=0xff;//秒个位if(ssg%2==0){dula=1;P0=tab[12];dula=0;P0=0xff;wela=1;P0=0xf5;delay(1);wela=0;P0=0xff;//..}}if(set1==2)//设置时间{dula=1;P0=tab[hhs];dula=0;P0=0xff;wela=1;P0=0xfe;delay(1);wela=0;P0=0xff;//时十位dula=1;P0=tab[hhg];