Presentation is loading. Please wait.

Presentation is loading. Please wait.

5-4 4x4矩陣鍵盤控制實習.

Similar presentations


Presentation on theme: "5-4 4x4矩陣鍵盤控制實習."— Presentation transcript:

1 5-4 4x4矩陣鍵盤控制實習

2 自我練習 Demo Section 5-4-1 利用二位七段顯示器,當第一個鍵按下時,數字出現在右邊的顯示器上,當第二個鍵按下時,原來右邊的數字移到左邊的顯示器上,而新按下的鍵出現在右邊的顯示器上,其餘類推。 是2進制的編碼,可將16個按鍵編成0000~1111,但本實習電路的輸出是利用7447去推七段數字,故只能顯示0~9,當按下的是A~F時,將會出現無意義的符號。請修改程式,使得當按下的是0~9就正常顯示,當按下的是A~F時,則顯示〔0〕。 同問題2,但當按下的鍵是A~F時,則七段顯示器將不顯示 (完全熄滅)。 5-4-2 本實習單元的程式並沒有去處理5~F的按鍵,當5~F有一鍵被按下時,LED顯示的狀況並不是我們所要的,請修改程式,使得5~F的鍵被按下時,使8個LED全亮。 請擴展廣告燈變化的種類,使按下1~18都有不同的廣告燈變化。 修改程式,使得當5~F的鍵被按下後,顯示出這些鍵的值(即5~F)。 Demo Demo

3 4矩陣鍵盤控制實習 8051 P1 P3.2 (INT0) ?

4 11 10 1110 1101 1011 0111 按下 放開 DOA (to P1.0) DOB (to P1.1)
按下 放開 To P3.2 (INT0) Ground. 00 01 10 11 DOA (to P1.0) DOB (to P1.1) DOC (to P1.2) DOD (to P1.3) P1.0 Vdd P1.1 P0.0 P1.2 P0.1 P1.3 P0.2 P1.4 P0.3 P1.5 P0.4 P1.6 P0.5 P1.7 P0.6 RESET P0.7 P3.0 (RXD) _EA/Vpp P3.1 (TXD) ALE/_PROG P3.2 (_INT0) _PSEN P3.3 (_INT1) P2.7 P3.4 (T0) P2.6 P3.5 (T1) P2.5 P3.6 (_WR) P2.4 P3.7 (_RD) P2.3 X2 P2.2 X1 P2.1 Vss P2.0 1110 1101 1011 0111 無 有 按 按 11 10

5 Exercise Exercise 說明按一個鍵後,硬體上如何處理。

6 Bounce

7 1 2 3 4 5 6 7 8 9 A B C D E F ↓ ↓ ↓ ↓ To P1 of 8051

8 Interrupt vector locations
Number Interrupt Vector Address (in the program memory) Description 0003H EXTERNAL 0 (i.e., INT0) 1 000BH TIMER/COUNTER 0 2 0013H EXTERNAL 1 (i.e., INT1) 3 001BH TIMER/COUNTER 1 4 0023H SERIAL PORT 5 002BH TIMER/COUNTER 2 (For 8052 only)

9 Program 5_4_1 Turn on SW2_3 0000H 02H 0001H 01H 0002H 00H 0003H 10H
ORG 000H JMP START ORG 003H JMP INT ; Interrupt vector of INT0 ORG 100H START: MOV SP,#30H ; SP = stack pointer MOV P1,#0FFH ; I/O port 當作input port時,其值必須先設為1. MOV P2,#0 MOV IE,# B ; Set EA and EX0 CLR IT0 JMP $ ;============================== INT0: ; Q: INT0 = ?H CLR EX ; disable INT0 MOV A,P1 ANL A,#0FH MOV P2,A SETB EX ; to enable INT0 RETI END SP Two types of RETURN instruction: RET for subprogram RETI for interrupt service routine

10 Set before use an input port! Why?
8051 D Q Port latch > pin Pull-up Internal data bus Vcc Read latch Read pin Write to latch Mackenzie p.23 Circuit diagram of an I/O port

11 Set before use an input port! Why?
If the previous output was “1”: 8051 D Q Port latch > pin Pull-up Internal data bus Vcc Read latch Read pin Write to latch Mackenzie p.23 Circuit diagram of an I/O port

12 Set before use an input port! Why?
If the previous output was “0”: 8051 D Q Port latch > pin Pull-up Internal data bus Vcc Read latch Read pin Write to latch Mackenzie p.23 Circuit diagram of an I/O port

13 P21

14 p.74 EA = 0  to disable all interrupt
EA = 1  to allow each interrupt to be enabled

15 p.75

16 5-4-1自我練習的問題1 由此例題你可以實際體驗edge triggering 和level triggering 的不同效果。

17 5-4-2 鑑盤控制(二)

18 I5_4_2.asm .SYMBOLS ON ORG 0000H SHOW4: JMP START MOV A,#10000000B
NEXT2: ORG 003H CJNE R0,#4,TEST JMP INT0 ORG 100H START: RR A MOV SP,#30H JMP NEXT2 MOV IE,# B CLR IT0 ;============================== MOV P1,#0FFH INT0: MOV P2,#0 CLR EX0 PUSH A MOV R0,#0 MOV A,P1 TEST: ANL A,#0FH CJNE R0,#0,SHOW1 MOV R0,A JMP TEST POP A SETB EX0 SHOW1: RETI CJNE R0,#1,SHOW2 MOV P2,#0FFH CALL DELAY ; DELAY 0.1S MOV P2,#00H DELAY: JMP SHOW1 MOV R6,#200 DL1: SHOW2: MOV R7,#249 CJNE R0,#2,SHOW3 DJNZ R7,$ MOV P2,#0FH DJNZ R6,DL1 RET MOV P2,#0F0H END JMP SHOW2 SHOW3: MOV A,# B NEXT1: CJNE R0,#3,SHOW4 MOV P2,A RL A JMP NEXT1

19 5-4-2自我練習的問題3 問題3:修改程式,使得當5~F的鍵被按下後,顯示出這些鍵的值(即5~F)。


Download ppt "5-4 4x4矩陣鍵盤控制實習."

Similar presentations


Ads by Google