; ===================================
; == 喇叭與MINIKEY應用控制 ==
; == 2014/12/29 ==
; == 蘇偉諺 4A037052 ==
; ===================================
;以MINIKEY的4個按鍵來控制喇叭,按S1、S2、S3、S4分別讓喇叭發出1kHz、2kHz、4kHz、8kHz聲響。
;-----------------------------------------------------------------------------
; 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
SPK EQU P1.7 ;CONTROL BIT OF SPEAKER
;-----------------------------------------------------------------------------
; MAIN PROGRAM
;-----------------------------------------------------------------------------
ORG 00H
MOV SP,#5FH
AGAIN: CALL MINIKEY
JNB MINIKEYFLAG,AGAIN
MOV A,MINIKEYNO
CJNE A,#0,NOTOUCHS1
MOV B,#8
NOTOUCHS1: CJNE A,#1,NOTOUCHS2
MOV B,#4
NOTOUCHS2: CJNE A,#2,NOTOUCHS3
MOV B,#2
NOTOUCHS3: CJNE A,#3,MUSIC;;;;;
MOV B,#1
MUSIC: MOV TMOD,#00010001B
MOV R3,#255
LPMUSIC2: MOV R2,B
LPMUSIC1: MOV TH1,#HIGH(65536-63)
MOV TL1,#LOW(65536-63)
SETB TR1
WAIT1: JNB TF1,WAIT1
CLR TF1
CLR TR1
DJNZ R2,LPMUSIC1
CPL SPK
DJNZ R3,LPMUSIC2
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: ;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
END
沒有留言:
張貼留言
文章有誤或有問題麻煩您留言告知! 謝謝您~~