资源描述:
《电子闹钟(沈).doc》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、#include"reg51.h"#include#defineuintunsignedchar#defineucharunsignedchar#defineTHCO0xee#defineTLCO0x0uchari,n;uintH,L;voiddelay(uint);ucharcodetable[]={0xfd,0x09,0x04,0xfd,0x09,0x04,0xfd,0x34,0x04,0xfd,0x83,0x04,0xfd,0x83,0x04,0xfd,0x34,0x04,0xfd,0x09,0x04,0xfc,0xad,0x04,0xfc,0
2、x44,0x04,0xfc,0x44,0x04,0xfc,0xad,0x04,0xfd,0x09,0x04,0xfd,0x09,0x04,0xfc,0xad,0x04,0xfc,0xad,0x08,0xfd,0x09,0x04,0xfd,0x09,0x04,0xfd,0x34,0x04,0xfd,0x83,0x04,0xfd,0x83,0x04,0xfd,0x34,0x04,0xfd,0x09,0x04,0xfc,0xad,0x04,0xfc,0x44,0x04,0xfc,0x44,0x04,0xfc,0xad,0x04,0xfd,0x09,0x04,0xfc,0xad,
3、0x04,0xfc,0x44,0x04,0xfc,0x44,0x08};unsignedcharcodeDuan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};//共阴极数码管,0-9段码表unsignedcharData_Buffer[10]={0,1,2,3,4,5,6,7,8,9};//四个数码管显示数值,数组变量定义staticunsignedcharBit=0;//静态变量,退出程序后,值保留staticunsignedcharBit1=0;staticunsignedcharBit2=0;stati
4、cunsignedcharBit3=0;staticunsignedcharBit4=0;staticunsignedcharBit5=0;staticunsignedcharBit6=0;staticunsignedcharTrouch=0;sbitP10=P1^0;//四个数码管的位码口定义sbitP27=P2^7;sbitP26=P2^6;sbitP25=P2^5;sbitP24=P2^4;sbitP23=P2^3;sbitP20=P2^0;sbitP21=P2^1;sbitP3_2=P3^2;sbitP11=P1^1;sbitP12=P1^2;sbitP13=P1
5、^3;sbitP14=P1^4;//四个数码管的位码口定义sbitP15=P1^5;sbitP16=P1^6;sbitP17=P1^7;voiddelay(inti){unsignedinta,b;for(a=i;a>0;a--);for(b=100;b>0;b--);}voidchange6(){P26=0;P25=0;delay(150000);do{if(P21==0)Bit6++;if(Bit6==2)Bit6=0;P0=Duan[Data_Buffer[Bit1]];//开段码P1=0xdf;delay(50);P0=Duan[Data_Buffer[Bit2]
6、];P1=0xef;delay(50);//先关位码P0=Duan[Data_Buffer[Bit3]];//开段码P1=0xf7;delay(50);P0=Duan[Data_Buffer[Bit4]];P1=0xfb;delay(50);//先关位码P0=Duan[Data_Buffer[Bit5]];//开段码P1=0xfd;delay(50);P0=Duan[Data_Buffer[Bit6]];P1=0xfe;delay(50);}while(P20==1);P26=1;P25=1;delay(25000);}voidchange5(){P24=0;P26=0;
7、delay(150000);do{if(P21==0)Bit5++;if(Bit5==4)Bit5=0;P0=Duan[Data_Buffer[Bit1]];//开段码P1=0xdf;delay(50);P0=Duan[Data_Buffer[Bit2]];P1=0xef;delay(50);//先关位码P0=Duan[Data_Buffer[Bit3]];//开段码P1=0xf7;delay(50);P0=Duan[Data_Buffer[Bit4]];P1=0xfb;delay(50);//先关位码P0=Duan[Data