版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、百度文庫讓每個人平等地提升自我第二章任務(wù)一:閃爍廣告燈的設(shè)計(jì)利用89c51單片機(jī)的端口控制兩個LED (DO和DD,編寫程序,實(shí)現(xiàn)兩個LED互閃。#includc#define uint unsigned int#define uchar unsigned charsbit LED1=POAO;sbit LED2=POA1;void delayms(uint ms)(uint i;while(ms-)(for(i=0;iD3-D4-D5 -D6-D7 ,然后再點(diǎn)亮D7-D6-D5-D4 -D3-D2-Dl-D0,重復(fù)循環(huán)。#includeinclude #dcfine uint unsigne
2、d int#dcfine uchar unsigned charuint i;uchar temp;uint a8=0xfe,0xfd.0xfb,0xf7,0xet0xdf.0xbL0x7f);void delayms(uint ms)(while(ms-) uintj;for(j=0;j120;j+);)void inain()(while(l)(PO=Oxfe;while(P0!=0x7f) (/Pl=temp;/delayms(500);PO=_croljPO,l); de!ayms(25O);)temp=0x7f;while(P0!=0xfe)(P0=temp;delayms(500)
3、;temp=_cror_(temp, 1);)任務(wù)三:拉幕式與閉幕式廣告燈的設(shè)計(jì)利用89C51單片機(jī)的P0端口實(shí)現(xiàn)8個LED D0D7的拉幕式與閉幕式廣告燈設(shè)計(jì)。拉幕式:開始D0D7全滅,延時片刻后首先D3和D4亮,其次是D2和D5亮,再是D1 和D6亮,最后是DO和D7亮。閉幕式:開始D0D7全亮,延時片刻后首先DO和D7火,其次是D1和D6火,再是D2 和D5滅,最后是D3和D4滅。#include#dcfine uint unsigned int#dcfine uchar unsigned charuchar code table= 0xe7,0xc3,0x81,0x00);void d
4、elay(uint x)(uint ij;for(i=x;i0;i-)for(j=120;j0;j-);)void inain()2百度文庫讓每個人平等地提升自我uint i;while(l)Pl=Oxff;delay(500);for(i=0;i0;i-)(Pl=tablei-1;delay(500);)任務(wù)四:復(fù)雜廣告燈的設(shè)計(jì)利用89c51單片機(jī)的端口實(shí)現(xiàn)8個LED (D0-D7)復(fù)雜廣告燈的控制,要求顯示規(guī)律為: 正向流水會反向流水。隔燈閃爍3次-高四盞、低四盞閃爍2次-隔兩盞閃爍3次,再重復(fù) 循環(huán)。#include#define uint unsigned int#includevoi
5、d delayms(uint ms)(uint i;while(ms-)for(i=0;i110;i+);)void main()(uint ijAx2=0xaa,0xff,yy2=0xf0,0x0f,zz2=0xb6.0xff);unsigned char aa;while(l)(aa=Oxfe;for(i=0;i7;i+)(P0=aa;aa=_crol_(aa.l);delayms(500);)for(i=0:i8;i+)(PO=aa;aa=_cror_(aa.l);delayms(500);)for(i=0;i3;i+)for(j=0;j2;j+)(PO=xxj;delayms(500)
6、;)for(i=0;i2;i+)for(j=0;j2;j+)(Po=yylil ; delayms(500);)for(i=0;i3;i+)for(j=0;j2;j+)(PO=zzjl ; delayms(500);)任務(wù)五:單個LED數(shù)碼管顯示設(shè)計(jì)使用89C51的P0 作為輸出口,外接LED數(shù)碼管,編寫程序,使數(shù)碼管循環(huán)顯示從9 的加1計(jì)數(shù)。#include#define uint unsigned int#define uchar unsigned charuchar table10= 0X80XF9.0XA4.0XB0,0X99.0X92,0X82,0XF8,0X80,0X90);uin
7、t key=0;void int_int()(EA=1;IT0=l;EX0=l;)void count_num() interrupt 0(if(key=9)key=0;else key+;)void main()(intjnt();whiled)(PO=tablekey;)任務(wù)六:多個LED數(shù)碼管顯示設(shè)計(jì)使用單片機(jī)P0和P2 口作為輸出口,外接一個8位LED數(shù)碼管,編寫程序,使數(shù)碼管顯示 “872AF635”。#include#include#dcfine uint unsigned int#dcfine uchar unsigned chardclay(ms)(while(ms-) int
8、 i;for(i=0;i110;i+);)inain()(uchara 16=0xc0.0xf9.0xa4.0xb0,0x99.0x92,0x82,0xf8,0x80,0x90.0x88,0x83.0xc6.0xaL0x86.0x8e);uchar b8= 0x08.0x07,0x02,0x0a,0x0f,0x06.0x03,0x05 j;uint i;while(l)j=0x01;for(i=0;i8;i+)(P2=j;PO=abi;j=_crol_(j,l);delay ;)任務(wù)七:查詢式按鍵設(shè)計(jì)將8個按鍵從18進(jìn)行編號,如果其中一個鍵被按下,則在LED數(shù)碼管上顯示相應(yīng)的鍵值。#inclu
9、de#dcfine uint unsigned int#dcfine uchar unsigned char inain()(uchara16=0xc0.0xf9.0xa4.0xb0.0x99.0x92.0x82.0xf80x80,0x90.0x88.0x83,0xc6,0xal,0x86,0x8e;PO=Oxff;while(PO!=Oxff) switch(PO)case Oxfe:P2=al; break;case Oxfd:P2=a;break;case Oxfb:P2=a3; break;case 0xf7:P2=a4; break;case Oxef:P2=a5; break;ca
10、se Oxdf:P2=a6; break;case Oxbf:P2=a7; break;case 0x7f:P2=a8;)任務(wù)八:LED數(shù)碼管顯示矩陣鍵盤按鍵的設(shè)計(jì)設(shè)計(jì)一個4*4的矩陣鍵盤,以PL0P1.3作為行線,以PL4PL7作為列線。要求:未按下 按鍵時,LED數(shù)碼管顯示按下按鍵時,在數(shù)碼管上顯示相應(yīng)的鍵值。#include#dcfine uchar unsigned char#dcfine uint unsigned intuchartable 17=0xbf.0xc0,0xf9.0xa4,0xb0.0x99,0x92.0x82,0xf8.0x80.0x90.0x88,0x8350xc
11、6,0xa L0x86,0x8e;uint num=0;void delay(uint x)(uchar ij;for(i=x;i0;i-) for(j=120;j0;j-);)keyscan() uint temp;temp=P2:temp&=0x0f;if(temp=0x0e)(P2=OxfO;temp=P2:temp&=0xf0;switch(temp)(case OxeO:num=l;break;case OxdO:num=2;break; case 0xb0:num=3;break; case 0x70:num=4;)if(temp=0x0d)(P2=OxfO;temp=P2:tem
12、p&=0xf0;switch(temp)(case 0xe0:num=5;break;case 0xd0:num=6;break;case 0xb0:num=7;break; case 0x70:num=8;)if(temp=0x0b)(P2=OxfO;temp=P2;temp&=0xf0;switch(temp)(case 0xe0:num=9;break; case 0xd0:num=10;break; case OxbO:num=ll;break; case 0x70:num=12;)if(temp=OxO7)(P2=OxfO;temp=P2;temp&=OxfO;switch(tcmp
13、)(case OxeO:num=13;break; case 0xd0:num=14;break; case OxbO:num=15;break;case 0x70:num=16;return num;)void display(uint num) if(nuin=O)PO=Oxbf;PO=tablenum;)niain()(uint temp;while(l)(P2=0x0f;temp=P2;if(temp!=OxOf) keyscan();display(num);)(2)#include#dcfine uchar unsigned char#dcfine uint unsigned in
14、t sbit LED1=P2AO;sbit LED2=P2A1:uchar num:uchar code LED_code=(0xc0.0xf9,0xa4,0xb0, 0x99.0x92.0x82.0xf8, 0x80,0x90.0x88,0x83, 0xc6.0xa 1.0x86,0x8e); 數(shù)碼管字形碼編碼void dclay(uint x)(uchar ij;for(i=x;i0;i-) for(j=120;j0;j-);)延時函數(shù)void display(uchar num)(P0=LED_codenum;)數(shù)碼管顯示函數(shù)void keyscan()鍵盤掃描函數(shù)(uchar temp
15、;P1 =0xfe;/key 1 -key4 第一行按下 temp=Pl;temp&=0xf0: if(temp!=OxfO) (delay(lO),消除抖動temp=Pl;temp&=0xf0; if(temp!=OxfO) (temp=Pl;switch(temp) ( case Oxee:num=l;break;case Oxde:num=2;break:case Oxbe:num=3;break:case 0x7e:num=4: break:) ) whiIe(temp!=OxfO)等待按鍵釋放 (temp=Pl;temp&=OxfO;)P1 =0xfd;/key5-key8 第二行按
16、下temp=Pl;temp&=OxfO: if(temp!=OxfO) (delay(lO),消除抖動temp=Pl;temp&=OxfO;if(temp!=OxfO) (temp=Pl;switch(temp) (case Oxed:num=5;break;case Oxdd:num=6;break:case Oxbd:num=7;break;case 0x7d:num=8;break:) ) while(temp!=OxfO)等待按鍵釋放 (temp=Pl;temp&=OxfO:)P1 =0xfb;key9-key 12 第三行按下temp=Pl;temp&=OxfO;if(temp!=O
17、xfO)delay(lO),消除抖動temp=Pl;temp&=OxfO;if(temp!=OxfO) (temp=Pl;switch(temp) (case Oxeb:num=9;break:case Oxdb:num=10;break;case Oxbb:num=ll;break:case Ox7b:num=12; break;)while(temp!=OxfO)等待按鍵釋放 (temp=Pl;temp&=OxfO;)Pl=Oxf7:/keyl3-key 16 第四行按下 temp=Pl;temp&=OxfO:if(temp!=OxfO) (delay(lO),消除抖動temp=Pl;te
18、mp&=OxfO;if(temp!=OxfO)temp=Pl;switch(temp)case 0xe7:num=13;break;case Oxd7:num=14;break:case Oxb7:num=15;break;case 0x77:num=16;break:)while(temp!=0xf0)等待按鍵釋放(temp=Pl;temp&=OxfO:)void inain()(while(l)(keyscan();if(num=0)PO=Oxbf;elsedisplay(num-l);)任務(wù)九:簡單撥號鍵盤的設(shè)計(jì)使用4*4的矩陣式鍵盤及8位共陽極LED數(shù)碼管設(shè)計(jì)一個簡單撥號鍵盤,要求在初
19、始狀態(tài) 時,8位數(shù)碼管均顯示每按下一個號碼后,原8位LED數(shù)碼管顯示的內(nèi)容向左移動1 位。#includc#include#dcfine uint unsigned int#dcfine uchar unsigned charuchar keycount=0.num;uchar code LEDl_code=0xc0,0xf9,0xa4.0xb0,0x99,0x92,0x82,0xf8,0x80,0x90.0x88,0x83, 0xc6.0xa 1,0x86.0x8e);數(shù)碼管字形碼編碼uchar LED2_duan8=0xbL0xbf0xbf.0xbf.0xbf0xbC0xbL0xbfy/8
20、 段共陽數(shù)碼管編碼 uchar LED2_wei8= 0x80,0x40,0x20,Ox 10,0x08,0x04,0x02,0x01;void dclay(uint x)(uchar i,j;for(i=x;i0;i-) for(j=120;j0;j-);)void displayO(uchar i;/P2=0x80;for(i=0;i8;i+) (P2=LED2_weii;P0=LED2_duan7-i; dclay(l);)void keyscanO(uchar temp;P3=0xfe;temp=P3;temp&=OxfO;if(temp!=OxfO)(delay(lO);temp=P
21、3:temp&=0xf0;if(temp!=OxfO) (temp=P3;switch(temp) (case Oxee:keycount+:num=0:break;case Oxde:keycount+;num= I ;break:case 0xbe:keycount+;num=2;break:case Ox7e:keycount+;num=3;break:)while(temp!=OxfO)(temp=P3;temp&=OxfO:)P3=0xfd;temp=P3;temp&=OxfO:if(temp!=OxfO)(delay(lO);tenip=P3;temp&=OxfO;if(temp!
22、=OxfO)(temp=P3;switch(temp)(case 0xcd:keycount+;num=4;break;case Oxdd:keycount+;num=5;break;case 0xbd:keycount+;num=6;break;case Ox7d:keycount+;num=7;break;)while(temp!=OxfO)(temp=P3;temp&=OxfO;)P3=Oxfb;temp=P3;temp&=OxfO;if(temp!=OxfO)(dclay(lO);temp=P3:temp&=OxfO;if(temp!=OxfO)teinp=P3;switch(temp
23、)(case Oxeb:keycount+;num=8;break:case 0xdb:keycount+;num=9;break;case 0xbb:keycount+;num=10;break;case Ox7b:keycount+;num=l 1 ;break; )while(temp!=OxfO)(temp=P3;temp&=OxfO;)P3=0xf7;temp=P3;temp&=OxfO;if(temp!=OxfO)(delay(lO);temp=P3:temp&=OxfO;if(temp!=OxfO)(temp=P3;switch(temp)(case Oxe7:keycount+
24、;num=12;break:case Oxd7:keycount+;num=13;break;case 0xb7:keycount+;num=14;break;case Ox77:keycount+;nuin= 15;break; )while(temp!=OxfO)(temp=P3;temp&=OxfO;)void main()uchar i;while(l) displayO;keyscan();if(keycount!=0) ( for(i=0;i右移流水一隔燈閃爍3次花樣顯示:如果按下K鍵 后,8只LED暫停默認(rèn)顯示,而進(jìn)行閃爍顯示,當(dāng)顯示達(dá)到5次后,繼續(xù)按默認(rèn)規(guī)律顯示。#includ
25、e#define uint unsigned int#define uchar unsigned charuint LED_table14=0xfe,0xfd,0xfb.0xf7.0xef.0xdf,0xbf,0x7f,0xbt0xdt0xef.0xf7.0xfb,0xfd; void delayms(uint ms)(uint i;while(ms-)for(i=0;i120;i+);)void intjnt()(EA=1;EXO=1;ITO=1;void LED_shan() interrupt 0 (uint k;for(k=0;k5;k+)(P0=0xaa;delayms(500);P
26、O=Oxff;delayms(500);)void mainO(int_int();while(l)(uint i;for(i=0;i14;i+)(PO=LEDjablei;delayms(500);)for(i=0;i3;i+)(P0=0xaa;delayms(500);PO=Oxff;delayms(500);)任務(wù)二:采用外中斷控制的條形LED彩燈設(shè)計(jì)P0端口作為輸出口,外接條形LED。編寫程序,當(dāng)按鍵K未按下時,LED進(jìn)行循環(huán)左移顯 示。如果第1次按下按鍵KB, LED進(jìn)行循環(huán)右移顯示。如果第2次按下按鍵KB, LED 進(jìn)行拉幕式與閉幕式花樣顯示。如果第3次按下按鍵K后,又恢復(fù)循環(huán)左移
27、顯示。狀態(tài)標(biāo)志位 /LED映射位 花樣數(shù)組#include unsigned char flag=O; unsigned char led =0; unsigned char tableJ= 0x00.0x81 .Oxc30xe7,180xff.0xe7,0xc3.0x81 先閉幕式再開幕式 void dclayms(unsigned int ms);void syslnit(void);void stepO(void);void step 1 (void);void step2(void);void main(void)(syslnit();while(l) switch(flag)延時函數(shù)
28、系統(tǒng)初始化狀態(tài)0狀態(tài)1狀態(tài)2初始化系統(tǒng)case 0:stepO();brcak:case 1: stepl();break:case 2: step2();break:default:break;)P0 = -led; 將led值映射到LED燈 delayms(500);延時 500ms ) ) void delayms(unsigned int ms) ( unsigned char i; for (;ms:nis-)for (i=110;i;i-);)void syslnit(void) (EX0=l;打開外部中斷0 EA =1;打開總中斷 IT0=l; 外部中斷。下降沿觸發(fā) ) void
29、 stepO(void) ( led =1;左移 if (led=0) 溢出處理 led = 0x01;)void step 1 (void) (led =1;右移 if(led=O) 溢出處理 led = 0x80;)void step2(void) (static char t;led = tablet+;開幕閉幕花樣顯示if (t=8)t = 0;)void EX_0() interrupt 0 外部中斷0服務(wù)函數(shù)flag+:百度文庫讓每個人平等地提升自我if (flag=3) flag = 0;)(2)#incl ude 頭文件#define uchar unsigned char#d
30、cfine uint unsigned int 宏定義uchar temp.key-count;uchar code tab=開幕式閉幕式編碼0x00,0x81,0xc3,0xe7,0xff,0xe7,0xc3.0x81;void dclay(uint ms) 延時子函數(shù)(uint i j;for(i=ms;i0;i-) for(j=0;j=8) count=0:)void init()百度文庫讓每個人平等地提升自我EA=1;EXO=1;ITO=1;temp=O;key_count=0;)void main()(init();whiled)(switch(key_count) (case 0:
31、 loop_le ft mo ve() ;bre ak;case 1 :loop_rightmove();break;case 2:open_close();break: default:break;)PO=-temp;dclay(25O);)void keyJntcrruptO interrupt 0外部中斷 INTO 中斷服務(wù)程序(key_count+;key_count%=3;/*if(key_count=3) key_count=0;*/ )任務(wù)三:采用兩個外中斷的LED彩燈控制P0端口作為輸出口,外接8只LED, P3.2外接按鍵KI, P3.3外接按鍵K2,編寫程序,沒 有按下任何
32、按鍵時,LED隔燈閃爍,當(dāng)按鍵K1為奇數(shù)次時,LED進(jìn)行左移流水-右移流水 顯示。當(dāng)按下按鍵K1為偶數(shù)次時,LED進(jìn)行拉幕式顯示;當(dāng)按下按鍵K2時,LED暫停顯 示,蜂鳴器發(fā)出“叮咚”的開門聲音,然后LED繼續(xù)花樣顯示(K2按鍵優(yōu)先)。#include#includc#dcfine uchar unsigned char#dcfine uint unsigned intsbit keyl=P3A2;sbit key2=P3A3;sbit beep=PlAO;uchar code tab=0xff0xe7,0xc3.0x8 L0x00.0x8 l,0xc3.0xe7,開幕式編碼uchar tem
33、p=OxOLkcy_count.fiag jight.beep_FG: void dclay(uint ms)(uint i,j;for(i=ms;i0;i-)for(j=110:j0;j-);)void init()(EA=1;打開總中斷EX0=l,打開外部中斷INTOEX1=1打開外部中斷INTIITO=1;/下降沿觸發(fā)方式下降沿觸發(fā)方式PX0=0;設(shè)置INTO為低中斷優(yōu)先級PX1=1;設(shè)置INT1為高中斷優(yōu)先級)void interval_LED()(PO=Oxff;delay(500);P0=0xaa;delay(500);)void Ieft_right_move()(if(!rig
34、ht)temp=_crol_(temp, 1);elsetemp=_crorjtemp, 1);if(temp=0x01)(right=O;)if(temp=0x80) right=l;)void open_LED()(uchar count;temp=tabcount+;if(count=8)count=0;)void BeepO(uchar i,j,k;for(i=100:i;i-)for(j=20;j;j-)Ifor(k=1000;k;k-j beep=-beep;)/*for(i=100;i:i-)for(j=200;j;j-)(for(k=1000;k;k-j beep=-beep;
35、*/beep_FG=0:)void main()(init();beep=O;while(l)(if(!flag)interval_LED();else(if(beep_FG)( BeepO;)else( switch(key_count%2) (case 1:Ieft_right_move();break: 奇數(shù)次按鍵左移右移顯示 case 0:open_LED();break: 偶數(shù)次按鍵拉幕式顯示 default:brcak;)PO=temp:dclay(400);)void keyl JnterruptO interrupt 0(flag=l;key_count+:)void key2
36、_intcrrupt() interrupt 2(flag=l;beep_FG=l;)任務(wù)四:采用兩個外中斷實(shí)現(xiàn)LED鍵控移位P0端口作為輸出口,外接8只LED, P3.2外接按鍵KI, P3.3外接按鍵K20編寫程序,要 求實(shí)現(xiàn)LED鍵控移位,按下按鍵K1時,8只LED左移1位;按下按鍵K2時,8只LED 右移1位。#include#include#define uint unsigned int#define uchar unsigned charuchar key 1 =0.key2=0.temp 1 =0 Jeinp2=0,tenip 11 =0,temp 12=0;/*void de
37、layms(uint ms) (uint i;while(ms-)for(i=0;i120;i+);)1*/ void intjnt() (EA=1;EX0=l;EX1=1;IT0=l;IT1 = 1;)void intO() internipt 0keyl+;)void intl() internipt 2(key2+;)void inain()(uchar a;intjnt();a=Oxfe;while( 1)(if(templ!=keyl)(PO = a;a=_crol_(a J);templ=keyl;)if(temp2!=key2)(PO = a;a=_cror_(a.l); key
38、2=temp2;)(2)#include#dcfine uint unsigned int#define uchar unsigned charuchar keyl =O,key2=Ojn.n.k;uchar table=0xfe.0xfd,0xfb,0xt7,0xet0xdf,0xbf.0x7f;void intjnt()(EA=1;EXO=1;ITO=1;EX1=1;IT1 = 1;)void intO() internipt 0keyl+; m=keyl%8: ) void int2() internipt 2 (key2+; n=key2%8; ) void inain() (intj
39、nt(); whiled) (k=(m-n+8)%8;PO=tablek; ) ) 任務(wù)五:采用外中斷實(shí)現(xiàn)計(jì)數(shù) 使用單片機(jī)PO、P2端口作為輸出口,外接一個2位LED數(shù)碼管,P3.2外接按鍵KI, P3.3 外接按鍵K2c編寫程序,每次按下K1時,LED數(shù)碼管進(jìn)行加1顯示;每次按下按鍵K2 時,LED數(shù)碼管進(jìn)行減1顯示,計(jì)數(shù)范圍為099。 #include 頭文件 #dcfine uint unsigned int 宏 定 義 #define uchar unsigned char 宏定義 uchar table=0xc0,0xf9,0xa4.0xb0,0x99.Ox920x82.Oxf8.O
40、x8O.Ox9O ;0-9 共陽字型碼編碼 char count=0: uchar shi.ge; void LED_scan()數(shù)碼管掃描子函數(shù) ( shi=count/10,分離十位 ge=count% 10分離個位 P2=table ge ;/ 顯示個位 PO=table sh i ;顯示十位 ) void int_int() 初始化 ( EA=1;打開總中斷EX0=l;打開外部中斷0EX1=1;打開外部中斷1IT0=l;設(shè)置下降沿觸發(fā)方式IT1 = 1;設(shè)置下降沿觸發(fā)方式) void main()主函數(shù)intjnt(); 調(diào)用初始化函數(shù)while(l)LED.scanO; 調(diào)用數(shù)碼管掃
41、描函數(shù) ) ) void intO() internipt 0外部中斷0服務(wù)程序count+;if(count=100)count=0:計(jì)數(shù)加1溢出操作)void int2() internipt 2外部中斷1服務(wù)程序count-;if(count0)計(jì)數(shù)減1溢出操作count=99;)(2)#include 頭文件#dcfine uint unsigned int 宏定義#dcfine uchar unsigned char 宏定義 uchar table=0xc0,0xf9,0xa4,0xb0,0x99.0x92,0x82.0xf8.0x80.0x90 ;0-9 共陽字型碼編碼char c
42、ount=0: uchar shi.ge;void delay(uint ms)延時子函數(shù) (uchar i;for(;ms;ms-) for(i=120;i;i);)void LED_scan()數(shù)碼管掃描子函數(shù)(shi=count/10,分離十位 ge=count% 10,分離個位 P2=0x01:個位對應(yīng)的數(shù)碼管點(diǎn)亮 PO=tablege;顯示個位 delay(l);P2=0x02;十位對應(yīng)的數(shù)碼管點(diǎn)亮PO=table sh i ;顯示十位 delay(l);)EA=1;打開總中斷EXO=1;打開外部中斷0EX1=1;打開外部中斷1ITO=1;設(shè)置下降沿觸發(fā)方式IT1=1;設(shè)置下降沿觸發(fā)
43、方式)void main()主函數(shù)(intjnt(); 調(diào)用初始化函數(shù) while(l) (LED.scanO; 調(diào)用數(shù)碼管掃描函數(shù))void intO() internipt 0外部中斷0服務(wù)程序count+;if(count=100)count=0:計(jì)數(shù)加1溢出操作)void int2() internipt 2 (count-;if(count0)count=99;外部中斷1服務(wù)程序計(jì)數(shù)減1溢出操作)任務(wù)六:采用外中斷進(jìn)行計(jì)數(shù)和清零控制使用單片機(jī)P0、P2端口作為輸出口,外接一個2位LED數(shù)碼管,P3.2外接按鍵KI, P3.3 外接按鍵K2.編寫程序,按鍵K2作為“加1/暫停/清零”控
44、制;按鍵K1作為加1計(jì)數(shù)控 制。當(dāng)按鍵K2沒有按下時,按鍵K1按下后LED數(shù)碼管總顯示為0:第1次按下鍵K2時, 每次按下KI, LED數(shù)碼管進(jìn)行加1顯示;第二次按下按鍵K2時,暫停加1計(jì)數(shù),按鍵K1 按下后LED數(shù)碼管顯示暫停前的數(shù)值:第3次按下按鍵K2時,LED數(shù)碼管顯示為0:第4 次按下按鍵K2時,與第1次類似。#include#dcfine uint unsigned int#define uchar unsigned charuchar key 1 =0.temp 1 =0.key2=0,ten】p2=0,key=0;uchar table=0XC0,0XF9,0XA4.0XB0,0
45、X99,0X92,0X82,0XF8,0X80,0X90);void dclayms(uint ms)while(ms-)uint i=0;for(i;i120;i+);)void int_int()(EA=1;EXO=1;EX1=1;ITO=1;IT1 = 1;)void intl() internipt 0(key2+;)void intO() internipt 2(keyl+;)void displayO(P2=0xfe;PO=tabIe tempi;delayms(2);P2=Oxfd;PO=tabletemp2J;delayms(2);)void main()(intjnt();w
46、hile(l)(templ=keyl%10;temp2=keyl/10;switch(key2%3) (case 0:while(l) (if(key2%3!=0) break;P2=0xfe;PO=tableO;delayms(2);P2=0xfd;PO=tableO;delayms(2);)key1=0;break:)case 1: displayO;break;case 2: key=keyl;while(l) (if(key2%3!=2) break;P2=0xfe;PO=tabIe tempi;delayms(2);P2=0xfd;P0=tabletemp2;delayms(2);)
47、keyl=key:break;)第六章任務(wù)一:簡單計(jì)數(shù)器的設(shè)計(jì)使用單片機(jī)P0, P2端口作為輸出口,外接一個2位LED數(shù)碼管,P3.4外接按鍵Kc編寫 程序,每次按鍵K按下時LED數(shù)碼管進(jìn)行加1顯示,計(jì)數(shù)范圍為099c #include#dcfine uint unsigned int#define uchar unsigned charuchar table=0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90);uchar key=O;void dclayms(uint ms)29百度文庫讓每個人平等地提升自我uint i;while(ms-)
48、for(i=0;i120;i+);)void intJntO(EA=1;ETO=1;開定時器0中斷TRO=1;啟動定時器0TMOD=0x05;設(shè)置工作方式為1選擇計(jì)數(shù)功能TH0=0xff;TLO=Oxff; 裝初值使得按一下就中斷)void intl() internipt 1(TH0=0xff;TL0=0xff;key+:)void displayO(P2=0xfe;P0=tablekey%10;delayms(3);P2=Oxfd;PO=tablekey/lO;delayms(3);)void inain()(intjnt();while(l)(displayO;if(key% 10=9&key/l 0=9)key=0;)#include#define uint unsigned int#define uchar unsigned charuchar tableJ=0XC0,
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《營銷法規(guī)實(shí)務(wù)》課件
- 養(yǎng)老院老人入住審批制度
- 養(yǎng)老院緊急救援制度
- 復(fù)習(xí)統(tǒng)計(jì)初步課件
- 2024年專用:20xx境外合資合同3篇
- 救護(hù)車掛靠私立醫(yī)院協(xié)議書(2篇)
- 《血透患教》課件
- 2024年環(huán)保材料研發(fā)與生產(chǎn)許可合同
- 2024年民間個人借貸協(xié)議范本集錦一
- 2024年版自駕游活動安全責(zé)任合同版B版
- 清水磚墻面修復(fù)專項(xiàng)施工方案
- 設(shè)備操作三好四會四項(xiàng)要求五項(xiàng)原則培訓(xùn)教材
- CCTV《開門大吉》選手報名表VM
- 乒乓球比賽用表
- 某公司項(xiàng)目部質(zhì)量管理體系及制度
- 關(guān)于開展全員營銷活動的實(shí)施方案
- 碩士開題報告和文獻(xiàn)綜述模板-北京理工大學(xué)研究生院
- 磚基礎(chǔ)工程量計(jì)算PPT課件
- 俄語視聽說基礎(chǔ)教程1
- 蝸輪蝸桿的設(shè)計(jì)及其參數(shù)計(jì)算
- 城鎮(zhèn)燃?xì)馐覂?nèi)施工及質(zhì)量驗(yàn)收規(guī)范(完整版)
評論
0/150
提交評論