資源描述:
《《51單片機(jī)數(shù)字時(shí)鐘-proteus仿真原理圖及keilc51編譯的c51程序》.doc》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、該實(shí)驗(yàn)采用proteus7.4sp3進(jìn)行的仿真,仿真原理圖如下圖所示,該實(shí)驗(yàn)采用定時(shí)器0的工作方式1定時(shí)500ms,等待20次定時(shí)1s進(jìn)行時(shí)鐘計(jì)數(shù)。通過定時(shí)器1的工作方式1定時(shí)500ms,用來調(diào)整數(shù)碼管閃爍的時(shí)間。K1是用來選中時(shí)分秒,按一下選中時(shí),再按一下選中分,再按一下選中秒,再按一下退出選中狀態(tài)。K2按一下數(shù)加一,K3按一下數(shù)減一。在調(diào)整時(shí)間時(shí),時(shí)鐘停走。/***********************************************************************程序名;??時(shí)鐘實(shí)驗(yàn)*功??能:數(shù)碼管通過動態(tài)掃描顯示時(shí)間,時(shí)
2、間可設(shè)定,調(diào)整時(shí)間時(shí)時(shí)鐘不走.*編程者:ZPZ*編程時(shí)間:2009/8/9**********************************************************************/#include#defineuintunsignedint#defineucharunsignedchar?????????????????sbit??_led=P2^7;sbit??key1=P2^0;sbit??key2=P2^1;sbit??key3=P2^2;uchar??num=0,temp=0,count=0;uchar
3、??aa;ucharhour,min,sec;ucharcodetable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};????????????????????????????????????void??delay(uintz);void??display(uchara,ucharb,ucharc,uchard,uchare,ucharf,ucharaa);void??read_key();void??led();void??time_change();/******************主函數(shù)??
4、*******************/voidmain(){?????????P2=0xff;?????????hour=12;?????????min=0;?????????sec=0;?????????TMOD=0x11;?????????TH0=(65536-50000)/256;?????????TL0=(65536-50000)%256;?????????TH1=(65536-50000)/256;?????????TL1=(65536-50000)%256;?????????EA=1;?????????ET0=1;?????????ET1=1;???
5、??????TR0=1;?????????TR1=1;?????????aa=0xff;????while(1)????{???????????????????????????time_change();????????????????????display(table[hour/10],table[hour%10],table[min/10],????????????????????????????table[min%10],table[sec/10],table[sec%10],0xff);????????????????????????}}