Download presentation
Presentation is loading. Please wait.
Published byDarlene Dean Modified 6年之前
1
A B C D E F 5-2 七段數字顯示控制實習 Input 0H 1H 2H 3H 4H 5H 6H 7H 8H 9H 0AH 0BH
The relation between the input and output of the seven-segment display: Input 0H 1H 2H 3H 4H 5H 6H 7H 8H 9H 0AH 0BH 0CH 0DH 0EH 0FH Output A B C D E F
2
自我練習 Section 5-2-1 5-2-1-1 修改程式令CPU從00、02、04一直計數到98後即停住再在98,計數間隔為0.5秒。
Demo Demo Section 5-2-1 修改程式令CPU從00、02、04一直計數到98後即停住再在98,計數間隔為0.5秒。 設計能從00計數到59的秒鐘計時。 5-2-2 在七段數字顯示器上,顯示98、96、94 、直到00後停下來,計數間隔為0.5秒。 在七段數字顯示器上,顯示您的座號並不斷閃爍。 5-2-3 修改程式使從00計數到59,再從59計數到00後停住。計數間隔為1秒。 5-2-4 修改程式一樣利用查表的方式,在DS3、DS4上從99顯示到00,並不斷重覆。每次變化間隔為0.25秒。 Demo
3
5-2-1 二位數字上數計數 8051 P2 SW2.3 Manual operation: 1. Turn On SW2_3.
Data flow: P2.7~P2.4 DS3 P2.3~P2.0 DS4
4
5-2-1 二位數字上數計數
5
Program I5_2_1.asm 二、程式: comment .SYMBOLS ON ORG 0000H JMP MAIN
MOV A,#00H NEXT: MOV P2,A CALL DELAY ADD A,#1 DA A JMP NEXT ;============================== ; DELAY 0.5S DELAY: MOV R5,#5 DL2: MOV R6,#200 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 DJNZ R5,DL2 RET END
7
Instruction: DA 8051 Instruction Set: DA Description:
* DA adjusts the contents of the Accumulator to correspond to a BCD (Binary Coded Decimal) number after two BCD numbers have been added by the ADD or ADDC instruction. If the carry bit is set or if the value of bits 0-3 exceed 9, 0x06 is added to the accumulator. If the carry bit was set when the instruction began, or if 0x06 was added to the accumulator in the first step, 0x60 is added to the accumulator. * The Carry bit (C) is set if the resulting value is greater than 0x99, otherwise it is cleared. Operation: DA Function: Decimal Adjust Accumulator Syntax: DA A Instructions OpCode Bytes Flags DA 0xD4 1 C Copied from
8
Please check the sequence in ICE
Instruction: DA ; Repeatedly increasing Acc by one following a DA instruction: INCREASE: ADD A,#1 ; Binary addition instruction DA A ; Decimal adjustment. From binary to BCD JMP INCREASE Result of ADD (Content of Acc.) Result of DA Please check the sequence in ICE 00H H 01H H 02H H …… 09H H 0AH 0AH + 06H = 10H (BCD of 10) 11H 12H ... 19H 1AH 1AH + 06H = 20H (BCD of 10) 21H … 98H H 99H H 9AH 9AH + 06H = 100H (overflow)
9
5_2_1 ADD A,#n ; Binary addition instruction
DA A ; Decimal adjustment. From binary to BCD Acc value after addition C bit Adjustment by “DA A” Acc value after adjustment 8BH 8BH + 06H = 91H 91H B8H B8H + 60H = 18H 18H 1
10
DA instruction A > 99H? C 1 N LSN > 9? N AC = 1? N
(A) (A) + 06H MSN > 9 N (A) (A) + 06H
11
DA instruction C = 1 C 1 N LSN > 9? (A) (A) + 06H N C = 1? N
MSN > 9 N (A) (A) + 06H
12
5-2-2 二位數字下數計數
13
Program I5_2_2.asm 二、程式: comment .SYMBOLS ON ORG 0000H JMP MAIN
MOV A,#99H NEXT: MOV P2,A CALL DELAY ADD A,#99H ; 減一 DA A JMP NEXT ;============================== ; DELAY 0.5S DELAY: MOV R5,#5 DL2: MOV R6,#200 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 DJNZ R5,DL2 RET END 、
14
5-2-2 (cont.) Adding #99H is equivalent to subtracting by #01H
Three ways to subtract 1 from Acc: ADD A,#99H SUBB A,#1 DEC A ADD A,#99H ; A + 99 – 100 = A – 1 DA A 5 + 99 104 1 + 99 100 2 + 99 101 Q1: Why not using “SUBB” or DEC instruction instead of ADD? A1: Because the DA instruction only work with the ADD instruction.
15
ADDition & SUBtraction Instructions
comment ADD A,#data ; A A + #data ADDC A,#data ; A A + #data + C SUB A, #data ; No such an instruction !!! SUBB A,#data ; A A - #data –C. The “B” in “SUBB” represents “Borrow” 53 48H 21 57H 31 F1H Step 1: Use SUBB. Initially, C = 0 (i.e., B = 0) 48H – 57H – 0 = F1, C = 1 (i.e., B = 1) Step 2: Use SUBB. At this moment, C = 1. 53H – 21H – 1 = 31H, C = 0 (i.e., B = 0)
17
5-2-3 二位數字上、下數計數
18
Program I5_2_3.asm 二、程式: comment .SYMBOLS ON ORG 0000H JMP MAIN
START: CALL UPCOUNT CALL DOWNCOUNT JMP START ;============================= ; INCREASEMENT UPCOUNT: MOV A,#00H NEXTU: MOV P2,A CALL DELAY ADD A,#1 DA A CJNE A,#00,NEXTU RET ;============================== ; DECREASEMENT DOWNCOUNT: MOV A,#99H NEXTD: MOV P2,A CALL DELAY ADD A,#99H DA A CJNE A,#99H,NEXTD RET ; DELAY 0.5S DELAY: MOV R5,#5 DL2: MOV R6,#200 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 DJNZ R5,DL2 END
20
5-2-4 利用查表法的二位數計數
21
Program I5_2_4.asm 二、程式: comment .SYMBOLS ON ORG 0000H JMP MAIN
START: MOV R1,#0 ; R1 is for the ones digit MOV R2,#0 ; R2 is for the tens digit MOV DPTR,#TABLE LOOP2: MOV A,R2 MOVC SWAP A MOV R3,A LOOP1: MOV A,R1 ADD A,R3 MOV P2,A CALL DELAY INC R1 CJNE R1,#10,LOOP1 MOV R1,#0 INC R2 CJNE R2,#10,LOOP2 JMP START comment . ;============================== ; DELAY 0.1S DELAY: MOV R6,#200 DL1: MOV R7,#249 DJNZ R7,$ DJNZ R6,DL1 RET TABLE: DB 00H,01H,02H,03H DB 04H,05H,06H,07H DB 08H,09H END
Similar presentations