51單片機流水燈、數(shù)碼管、定時器、秒表、計算器程序_第1頁
51單片機流水燈、數(shù)碼管、定時器、秒表、計算器程序_第2頁
51單片機流水燈、數(shù)碼管、定時器、秒表、計算器程序_第3頁
51單片機流水燈、數(shù)碼管、定時器、秒表、計算器程序_第4頁
51單片機流水燈、數(shù)碼管、定時器、秒表、計算器程序_第5頁
已閱讀5頁,還剩27頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、流水燈#include<reg52.h>chardata_group=0x7e,0xbd,0xdb,0xe7,0xclb,0xbclr0x7e);unsignedinta;voiddelay(unsignedinttime)(inti,j;for(i=time;i>Oii-)for(j=100;j>0;j-);)voidmove_mid_side(void)(intm;for(m=0;m<7;m+)P1=data_groupm;delay(500);)voidmove_right_only(void)(inta,temp;delay(500);temp=0x80;

2、for(a=7:;a>=0;a_)temp=temp;P仁temp;delay(500);temp=-temp;temp»=1;temp=0x80;delay(IOOO);)voidmove_left_only(void)(inta5temp;delay(500);temp=0x01;for(a=7:;a>=0:a_)temp=Meinp;P仁temp;delay(500);temp二temp;temp«=1;Itemp=OxO1;delay(IOOO);)voidmoverighthlod(void)(inta,temp;temp=0x7f;for(a=8;a

3、>=0;a_)P仁temp;delay(500);temp=temp»1;)temp=Hemp;delay。000);)voidmovejefthold(void)(inta,temp;temp=0xfe;for(a=8;a>=0;a_)P仁temp;delay(500);temp«=1;)temp=temp;delay(1000);)voidmain()(while(1)move_left_hold();move_mid_side();move_right_hlod();move_mid_side();move_left_only();move_right_o

4、nly();數(shù)碼管#inelude<reg52.h>chardataduan=0xc0,0xf9,0x34,0x50,0x99,0x92,0x82,0xf8,0x80,0x90)chardata_wei=0xff,0x7f,0xbfQxdf,0xM0xf7,0xfbQxfd,0xfe,0x00;/Oxff全繞之后為第畸鱗人懂/chardata_wei_add=0x7f,0x3f,0x1f,OxOf,0x07,0x03,0x01,0x00;voiddelay(unsignedinttime)(intij;for(i=time;i>0;i-)for(j=O;j<100;j+

5、);)voidshow_numbeionly(void):inti;P2=data_wei1;P2為位選for(i=0;i<10;i+)PO=data_duaniJ;P0為段選delay(500);)voidmove_show1(void)/*數(shù)碼管動態(tài)顯示子程序.*/inti;for(i=1;i<2;i+)P2=data_weii;P0=data_duani;delay(1);)voidmove_show2(void)(inti;for(i=1;i<3;i+)P2=data_weii;PO=data_duani;delay;voidmove_show3(void)(inti

6、;for(i=1;i<4;i+)P2=data_weii;PO=data_duani;delay(1);)voidmove_show4(void)(inti;for(i=0;i<5;i+)P2=data_weii;PO=data_duani;delay(1);)voidmove_show5(void)(inti;for(i=0;i<6;i+)P2=data_weii;PO=data_duani;delay;)voidmove_show6(void)(inti;for(i=0;i<7;i+)P2=data_weii;PO二dataduani;delay;)voidmove

7、_show7(void)(inti;for(i=0;i<8;i+)P2=data_weii;PO=data_duani;delay(1);voidmove_show8(void)(inti;for(i=0;i<9:i+)(P2=data_weii;PO=data_duani;delay(1);)/*數(shù)碼管動態(tài)顯示,實現(xiàn)數(shù)碼管由1在八個數(shù)碼管上一次顯示mjvoidmove_show_hold(void)(inttempsi;temp=1000;.for(i=temp;i>0;i-)move_show1();temp=600;for(i=temp;i>0;i-)move_s

8、how2();temp=400;for(i=temp;i>0;i-)move_show3();temp=200;for(i=temp;i>0;i-)move_show4();temp=200;for(i=temp;i>0;i-)move_show5();temp=200;for(i=temp;i>0;j-)move_show6();temp=100;for(i=temp;i>0;i-)move_show7();temp=100;for(i=temp;i>0;i-)move_show8();void show all(void)將所有的位選端口打開,變化段選,

9、顯示整體變化1-9inti;P2二datawei9;for(i=0;i<10;k+)PO=data_duani;delay(500);intmain(void)(while(1)Jtfshow_numberonly();move_show8();/moveshowhold。;0o*</show_all();.獨立按鍵#inelude<reg52.h>sbitkey1=P3A0;sbitd2=P1A0;inttemp,number=0;voiddelay(unsignedinttime)intij;for(i=time;i>0;i-)(for(j=100;j>

10、0;H;intmain(void)(temp=0xfe;while(1)d2=1key1=1;.P仁temp;if(key1=0)delay(100);if(key1=O)number+;:if(number<=7)temp=Hemp;temp=temp«1;temp=Hemp;P仁temp;else'temp=Oxfe;number=O;)矩陣按鍵#include<reg52.h>chardata_duan=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,Oxf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,

11、0x8e,;/0-9chardata_wei=0xff,0x7f,0xbf,0xdf,0xet0xf7,0xfb,0xfd,0xfe50x00);intnumber=O:voiddelay(unsignedinttime)(intij;for(i=time;i>0;i-)for(j=0;j<l00;j+);/voidmove_show1(void)催/inti;/for(i=1;i<2;i+)/P2=data_weii|;P0=data_dua叩;/delay;/)11/voidmove_show2(void)/inti;Hfor(i=1;i<3;k+KHP2=data

12、_weiiJ;/P0=data_duadelay(1);voidsean_key(void)inttemp;P仁Oxfe;temp=P1;temp=temp&0xfO;while(temp!=OxfO)delay(1);temp=P1;temp=temp&OxfO;while(temp!=OxfO)switch(temp)caseOxeO:number=12;break;caseOxdO:number=13;break;caseOxbO:number=14;break;case0x70:number=15;break;while(temp!=OxfO)temp=P1;temp=

13、temp&0xfO;)P1=Oxfd;temp=P1;temp=temp&0xfO;while(temp!=OxfO)delay(1);temp=P1;temp=temp&OxfO;while(temp!=OxfO)switch(temp)caseOxeO:number=8;break;*"r,ocaseOxdO:number=9;break;caseOxbO:number=10;break;case0x70:number=11jbreak;while(temp!=OxfO)temp=P1;temp=temp&0xfO;)P1=Oxfb;temp=P1

14、;temp=temp&0xfO;while(temp!=OxfO)delay;temp=P1;temp=temp&OxfO;while(temp!=OxfO)switch(temp)caseOxeO:number=4;break;caseOxdO:number=5;break;caseOxbO:number=6;break;case0x70:number=7;break;)while(temp!=OxfO)temp=P1;temp=temp&0xfO;P1=0xf7;temp=P1;temp=temp&0xfO;while(temp!=OxfO)delay;te

15、mp=P1;temp=temp&OxfO;while(temp!=OxfO)switch(temp)caseOxeO:number=O;break;caseOxdO:number=1;break;caseOxbO:number=2;break;case0x70:number=3;break;while(temp!=OxfO)temp=Pl;temp=temp&OxfO;)/returnnumber;.intmain(void)(intnum=O;while(1)/num=scan_key(num);4sean_key();P2=data_wei1;PO=data_duannum

16、ber;定時器中斷#inelude<reg52.h>chardata_duan=OxcO,0x19,0x34,0x60,0x99,0x92,0x82,0x(8,0x80,0x90;/0-9chardata_wei=0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x00;/Oxff全美,之后為第一個數(shù)碼管到第八個數(shù)碼管intnumber=0,time=0;intmain(void)/TMOD=0x01;設(shè)置工作方式定時器0、1人V/THO=(65536-50000)/256;a/TL0=(65535-50000)%256-;/EA=1;給計

17、數(shù)器裝初值"b開總中斷/ET0=1;TR0=1;TMOD=0x10;設(shè)置工作方式定時器TH1=(65536-50000)/256;TL1=(65535-50000)%256;EA=1;ET仁1;TR1=1;while(1)if(number=20)P2=data_wei2;定時器T。中斷允許啟動定時器01給計數(shù)器裝初值開總中斷定時器T1中斷允許啟動定時器1PO=dataduan4;if(time=40)P2=data_wei0;number=O;time=O;)voidexter3()interrupt3TH1 =(65536-50000)/256;給計數(shù)器裝初值TL1=(65535

18、-50000)%256;time+;number+;)/voidexterl()interrupt1/THO=(65536-50000)/256;給計數(shù)器奘初值/TL0=(65535-50000)%256;/time+;/number+;陰時鐘#inelude<reg52.h>chardata_duan=0xc0,0xf9,0xa430xb0,0x99,0x92,0x82,0xf8,0x80,0x90;/0-9a>chardata_wei=0xff,0x7f,0xbf,0xdf,0xef,0xf730xfb,0xfd,0xfeJ0x00;unsignedlongintseco

19、nd=0,minute=0,hour=0,point=O,tip=O;unsignedlonginttime=0,sign=0,number=0,key=0,variable=0;unsignedlongintS仁0,S2=0,M1=0,M2=0,H1=0;H2=0;voiddelay(unsignedinttime)intij;for(i=time;i>0;i-)for(j=O;j<100;j+);voidkey_scan(void)inttemp;應(yīng)用按鍵檢測/ / / / / / */ / / H / / / /P仁0xf7;temp=Pl;temp=temp&0xf

20、O;while(temp!=OxfO)delay;temp=P1;temp=temp&OxfO;while(temp!=OxfO)switch(temp)caseOxeO:number=1;break;caseOxdO:number=2;break;caseOxbO:number=3;break;case0x70:number=4;break;)while(temp!=OxfO)(temp=P1;temp=temp&0xfO;P仁Oxfb;/temp=Pl;/temp=temp&0xfO;.while(temp!=OxfO)delay;temp=P1;temp=temp

21、&OxfO;while(temp!=OxfO)switch(temp)caseOxeO:nuinber=5;break;caseOxdO:nunnber=6;break;caseOxbO:number=7;break;case0x70:number=8;break;while(temp!=OxfO)temp=Pl;temp=temp&0xfO;)/)voidadjust_alarm(void)if(number=1)控制時鐘的后動與停止key=!key;if(key=1)EA=0;variable=time;)if(key=O)EA=1;)number=O;if(number=

22、2)調(diào)節(jié)時間選擇標(biāo)志位tip=tip+1;tip=tip%6;if(tip=O)tip=6;)number=O;)if(number=3)&&(EA=0)if(tip=1)if(tip=2)time=time-10;if(tip=3)time三time-60;if(tip=4)time=time-600;if(tip=5)time=time-3600;if(tip=6)time二time-36000;number=0;)if(number=4)&(EA=0)if(tip=1)time=time+1;if(tip=2)/ It / / H / / / / / / time

23、=time+10;if(tip=3)time=time+60;if(tip=4)time=time+600;if(tip=5)time=time+3600;if(tip=6)time=time+36000;number=O;if(number=5)&&(EA=O)variable=variable-1;if(tip=2)variable=variable-10;if(tip=3)variable=variable-60;jf(tip=4)variable=variable-600;if(tip=5)variable=variable-3600;if(tip=6)variable

24、=variable-3600;number=O;number=6)&(EA=O)/if(tip=1)/variable=variable+1;if(tip=2)/variable=variable+10;/if(tip=3)/variable=variable+60;/if(tip=4)/variable=variable+600;"if(tip=5)/variable=variable+3600;/if(tip=6)/variable=variable+36000;/number=O;voidcompare_time(void)(if(time>variable)J)

25、voidalarmshows(void)(intsign2;for(sign2=1;sign2<2;sign2+)n數(shù)碼管動態(tài)顯示S仁second%10;P2=data_weisign2;lPO=datajLduanS1;delay;).*for(sign2=2;sign2<3;sign2+)S2=second/10;P2=data_weisign2;PO=data_duanS2;delay;)for(sign2=3;sign2<4;sign2+)P2=data_weisign2;PO=Oxbf;delay;)for(sign2=4;sign2<5;sign2+)M仁minute%10;P2=d

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論