zkt_PiratesDen
New Member
Looks like a good place so share ideas etc.
Ive been investigating the dish network ir/uhf remote. In the process I wrote this code which stores a data packet in ram and displays the timing data on porta and then on portb.2 . Porta sequentially displays the bit number and the half bit periods as 2 bytes ( high byte-low byte) and then pulses portb.2 with the timing data for display on a scope. Kinda turns an ordinary scope into a digital storage scope Max number of half bit periods stored is 32 but could be more by using more ram banks ( uses only bank 0). Code runs on a pic16f87-88. might run on others without modification. Not too well commented but if will explain operation if anyones interested. Lastly, utilizes tmr1, rbif, and indirect addressing. Anyone working with ir remotes give me a pm. asm follows . compiled on mikrobasic compiler
zkt
Ive been investigating the dish network ir/uhf remote. In the process I wrote this code which stores a data packet in ram and displays the timing data on porta and then on portb.2 . Porta sequentially displays the bit number and the half bit periods as 2 bytes ( high byte-low byte) and then pulses portb.2 with the timing data for display on a scope. Kinda turns an ordinary scope into a digital storage scope Max number of half bit periods stored is 32 but could be more by using more ram banks ( uses only bank 0). Code runs on a pic16f87-88. might run on others without modification. Not too well commented but if will explain operation if anyones interested. Lastly, utilizes tmr1, rbif, and indirect addressing. Anyone working with ir remotes give me a pm. asm follows . compiled on mikrobasic compiler
zkt
Code:
program TMR1
' Stores 32 ir remote packet half bit periods in ram bank 0 and displays them on porta
' rbif detects bit transitions and tmr1 measures half bit periods
' indirect addressing to store data
' requires ir demodulator connected to portb.7
' pic 16F87
dim n as byte absolute 127
main:
asm
bsf status,rp0
bcf status,rp1
movlw 98
movwf osccon
movlw 128
movwf trisb
movlw 32
movwf trisa
movlw 7
movwf cmcon
bcf status,rp0
bcf intcon,tmr1on
bcf t1con,tmr1cs
movlw 225
clrf tmr1h
clrf tmr1l
bsf t1con,tmr1on
bcf t1con,T1CKPS1
bcf t1con,T1CKPS1
movlw 31
movwf fsr
movlw 255
movwf porta
ck_pin: ' wait for packet
btfss intcon,rbif
goto ck_pin
movf portb,w
bcf intcon,rbif ' clr portb change flag
bsf t1con,tmr1on ' start tmr1
wait_for_transition: ' wait for half bit period to end
btfss intcon,rbif
goto wait_for_transition
bcf t1con,tmr1on 'end of half bit period turn tmr1 off
incf fsr,f
btfsc fsr,6 ' stored 32 bit periods yet ?
goto done
movf tmr1h,w
movwf indf
incf fsr,f
btfsc fsr,6 ' stored 32 bit periods yet ?
goto done
movf tmr1l,w
movwf indf ' store tmr1l in next memory space
clrf tmr1h ' since the previous half bit period has ended the
clrf tmr1l ' next has started so reset tmr1 and
bsf t1con,tmr1on
movf portb,w
bcf intcon,rbif ' reset portb change flag
goto wait_for_transition ' loop to wait_for_port_change:
done:
bcf intcon,rbif
end asm
delay_ms(700) ' if more than 1 packet sent wait for it to end
'goto scope_display
port_display:
porta=0
portb=0
fsr=32
for n=1 to 2
porta=n
portb=3
delay_ms(4000)
porta=0
portb=0
delay_ms(100)
porta=indf
portb=2
delay_ms(4000)
porta=0
portb=0
delay_ms(100)
inc (fsr)
porta=indf
portb=1
delay_ms(4000)
porta=0
portb=0
delay_ms(100)
inc(fsr)
next n
'goto port_display ' uncomment to repeat port display
scope_display:
portb.2=1
asm
movlw 3
movwf porta
start:
movlw 31
movwf fsr
movlw 20 ' 20 seems to be bout right
movwf main_global_n
repeat:
decfsz main_global_n,f
goto $+2
goto start
bcf t1con,tmr1on
bcf pir1,tmr1if
incf fsr,f
movf indf,w
sublw 255
movwf tmr1h
incf fsr,f
movf indf,w
sublw 242
movwf tmr1l
bcf portb,2
bsf t1con,tmr1on
on_time:
btfss pir1,tmr1if
goto on_time
bcf t1con,tmr1on
bcf pir1,tmr1if
incf fsr,f
movf indf,w
sublw 255
movwf tmr1h
incf fsr,f
movf indf,w
sublw 239
movwf tmr1l
bsf portb,2
bsf t1con,tmr1on
off_time:
btfss pir1,tmr1if
goto off_time
goto repeat
end asm
end.