單片機可預置可逆4位計數(shù)器
4.程序設計內容
(1.兩個獨立式按鍵識別的處理過程;
(2.預置初值讀取的問題
(3.LED輸出指示
5. 程序框圖
圖4.12.2
6. 匯編源程序
COUNT EQU 30H
ORG 00H
START: MOV A,P3
ANL A,#0FH
MOV COUNT,A
MOV P1,A
SK2: JB P3.6,SK1
LCALL DELY10MS
JB P3.6,SK1
INC COUNT
MOV A,COUNT
CJNE A,#16,NEXT
MOV A,P3
ANL A,#0FH
MOV COUNT,A
NEXT: MOV P1,A
WAIT: JNB P3.6,WAIT
LJMP SK2
SK1: JB P3.7,SK2
LCALL DELY10MS
JB P3.7,SK2
DEC COUNT
MOV A,COUNT
CJNE A,#0FFH,NEX
MOV A,P3
ANL A,#0FH
MOV COUNT,A
NEX: MOV P1,A
WAIT2: JNB P3.7,WAIT2
LJMP SK2
DELY10MS: MOV R6,#20
MOV R7,#248
D1: DJNZ R7,$
DJNZ R6,D1
RET
END
評論