Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

howdy all heres some PIC code...

Status
Not open for further replies.

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
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.
 
echostar IR remote control protocol

I was also trying to use my dish remote control for other uses, and could never understand the output. I am an avr and 8051 guy, I don't know pic.

I built a device similar to the one in avr410 spec.
The device reads the IR codes and prints them to the PC's hyperterminal. Works fine with my XM radio remote control, and others.

I don't think it was working properly with the echostar remote because most of the bytes were the same, i.e cmd byte the same as data bytes.

SO i gave up a long time ago. If you have any ideas on how I can get this to work, let me know.

Maybe a parts list for the above code? The hex file?

Thanks
 
Last edited:
johnsmith123 said:
I was also trying to use my dish remote control for other uses, and could never understand the output. I am an avr and 8051 guy, I don't know pic.

I built a device similar to the one in avr410 spec.
The device reads the IR codes and prints them to the PC's hyperterminal. Works fine with my XM radio remote control, and others.

I don't think it was working properly with the echostar remote because most of the bytes were the same, i.e cmd byte the same as data bytes.

SO i gave up a long time ago. If you have any ideas on how I can get this to work, let me know.

Maybe a parts list for the above code? The hex file?

Thanks
good to hear from you !
I finally got the damn thing to work just today.
the remote I`m using is the silver one that came with a dvr 510
which is a universal remote capable of outputing rc5,sony,jvc and god knows what else. this screwed me up for a long while untill i set the aux code to 566, which is a phillips rc5 code
the hardware consists of an if demod chip pulled from an old sat receiver and a pic 16f87 with leds on its i/o port as binary indicators of the received rcs code. the ir signal is a 14 bit manchester encoded packet.
rc5 packet consists of 2 start bits- always one-one
toggle bit- alternates with each remote button press
5 address bits
6 command bits
the algo is really quite simple;
1. wait for input pin to go low- the signal starts at the SECOND half of the first bit
2. measure the half bit period
3. delay a full bit period- youre now at the beginning of the third bit
4. shift the bit value into storage
5. loop to delay full and store a total of 12 times
the code is in asm but should woprk in a high level lang such as mikrobasic but doesnt. not sure if there was an error or the basic takes too long to run. wouldnt think it takes too long tho, the half bit period is abt 944us the ck=8mhz and the timer has a prescale of 16. thats about 4k of instruction time to count to 128 or so. gotta be a bug. it obviously should work on a 8051 if rewritten.
heres the asm which works, folowed by the basic which doesnt
lemme know what you think

Code:
program rc5
' pic 16F87
dim dly_half_period as byte absolute 127
dim tmp as byte absolute 126
dim n as byte absolute 124
dim test as byte absolute 119
dim addr,data as byte
main:
osccon=%01110010
while iofs=1
wend
cmcon=7
trisa=(32+4)
trisb=0
portb=255
porta=3
t2con.t2ckps1=1
t2con.t2ckps0=0
t2con.toutps0=0
t2con.toutps1=0
t1con.toutps2=0
dly_half_period=0
tmp=0
n=12
addr=0
data=0
test=0
asm
bcf status,rp0
bcf status,rp1
bcf t2con,tmr2on
clrf tmr2
clrf main_global_tmp
bsf status,rp0
movlw 255
movwf pr2
bcf status,rp0
movlw 6
movwf main_global_n
movlw 0
movwf main_global_addr
movwf main_global_data

ck_pin:
btfsc porta,2
goto ck_pin
bsf t2con,tmr2on
bsf t2con,t2ckps1

wait_for_transition:
btfss porta,2
goto wait_for_transition
bcf t2con,tmr2on            ' timer is right
movf tmr2,w
sublw 255
movwf main_global_dly_half_period

get_addr:
call delay_half
call delay_half

movf porta,w
andlw 4
movwf main_global_tmp
bcf status,c
rrf main_global_tmp,f
rrf main_global_tmp,f
movf main_global_tmp,w
iorwf main_global_addr,f
bcf status,c
rlf main_global_addr,f
decfsz main_global_n,f
goto get_addr

bcf status,c
rrf main_global_addr,f
movlw 6
movwf main_global_n

get_data:
call delay_half
call delay_half

movf porta,w
andlw 4
movwf main_global_tmp
bcf status,c
rrf main_global_tmp,f
rrf main_global_tmp,f
movf main_global_tmp,w
iorwf main_global_data,f
bcf status,c
rlf main_global_data,f
decfsz main_global_n,f
goto get_data
bcf status,c
rrf main_global_data,f
end asm


'goto main



portb=addr
delay_ms(3000)
portb=data
delay_ms(3000)
goto main

asm
delay_half:
bcf t2con,tmr2on
movf main_global_dly_half_period,w
movwf tmr2
bcf pir1,tmr2if
bsf t2con,tmr2on
bsf t2con,t2ckps1
delay_half_bit_period:
btfss pir1,tmr2if
goto delay_half_bit_period
return
end asm
end.

Code:
program rc5
' pic 16F87

dim dly_half_period,tmp,addr,data,addr_cnt,data_cnt,n as byte
main:
osccon=%01110010
while iofs=1
wend
cmcon=7
trisa=(32+4)
trisb=0
portb=255
porta=3
t2con.t2ckps1=1
t2con.t2ckps0=0
t2con.toutps0=0
t2con.toutps1=0
t1con.toutps2=0
addr=0
data=0
while porta.2 = 1
wend
t2con.tmr2on=1
t2con.t2ckps1=1

while porta.2=0
wend
t2con.tmr2on=0
dly_half_period=255-tmp

for addr_cnt=1 to 6
    for n=1 to 2
        t2con.tmr2on=0
        tmr2=dly_half_period
        pir1.tmr2if=0
        t2con.tmr2on=1
        t2con.t2ckps1=1
        while pir1.tmr2if=0
        wend
    next n
tmp=porta and 4
status.c=0
tmp=tmp>>2
addr=addr or tmp
status.c=0
addr=addr<<1
next addr_cnt
status.c=0
addr=addr>>1
for data_cnt=1 to 6
    for n=1 to 2
        t2con.tmr2on=0
        tmr2=dly_half_period
        pir1.tmr2if=0
        t2con.tmr2on=1
        t2con.t2ckps1=1
        while pir1.tmr2if=0
        wend
    next n
tmp=porta and 4
status.c=0
tmp=tmp>>2
data=data or tmp
status.c=0
data=data<<1
next data_cnt
status.c=0
data=data>>1

portb=addr
delay_ms(2000)
portb=data
delay_ms(2000)
goto main
end.
 
RC5 remote control code

I am also using the silver remote, but mine is for a 501 model(same thing).

so what you've done is used an auxiliary remote function that is RC5.
I have done the same thing with an avr, however I did not try the 566 code, I'll give it a shot.
I cannot assemble your code and I do not have a PIC 16f87, so I will have to figure it out in order to see what the problem is with my avr source.

If I get it to work, I will post the source here, someone else may find use for it.
 
Last edited:
Johnsmith, you can download the mikrobasic compiler for the PIC (trial version), it allows 2K of binary..

But you would have to order a PIC. mouser.com and use Post office to ship. It is not a lot of money.
 
I can understand why you dont want to change platforms in midstream alrite.
One problemI had was setting the pic clock and timer prescale to the correct value tmatch the pulse period. If youre off the timer can overflo and start over from zero therby screwing you up considerably. A little math in the beginning would have saved much grief. The first pulse starts in the second half too. Gotta know that else youre gonna be reading the wrong periods thruout the packet. GL
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top