资源描述:
《数字时钟C程序及仿真》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#includcunsignedcharcodeSEG7[12]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,OxF8,0x80,0x90,0xbf,0xff,};unsignedshortinttcount;//sbitset=PlA0;//sbitup=PlAl;//sbitdown=PlA2;unsignedcharDisSecondL,DisSecondH,DisMinutL,DisMinutH,DisHourL,DisHourH;〃结构体变量structtime{unsignedcharsecond;unsi
2、gnedcharminute;unsignedcharhour;Jtimel;〃延时子程序voiddelay(k)unsignedintk;{unsignedcharj;while((k-)!=0)for(j=0;j<125;j++);〃时钟调整了程序TimeUpDown(n5x,y)unsignedcharn,x,y;{if(up==0){delay(50);//消除抖动if(up==0){n++;if(n==x)//上限越界显示为0n=0;while(up==0);if(down==0)delay(50);if(down==0){if(n==O)//下限越界显
3、示为最大可显示n=y;elsen-;while(down==0);1Ireturnn;//返回调整后的值}*/〃显示子程序voiddisplay(DisSecondL,DisSecondH,DisMinutL,DisMinutH,DisHourL,DisHourH){〃日日日日日日//123456//hHhLmHmLsHsL//010204081020P2=0x00;P0=SEG7[DisSecondL];〃显示秒钟的个位P2=0x20;delay(3);P2=0x00;P0=SEG7[DisSecondHl;〃显示秒钟的十位P2=0x10;delay(3);P2
4、=0x00;P0=SEG7[DisMinutL];〃显示分钟的个位P2=0x08;delay(3);P2=OxOO;P0=SEG7[DisMinutHJ;〃显示分钟的十位P2=0x04;delay(3);P2=OxOO;PO=SEG7[DisHourL];〃显示小时的个位P2=0x02;delay⑶;P2=0x00;if(DisHourH==0){;)else{P0=SEG7[DisHourH];〃显示小时的十位P2=0x01;delay(3);voidmain(){//unsignedcharFlag;timel.second=40;timel.minute=0
5、3;limel.hour=05;TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ETO=1;TR0=1;while(l){display(DisSccondL,DisSccondH,DisMinutL,DisMinutH,DisHourL,DisHourH);if(set==0)〃设置标志位Flagdelay(50);if(set==0)TRO=0;Flag++;if(Flag>3)//0:显示时间,1:小时调整,2:分钟调整,3:秒调整Flag=0;}while(set==0);}switch
6、(Flag){case0:TRO=1;display(time1•second%10,time1.second/10,time1.minute%10,time1.minute/105time1.hour%10,timel.hour/10);break;case1:〃时钟小时调整TR0=0;timeI•hour=TimeUpDown(time1.hour,24,23);display(10,10,10,10,timel.hour%10,timel.hour/10);break;case2:〃时钟分钟调整timel.minute=TimeUpDown(timel.mi
7、nute.60,59);display(10,10,timeI.minute%10,timeI.minute/10,10,10);break;case3:〃时钟秒调整time1.sccond=TimcUpDown(timc1.second,60,59);display(timc1.second%10,timc1.second/10J0,10J0,10);break;//default://break;voidtO(void)interrupt1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;tcount++;if(tcou
8、nt==2