# small problem with tmr1 16f87

Status
Not open for further replies.

#### 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
Code:
program rc5
' pic 16F87

dim hbp as byte 'absolute 127
dim dly_full as byte

main:
hbp=0
dly_full=0
tmp=0
byte_cnt=2
shift_data_bit=7
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
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_data

movf porta,w
andlw 7
movwf main_global_tmp
bcf status,c
rrf main_global_tmp,f
movf main_global_tmp,w
bcf status,c
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
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
delay_ms(3000)
portb.0=1
portb.1=0
porta=data
delay_ms(3000)
goto display
end.            ' start tmr1

#### Papabravo

##### Well-Known Member
I guess it must be related to the fact that you have two labels with the same name. The first one is the one in the symbol table and the second one got thrown on the floor. So the timer keeps being reinitialized and it never sets the flag.

Throw that rotton compiler or interpreter away for not telling you about the duplicate label. That's really a crock!

#### zkt_PiratesDen

##### New Member
Thanks Papa ! Not sure whos the worst really: the programmer for looking right at it and not seeing the obvious, or the "rotten compiler" for not pointing it out in the first place. The compilers not too bad really, does a pretty good job in basic, but stretches a bit thin in asm. Been wondering about the programmer for some time now.

#### mramos1

##### Active Member
Looking at your code posts, I was wondering what compiler it was? And PapaB is right, delay_full should have been flagged by it.

For the amount of ASM in your posts, why are you not just using MPLABs free ASM to start with?

Last edited:

#### zkt_PiratesDen

##### New Member
Its a Mikrobasic compiler. Im using it because the remainder of the pogram Im working on will be in basic. Mikrobasic has some built-in ic2 routines that will be handy later on. Only the packet recieve part needs to be in asm . And tuth of the matteri s , it probably doesnt need to be. But Im having so much fun with the asm Im gonna write the packet rec part in asm anyway. And, I dont have a lot of experience in asm, so the practice is good too. The limitations of the compiler make it just that more interesting. On top of that, the red gun driver transistor is burned out in this monitor and I dont want to take the time to fix it. Which makes it even more interesting because labels in the the compiler window are normally in red and stand out."That which doesnt kill you makes you stronger", or so they say.
Maybe you have an idea on this:
a 12 bit packet is input on portb.7. the first 6 bits are address bits and the next are data bits
all I need to do now is send the first 6 bits to byte A and he second to byte B
I undrstand how to shift the bits in
In basic to seperate them intio 2 bytes would be:
for bit= 1 to 12
if bit <6 then do address thing
else do data thing
next bit
or similar. sure you get the idea
but nothing comes to mind an asm especially with the f87 meager instruction set.
however the days still young and Im still working on the first cup of cofee.

zkt
the second cup did the trick
this is why God invented flags

Last edited:

#### mramos1

##### Active Member
I pulled Mikrobasic, have not looked at it yet. Looks good based on the free version, it allows a large byte .hex file (in demo) so I will look at it. And I think they had cross platform on chips (very nice). If I recall. I think I pulled an AVR and PIC version if the same one. Pulled it a week or so ago, and one
day I hope to have time to look at it..

If you are into PICS, PROTON is the answer, but they limit the chips you can use in the free version (and I did not have those handy) and 50 lines of code so you can not realize they have are the future high level compiler for the PICs (IMHO)..

I have spent my budge for now (wife kids, etc) and just found my Atmel programmer is broke. So a programmer is next for me.

I normally use RVKBASIC on the AVRs for most items (not now, programmer is POOF). But last project was MPLABs/ASM 12f509 and it is really nice. And there are routines all over for it. But I see why now, the built in libraries are nice.

On the portb.7 thing in BASIC, you will have to "for next" it and if less than 7 (not 6 since the for next started at 1 and want the first 6 bits). Pretty much like you have. In ASM, you do it the same way, just more typing.. In ASM, set up the loop and a counter, and flip a bit to to flag another memory location.

You are tring to read it in and then write it to the ports right? So you have to save them in RAM (ASM) or variables (BASIC) then write them out.

#### zkt_PiratesDen

##### New Member
Thats a bummer about the programmer alrite. Hope you can fix it. Not sure I follow you on the Proton; 50 lines of code and a sparce pic inventory seems to shoot it in the head. Mkbas has a shipload of librarys, 2k of code, and a worthless forum for free. also availale in pascal and c and avrs. Theres talk about adding some gps stuff in the next release. I shouldnt be so hard on the forum. Theres some very knmowlegegable people there and a lot of good free code.It aint too lively and very serious.
Im about to wrap this part of the project up.
latr,
zkt

#### mramos1

##### Active Member
zkt_PiratesDen said:
Thats a bummer about the programmer alrite. Hope you can fix it.
Fixed it last night. So not looking at ICD2 again. I see Mike has a small one and Bill has a little larger one. Either way I have to order a chip.
Not sure I follow you on the Proton; 50 lines of code and a sparce pic inventory seems to shoot it in the head. Mkbas has a shipload of librarys, 2k of code, and a worthless forum for free. also availale in pascal and c and avrs. Theres talk about adding some gps stuff in the next release. I shouldnt be so hard on the forum. Theres some very knmowlegegable people there and a lot of good free code.It aint too lively and very serious.
I did load the MKbasic PIC, if it does 509 I will use on my next project. Pulled the PIC, AVR and PICDsp version, 2K is a lot of code. If no 12f509, back to MPLABs again.

Thanks for the info. Looks like that will be my pick for now. I bought MELabs and Mbasic, not happy with them. One is bloat the other is crippled until you come up with another \$150 to get IF ELSE ENDIF. hehehe.. If I didn't want IF ELSE ENDIF I would use ASM.

Status
Not open for further replies.