Presentation is loading. Please wait.

Presentation is loading. Please wait.

5-6 串列埠模式0輸出埠擴充實習.

Similar presentations


Presentation on theme: "5-6 串列埠模式0輸出埠擴充實習."— Presentation transcript:

1 5-6 串列埠模式0輸出埠擴充實習

2 串列埠  模式0 Clock frequency = 12 MHz/12 = 1 MHz

3 TXD RXD 8051 Turn on these switches: SW1_1: SW1_6: SW2_1: SW2_2: SW1_6

4 SH/LD 74165 operation 1 The FFs in are shifted out by the clock. The FFs in are updated (loaded) with new values.

5 74164: 8-Bit Serial-Input/Parallel-Output Shift Register

6 Related registers

7 SCON register SM2:設定RI=1的時機 模式 SM2 SM2 = 0 1
SM2 = 0 1 SM2 = 1  UART 接收到正確的停止位元才會令RI = 1 2 & 3 SM2 = 1  UART 接收到第九個資料位元RB8=1才會令RI = 1。 SM2可做多處理器通信之控制。

8 Because the serial port is now used as an output port
SCON register SM0 SCON.7 SM1 SCON.6 SM2 SCON.5 REN SCON.4 To enable the serial port receiving REN = 0  UART not receiving REN = 1  UART receiving TB8 SCON.3 9th transmitted bit RB8 SCON.2 9th received bit or the stop bit TI SCON.1 TI = interrupt flag Mode 0: The 8th bit transmitted  TI = 1  Interrupt request to CPU Mode 1, 2, 3: The stop bit transmitted  TI = 1  Interrupt request to CPU RI SCON.0 RI = interrupt flag The 8th bit received  RI = 1  Interrupt request to CPU The stop bit received & SM2 ……. RI = 1  Interrupt request to CPU Because the serial port is now used as an output port

9 Programs 自我練習: 5-6-1-1 將程式中每一道 JNB TI,$ 與 CLR TI 指令去掉,再執行,觀看結果有無改變。
在程式執行過程中,分別將 SW1_1 與 SW1_6 撥至 OFF 位置,觀看執行結果有何變化。 在程式正常執行之下,以示波器觀察RXD與TXD接腳上之波形。 (Demo ) 設計一程式將一鍵盤中所鍵入之數字,透過串列埠,顯示在DS2七段顯示器上。

10 Programs Program 5-6-1 利用74164做I/O port 擴充,控制八個LED做五種變化的廣告燈控制。
1. 單一燈亮向右移動,執行四遍。 2.單一燈亮向左移動,執行四遍。 3.單一燈亮向左、右來回移動,執行二遍。 。 4. 四燈亮四燈滅交互顯示,執行四遍。 5. 由左右向中間移動,再往外移開,執行四遍。 Program 5-6-2 利用74164做I/O port 擴充,控制七段數字顯示器從00計數到99,再重覆。

11 TI becomes “1” when the 8th bit has been sent.
5-6-1程式重點 ORG 000H MOV SCON,# B ; Set Mode 0 START: ;============================== MOV R5,#4 ;SET COUNTER MOV A,# B NR1: RR A MOV SBUF,A ;SEND DATA JNB TI,$ ; TI = Transmission interrupt. ; TI will be set when the serial transmission through SBUF is done. CLR TI CALL DELAY JNB A.0,NR1 DJNZ R5,NR1 TI becomes “1” when the 8th bit has been sent.

12 ˋ Homework: JNB TI,$ CLR TI 這兩個指令去掉,程式是動作是否仍然正確?Why?

13 5-6-1 串列埠擴充做廣告燈控制

14 Program I5_6_1.ASM .SYMBOLS ON ORG 0000H JMP MAIN ORG 0050H MAIN:
MOV SCON,# B ;SET MODE 0 START: ;============================== MOV R5,#4 ;SET COUNTER MOV A,# B NR1: RR A MOV SBUF,A ;SEND DATA JNB TI,$ CLR TI CALL DELAY JNB A.0,NR1 DJNZ R5,NR1 MOV A,# B NL1: RL A JNB A.7,NL1 DJNZ R5,NL1 MOV R5,#2 ;SET COUNTER NR2: JNB A.0,NR2 NL2: JNB A.7,NL2 DJNZ R5,NR2 N3: MOV SBUF,#0F0H ;SEND DATA MOV SBUF,#0FH ;SEND DATA DJNZ R5,N3 N4: MOV A,#0 NDATA: PUSH A MOV DPTR,#TABLE MOVC POP A INC A CJNE A,#7,NDATA DJNZ R5,N4 JMP START TABLE: DB B DB B DB B DB B DB B ; DELAY 0.1S DELAY: MOV R6,#200 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 RET END

15

16 5-6-2 串列埠擴充做數字顯示控制

17 Program I5_6_2.ASM .SYMBOLS ON ORG 0000H JMP MAIN ORG 0050H MAIN:
MOV SCON,# B ;SET MODE 0 MOV A,#0 NEXT: MOV SBUF,A ;SEND DATA JNB TI,$ CLR TI CALL DELAY ADD A,#1 ;A=A+1 DA A ;BIN TO BCD JMP NEXT ;============================== ; DELAY 0.125S DELAY: MOV R6,#250 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 RET END

18


Download ppt "5-6 串列埠模式0輸出埠擴充實習."

Similar presentations


Ads by Google