資源描述:
《基于c51單片機(jī)的數(shù)字可調(diào)時(shí)鐘》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、河南機(jī)電高等??茖W(xué)校《C51程序設(shè)計(jì)》大作業(yè)設(shè)計(jì)題目:數(shù)字可調(diào)時(shí)鐘班級:通技091學(xué)號:090413128姓名:成績:2011年11月1設(shè)計(jì)任務(wù)制作數(shù)字可調(diào)時(shí)鐘,要求可以分開調(diào)節(jié)分、時(shí)、年、月、日,能夠顯示溫度。2電路原理圖以下為protel99se畫的的原理圖3系統(tǒng)流程圖數(shù)字可調(diào)時(shí)鐘分以下四個(gè)部分構(gòu)成:顯示部分:此次顯示采用了動態(tài)掃描顯示,采用74ls573進(jìn)行數(shù)據(jù)鎖存。溫度采集:溫度采集采用了18b20采集的,18b20轉(zhuǎn)化溫度較快,精度高。時(shí)鐘:采用普通的ds1302芯片。數(shù)據(jù)運(yùn)算:單片機(jī)
2、用普通的8051單片機(jī)(12M晶振)。數(shù)碼管顯示模塊單片機(jī)鍵盤溫度采集模塊時(shí)鐘模塊4源程序/*******************************數(shù)字可調(diào)時(shí)鐘*********************************//*******************************by:lhc****************************************/#include#defineDataPortP0voiddelayms(unsigned
3、chari);sbitDQ=P1^3;sbitsclk=P1^4;sbitdate=P1^5;sbitrst=P1^6;sbitLATCH1=P2^2;//定義鎖存使能端口段鎖存sbitLATCH2=P2^3;//位鎖存unsignedchartime[8]={20,11,11,27,11,30,00,7};//年月日時(shí)分秒周unsignedchartime1[8],readtemflag;unsignedcharcodeDuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,
4、0x6d,0x7d,0x07,0x7f,0x6f};//顯示段碼值0~9unsignedcharcodeWeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分別對應(yīng)相應(yīng)的數(shù)碼管點(diǎn)亮,即位碼unsignedcharcodepingnian[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//平年的月份天數(shù)unsignedcharcodeyunnian[13]={0,31,29,31,30,31,30,31,
5、31,30,31,30,31};//閏年的月份天數(shù)unsignedcharTempData[8];//存儲顯示值的全局變量voiddelay(unsignedchari){while(--i);//us延時(shí)函數(shù)}voiddelayms(unsignedchari)//ms延時(shí)函數(shù){while(i--){delay(245);delay(245);}}bitrest(void)//18b20重啟函數(shù){bitk=0;DQ=1;delay(5);DQ=0;delay(150);delay(200);D
6、Q=1;delay(40);k=DQ;delay(25);return(k);}unsignedcharread()//18b20讀數(shù)據(jù)函數(shù){unsignedchari=0;unsignedchardat=0;for(i=0;i<8;i++){DQ=0;dat>>=1;DQ=1;if(DQ)dat
7、=0x80;delay(25);}return(dat);}voidwrite(unsignedchardat)//18b20寫數(shù)據(jù)函數(shù){unsignedchari=0;for(i=0;i<8;i++
8、){DQ=0;DQ=dat&0x01;delay(25);DQ=1;dat>>=1;}delay(25);}unsignedintReadTemperature(void)//讀取溫度函數(shù){unsignedchara=0;unsignedintkk=0,b=0;LOOP:if(rest()==0){write(0xCC);//跳過ROMwrite(0x44);//初始化溫度轉(zhuǎn)換delayms(20);rest();TH1=0XFa;TL1=0Xff;write(0xCC);write(0xBE)
9、;//讀取溫度a=read();b=read();b<<=8;kk=a+b;return(kk);}elsegotoLOOP;}voidrestds1302(void){sclk=0;rst=0;//ds1302重啟}voidwritebyte(unsignedcharaddr,unsignedcharbyte)//寫入ds1302一個(gè)字節(jié)數(shù)據(jù){unsignedchari;rst=1;addr=addr&0xfe;for(i=0;i<8;i++){date=addr&0x01;sclk=1;sc