?? upd6121.asm
字號:
;=======================================================
;
; FILENAME : NEC_uPD6121.asm
; AUTHOR : Ben Hsu
; M.P. : +886-952-778-122
; DATE : 2008/05/30
; DESCRIPTION :
; Read the NEC uPD6121 by TMR0 interrput
; and INTE interrupt
; The signal is input by INTE pin
;
;=======================================================
list p=pic16f677, r=dec
#include <p16f677.inc>
cblock 0x20
w_temp
status_temp
pclath_temp
fsr_temp
SystemFg
RxBuf : 4
TmrBase
TmrCycle
GetIndex
KeyRepeat
endc
BANK0 MACRO
bcf STATUS, RP0
bcf STATUS, RP1
ENDM
BANK1 MACRO
bsf STATUS, RP0
bcf STATUS, RP1
ENDM
BANK2 MACRO
bcf STATUS, RP0
bsf STATUS, RP1
ENDM
BANK3 MACRO
bsf STATUS, RP0
bsf STATUS, RP1
ENDM
#define FgGetDataOK SystemFg, 0
#define CF STATUS, C
#define ZF STATUS, Z
;=======================================================
; Starting point of the procedure
;
org 0x0000
nop
goto Initialize
;=======================================================
; Interrupt vector address
;
org 0x0004
Interrupt
movwf w_temp
swapf STATUS, w
clrf STATUS
movwf status_temp
movf FSR, w
movwf fsr_temp
movf PCLATH, w
movwf pclath_temp
clrf PCLATH
; Into the TMR0 interrupt vector
; Interrput cycle is 128us
T0Vect
btfss INTCON, T0IF
goto T0VectEnd
movlw 0x80
movwf TMR0
bcf INTCON, T0IF
incf TmrBase, f
T0VectEnd
; Into the pin intrrupt vector
InteVect
btfss INTCON, INTF
goto InteVectEnd
bcf INTCON, INTF
movf TmrBase, w
movwf TmrCycle
clrf TmrBase
GetStart
movf GetIndex, f
btfss ZF
goto GetLeader
incf GetIndex, f
goto InteVectEnd
; Get leader code
GetLeader
decf GetIndex, w
btfss ZF
goto GetData
movlw .30
subwf TmrCycle, w
btfss CF
goto GoElse
; If pluse width to be equal or smaller than 11.5ms,
; The signal is repeat key
movlw .92
subwf TmrCycle, w
btfss CF
goto IsRepeat
clrf KeyRepeat
incf GetIndex, f
goto InteVectEnd
; Get data code
GetData
movlw .35
subwf GetIndex, w
btfsc CF
goto GoElse
movlw .13
subwf TmrCycle, w
rrf RxBuf+3, f
rrf RxBuf+2, f
rrf RxBuf+1, f
rrf RxBuf, f
incf GetIndex, f
movlw .34
xorwf GetIndex, w
btfss ZF
goto InteVectEnd
bsf FgGetDataOK
goto GoElse
IsRepeat
incf KeyRepeat, f
GoElse
clrf GetIndex
InteVectEnd
InterruptVectEnd
movf pclath_temp, w
movwf PCLATH
movf fsr_temp, w
movwf FSR
swapf status_temp, w
movwf STATUS
swapf w_temp, f
swapf w_temp, w
retfie
;=======================================================
; FUNCTION NAME : Initialize
; DESCRIPTION :
; 1. Set up the initialize register of system
; and the initialize value of parameters
;
;
Initialize
BANK1
; TMR0 Prescale Rate 1:1
; Interrupt on falling edge of INTE pin
; *** Signal normal in high level , set falling edge
; *** Signal normal in low level , set rising edge
movlw 0x88
movwf OPTION_REG
; The RA2 is INTE pin
; To set the RB7 pin is output mode for LED use
movlw 0xff
movwf TRISA
movlw 0x7f
movwf TRISB
movlw 0xff
movwf TRISC
BANK2
clrf ANSEL
clrf ANSELH
BANK0
clrf GetIndex
clrf KeyRepeat
bsf PORTB, 7
; To set the interrupt enable bit
bsf INTCON, T0IE
bsf INTCON, INTE
bsf INTCON, GIE
; to continue main loop
;=======================================================
;
; Main loop
; The RxBuf and RxBuf+1 is custom code
; The RxBuf+2 and RxBuf+3 is data code
;
Start
btfss FgGetDataOK
goto Start
bcf FgGetDataOK
movlw 0x04
xorwf RxBuf, w
btfss ZF
goto Start
movlw 0xb9
xorwf RxBuf+1, w
btfss ZF
goto Start
movlw 0x01
xorwf RxBuf+2, w
btfss ZF
goto Start
btfss PORTB, 7
goto SetRB7
bcf PORTB, 7
goto Start
SetRB7
bsf PORTB, 7
goto Start
;=======================================================
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -