红外线发射与接收一例
STATUS equ 0X03
PORTA equ 0x05
PORTB equ 0x06
W equ 0x00
F equ 0x01
Z equ 0x02
C equ 0x00
;------------------
n55ks equ 0x0C ;
nchks equ 0x0D ;
avgIR equ 0x0E ;
nsamp equ 0x0F ;
tdetect equ 0x10 ;
;-----------------------
org 0x000
goto start
org 0x004
start
movlw b'00000001'
tris PORTA ; RA0 红外输入
movlw b'00000000'
tris PORTB ;RB0 红外输出
; 2us in goto at end of loop
blip call doblip ; +6.248ms = 6.250ms total
call seeblip ; 6.250ms total
call seeblip ; 6.250ms total
call seeblip ; 6.250ms total
call seeblip ; 6.250ms total
call seeblip ; 6.250ms total
call seeblip ; 6.250ms total
call seeblip ; 6.250ms total
nop
nop
call doblip
call seeblip
call seeblip
call seeblip
call seeblip
call seeblip
call seeblip
call seeblip
goto blip ;
;============ 产生 55.5kHz 锯形波 (346*18us=6.228ms)======
doblip
movlw 0xFF
movwf n55ks
osc nop
call make55k ;RB0 红外输出
decfsz n55ks,F
goto osc
;--------------
morblip ;6253us DELAY
movlw 0x5B
movwf n55ks
oscmore call make55k ;RB0 红外输出
nop
decfsz n55ks,F
goto oscmore
;-------------
call delay8u
nop
nop
nop
nop
nop
bcf PORTB,2 ; RB2 LED 指示
return
;---------------------------
make55k bsf PORTB,0 ;RB0 红外输出
call delay8u
bcf PORTB,0
return
delay8u nop
nop
nop
nop
return
;========= 6.250ms ===================
seeblip
clrf avgIR
movlw 0xF9
movwf nchks
chk call chkIR ;//
decfsz nchks,F
goto chk
movf avgIR,W ;
sublw 0X78
btfss STATUS,C
goto detectd
bcf PORTB,0 ;RB0 红外输出 OFF
goto chkdone
detectd bsf PORTB,0
nop
chkdone
call delay8u
nop
nop
nop
nop
return
;========================
chkIR
clrf nsamp
btfss PORTA,0
incf nsamp,F
btfss PORTA,0 ; RA0 红外输入
incf nsamp,F
btfss PORTA,0 ; RA0 红外输入计数值存到 nsamp
incf nsamp,F
btfss PORTA,0
incf nsamp,F
btfss PORTA,0
incf nsamp,F
btfss PORTA,0 ; 共六次 nsamp 》 5 , avgIR 增一
incf nsamp,F
nop
movf nsamp,W
sublw 0X04
btfss STATUS,C
incf avgIR,F
return
;============================
end
|