;------------------------------------------
; ===================================
; == 七段與MINIKEY應用控制 ==
; == 2014/12/29 ==
; == 蘇偉諺 4A037052 ==
; ===================================
;------------------------------------------
; 以MINIKEY的4個按鍵來控制七段顯示器的動作,按S1、S2、S3、S4分別顯示“┌” 、 “┐” 、“└” 、“┘”。;-----------------------------------------------------------------------------
; PARAMETER DEFINE
;-----------------------------------------------------------------------------
MINIOUT0 EQU P3.2 ;OUTBIT0 OF MINIKEY
MINIOUT1 EQU P3.3 ;OUTBIT1 OF MINIKEY
MINIIN0 EQU P3.4 ;INBIT0 OF MINIKEY
MINIIN1 EQU P3.5 ;INBIT1 OF MINIKEY
MINIKEYNO DATA 35H ;NUMBER OF PRESSED MINIKEY
MINIKEYFLAG EQU 20H.1 ;FLAG OF PRESSED MINIKEY
SEGLED EQU P1 ;DATA BUS OF 7SEGMENT & LED
;-----------------------------------------------------------------------------
; MAIN PROGRAM
;-----------------------------------------------------------------------------
ORG 00H
MOV SP,#5FH
CLOSE: MOV SEGLED,#01111111B
AGAIN: CALL MINIKEY
JNB MINIKEYFLAG,CLOSE
MOV A,MINIKEYNO
CJNE A,#0,NOTOUCHS1
MOV SEGLED,#01011110B
JMP AGAIN
NOTOUCHS1: CJNE A,#1,NOTOUCHS2
MOV SEGLED,#01111100B
JMP AGAIN
NOTOUCHS2: CJNE A,#2,NOTOUCHS3
MOV SEGLED,#01100111B
JMP AGAIN
NOTOUCHS3: CJNE A,#3,AGAIN;;;;;
MOV SEGLED,#01110011B
JMP AGAIN
;-----------------------------------------------------------------------------
; SCAN MINIKEY
;-----------------------------------------------------------------------------
MINIKEY: CLR MINIOUT0
MOV R7,#20 ;DELAY 1ms
CALL DELAY
;----------------------
JB MINIIN0,MIKY0
MOV MINIKEYNO,#0
SETB MINIKEYFLAG
JMP MIKYRET
;----------------------
MIKY0: JB MINIIN1,MIKY1
MOV MINIKEYNO,#1
SETB MINIKEYFLAG
JMP MIKYRET
;----------------------
MIKY1: SETB MINIOUT0
CLR MINIOUT1
MOV R7,#20 ;DELAY 1ms
CALL DELAY
;----------------------
JB MINIIN0,MIKY2
MOV MINIKEYNO,#2
SETB MINIKEYFLAG
JMP MIKYRET
;----------------------
MIKY2: JB MINIIN1,MIKY3
MOV MINIKEYNO,#3
SETB MINIKEYFLAG
JMP MIKYRET
;----------------------
MIKY3: CLR MINIKEYFLAG
MIKYRET: SETB MINIOUT0
SETB MINIOUT1
RET
;-------------------------------------------------------------------------------
; DELAY TIME=R7*0.05mS
;-------------------------------------------------------------------------------
DELAY: MOV TMOD,#00010001B ;Timer 0 : MODE 1
LOOPDY: MOV TH0,#HIGH(65536-50) ;
MOV TL0,#LOW(65536-50) ;
SETB TR0 ;
WAIT: JNB TF0,WAIT ;
CLR TF0 ;
CLR TR0 ;
DJNZ R7,LOOPDY ;
RET
;-------------------------------------------------------------------------------
; DELAY TIME=R7*50mS
;-------------------------------------------------------------------------------
DELAY50ms:
DLOOP1: MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000)
SETB TR0
JNB TF0,$
CLR TR0
CLR TF0
DJNZ R7,DLOOP1
RET
END
沒有留言:
張貼留言
文章有誤或有問題麻煩您留言告知! 謝謝您~~