zkt_PiratesDen
New Member
does anyone see anyhing right off hand that causes the delay_full subroutine to not return. . disregard the comments. theyre all out of order. gotta be something stupid
thanks
zkt
thanks
zkt
Code:
program rc5
' pic 16F87
dim hbp as byte 'absolute 127
dim dly_full as byte
dim tmp,byte_cnt,shift_addr_bit,shift_data_bit,addr,data as byte
main:
hbp=0
dly_full=0
tmp=0
byte_cnt=2
shift_addr_bit=7
shift_data_bit=7
addr=0
data=0
cmcon=7
portb=0
t1con.tmr1cs=0 ' set tmr1 to increment with Fosc does not defalt to 0
asm
start:
bsf status,rp0
bcf status,rp1
movlw 82
movwf osccon
movlw 128
movwf trisb
movlw 32
movwf trisa
movlw 7
movwf cmcon
bcf status,rp0
bcf intcon,tmr1on
bcf t1con,tmr1cs
clrf tmr1h
clrf tmr1l
bcf t1con,tmr1on
bsf t1con,T1CKPS1
bsf t1con,T1CKPS0
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 of
movf tmr1l,w
movwf main_global_hbp
movwf main_global_tmp
bcf status,c
rlf main_global_tmp,w
sublw 255
movwf main_global_dly_full
movf main_global_hbp,w
movwf main_global_tmp
bsf status,c
rrf main_global_tmp,w ' calc three qtr dly
addwf main_global_tmp,f
sublw 255
movwf main_global_tmp
movwf tmr1l ' load tmr1 with three qtr dly
bcf pir1,tmr1if ' clr tmr1 interrupt flag
bsf t1con,tmr1on
' start tmr1
delay_three_qtr: ' delay until mid of first half bit period
btfss pir1,tmr1if ' delay done yet ?
goto delay_three_qtr
get_bit:
call delay_full
clrf porta
cnt_two_bytes:
decfsz byte_cnt,f
goto get_store_addr
goto get_store_data
get_store_addr:
movf porta,w
andlw 7
movwf main_global_tmp
shift_addr_to_lsb:
bcf status,c
rrf main_global_tmp,f
decfsz shift_addr_bit,f
goto shift_addr_to_lsb
movf main_global_tmp,w
iorwf addr,f
bcf status,c
rlf main_global_addr,f
goto get_bit
get_store_data:
movf porta,w
andlw 7
movwf main_global_tmp
shift_data_to_lsb:
bcf status,c
rrf main_global_tmp,f
decfsz shift_data_bit,f
goto shift_data_to_lsb
movf main_global_tmp,w
iorwf addr,f
bcf status,c
rlf main_global_data,f
goto done
delay_full:
bcf t1con,tmr1on
movf main_global_dly_full,w
movwf tmr1l ' load tmr1 with full dly
bcf pir1,tmr1if ' clr tmr1 interrupt flag
bsf t1con,tmr1on
delay_full:
btfss pir1,tmr1if
goto delay_full
return
done:
end asm
display:
portb.1=1
portb.0=0
porta=addr
delay_ms(3000)
portb.0=1
portb.1=0
porta=data
delay_ms(3000)
goto display
end. ' start tmr1