?? dialphon.asm
字號:
list p=16f627
Title "DialPhon.asm"
include <p16f627.inc>
cblock 0x20
W_TEMP,STATUS_TEMP
CALLCNTR,CALLSTATE,CMDCNTR,CMDSTATE,TONECNTR,TONESTATE
DLYCNTH,DLYCNTL,TIMECNTR,TONECYC
endc
#define dlycmd 0x5 ; delay 5ms
#define dlytone 0x14 ; delay 20ms
#define dlybtn 0x32 ; delay 50ms
; Reset vector
org 00h
goto start
; interrupt vector
org 04h
goto interrupt
; Program start
org 05h
interrupt
movwf W_TEMP ;Save W to W_TEMP
swapf STATUS,W
clrf STATUS
movwf STATUS_TEMP
btfss INTCON,T0IF
goto endofint
bcf INTCON,T0IF
incf TIMECNTR,F
movlw 0x51 ; 50ms interrupt 0x51
movwf TMR0
endofint
clrf STATUS
swapf STATUS_TEMP,W
movwf STATUS
swapf W_TEMP,F
swapf W_TEMP,W
retfie
start
; bank1 select
bsf STATUS,RP0
bcf STATUS,RP1
movlw b'00000111' ; TMR0 internal clock prescale=256
movwf OPTION_REG
movlw b'11111111' ; PORTA All bits input
movwf TRISA
movlw b'00000000' ; PORTB All bits output
movwf TRISB
; bank0 select
bcf STATUS,RP0
bcf STATUS,RP1
movlw b'10100000' ; Global,TMR0 interrupt enable
movwf INTCON
movlw 0x51 ; 50ms interrupt 0x51
movwf TMR0
clrf PORTA
clrf TIMECNTR
clrf CMDCNTR
clrf CALLCNTR
clrf TONECNTR
clrf TONECYC
bsf CMDSTATE,0 ; First Command State->'H'
bsf CALLSTATE,0 ; First Call Button State->'H'
bsf TONESTATE,0 ; First StopSound(Tone)input State->'H'
movlw b'10000001' ; Alarm -> off,Hook -> down
movwf PORTB
; bcf PORTB,3 ; 16f74 test
DisConnect
movlw b'10000001' ; Alarm -> off,Hook -> down
movwf PORTB
; bcf PORTB,3 ; 16f74 test
btfss PORTA,0 ; Receive Command ?
goto rcvcmdproc
bsf CMDSTATE,0 ; Current Command State->'H'
btfss PORTA,2 ; Call Button Push Down ?
goto callbtnproc1
bsf CALLSTATE,0 ; Current Call Button State->'H'
goto DisConnect
callbtnproc1
movlw dlybtn
movwf DLYCNTH
call delay
; Call Button Push Down State Reconfirm
btfsc PORTA,2
goto DisConnect ; Call Button Push Down
btfss CALLSTATE,0 ; Previous Call Button State 'H'? Confirm
goto DisConnect
bcf CALLSTATE,0 ; Current Call Button State->'L'
incf CALLCNTR,F
movf CALLCNTR,W
bsf STATUS,C
sublw 0x0 ; n>=1 ?
btfsc STATUS,C
goto DisConnect
clrf CALLCNTR
clrf CMDCNTR
goto Connect
rcvcmdproc
movlw dlycmd
movwf DLYCNTH
call delay
; Receive Command State Reconfirm
btfsc PORTA,0
goto DisConnect
btfss CMDSTATE,0 ; Previous Command State 'H'? Confirm
goto DisConnect
bcf CMDSTATE,0 ; Current Command State->'L'
incf CMDCNTR,F
movf CMDCNTR,W
bsf STATUS,C
sublw 0x78 ; n>120 ?
btfsc STATUS,C
goto DisConnect
clrf CALLCNTR
clrf CMDCNTR
goto Connect
nop
Connect
movlw b'11100001' ; Alarm -> on,Hook -> up
movwf PORTB
; bsf PORTB,3 ; 16f74 test
btfss PORTA,2 ; Call Button Push Down
goto callbtnproc2
bsf CALLSTATE,0 ; Current Call Button State->'H'
btfss PORTA,1 ; Stop Sound(Tone) input
goto toneproc
bsf TONESTATE,0 ; Current StopSound(Tone) input State->'H'
goto Connect
callbtnproc2
movlw dlybtn
movwf DLYCNTH
call delay
; Call Button Push Down State Reconfirm
btfsc PORTA,2
goto Connect
btfss CALLSTATE,0 ; Previous Call Button State 'H'? Confirm
goto Connect
bcf CALLSTATE,0 ; Current Call Button State->'L'
incf CALLCNTR,F
movf CALLCNTR,W
bsf STATUS,C
sublw 0x0 ; n>=1 ?
btfsc STATUS,C
goto Connect
clrf CALLCNTR
clrf TONECNTR
goto DisConnect
toneproc
movlw dlytone
movwf DLYCNTH
call delay
; Stop Sound input State Reconfirm
btfsc PORTA,1
goto Connect
btfss TONESTATE,0 ; Previous StopSound(Tone) input State->'H' Confirm
goto Connect
bcf TONESTATE,0 ; Current StopSound(Tone) input State->'L'
movf TIMECNTR,W ; Tone signal period detection
movwf TONECYC
clrf TIMECNTR
bsf STATUS,C
sublw 0x0b ; period > 600ms ?
btfsc STATUS,C
goto noiseproc
;;;;;;;;;;;;;;;;;;;;
; btfss PORTB,2 ; 16f74 test
; goto lp0003 ; 16f74 test
; bcf PORTB,2 ; 16f74 test
; goto lp0004 ; 16f74 test
;lp0003 ; 16f74 test
; bsf PORTB,2 ; 16f74 test
;lp0004 ; 16f74 test
;;;;;;;;;;;;;;;;;;;;
movf TONECYC,W
bcf STATUS,C
sublw 0x0f ; period < 800ms ?
btfss STATUS,C
goto noiseproc
incf TONECNTR,F
movf TONECNTR,W
bsf STATUS,C
sublw 0x5 ; n>5 ?
btfsc STATUS,C
goto Connect
clrf TONECNTR
clrf CALLCNTR
goto DisConnect
noiseproc
clrf TONECNTR
goto Connect
delay ; 1ms delay loop(1 introduction cycle =1.117475us)
nop
movlw 0xb3
movwf DLYCNTL
lp
nop
nop
decfsz DLYCNTL,F
goto lp
decfsz DLYCNTH,F
goto delay
return
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -