sdiseiwewew基于51单片机的电子钟C语言程序#includereg51.h#includeabsacc.h#defineucharunsignedchar#defineuintunsignedint/*七段共阴管显示定义*/ucharcodedispcode[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0xBF,0x86,0xCB,0xCF,0xEF,0xED,0xFD,0x87,0xFF,0xDF};/*定义并初始化变量*/ucharseconde=0;ucharminite=0;ucharhour=12;ucharmstcnt=0;sbitP1_0=P1^0;//second调整定义sbitP1_1=P1^1;//minite调整定义sbitP1_2=P1^2;//hour调整定义/*函数声明*/voiddelay(uchark);//延时子程序voidtime_pro();//时间处理子程序voiddisplay();//显示子程序voidkeyscan();//键盘扫描子程序/*****************************//*延时子程序*//****************************/voiddelay(uchark){ucharj;while((k--)!=0){for(j=0;j125;j++){;}}}/**************************//*时间处理子程序*//**************************/voidtime_pro(void)sdiseiwewew{if(seconde==60)//秒钟设为60进制{seconde=0;minite++;if(minite==60)//分钟设为60进制{minite=0;hour++;if(hour==24)//时钟设为24进制{hour=0;}}}}/*****************************//*显示子程序*//*****************************/voiddisplay(void){P2=0xfe;P0=dispcode[hour/10];//显示小时的十位delay(4);P2=0xfd;P0=(dispcode[(hour%10)])|0X80;//显示小时的个位delay(4);P2=0xfb;P0=dispcode[minite/10];//显示分的十位delay(4);P2=0xf7;P0=(dispcode[minite%10])|0X80;//显示分的个位delay(4);P2=0xef;P0=dispcode[seconde/10];//显示秒的十位delay(4);P2=0xdf;P0=dispcode[seconde%10];//显示秒的个位sdiseiwewewdelay(4);}/*******************************//*键盘扫描子程序*//*******************************/voidkeyscan(void){if(P1_0==0)//按键1秒的调整{delay(30);if(P1_0==0){seconde++;if(seconde==60){seconde=0;}}}if(P1_1==0)//按键2分的调整{delay(30);if(P1_1==0){minite++;if(minite==60){minite=0;}}}if(P1_2==0)//按键3小时的调整{delay(30);if(P1_2==0){hour++;if(hour==24){hour=0;}}}}voidtimer0(void)interrupt1using0//定时器0方式1,50mssdiseiwewew中断一次{TH0=0x3c;TMOD=0x11;mstcnt++;if(mstcnt==20){seconde++;mstcnt=0;//注意点。对计数单元的清零十分的重要,本次调试中就是}//因为忽略了这一点,给我早成了很大的被动。}/**************************//*主函数*//**************************/voidmain(void){P1=0xff;//初始化p1口,全设为1TMOD=0x11;//time0为定时器,方式1TH0=0x3c;//预置计数初值TL0=0xb0;EA=1;ET0=1;TR0=1;while(1){keyscan();//按键扫描time_pro();//时间处理display();//显示时间}}sdiseiwewew