PDA

View Full Version : Translation Problem



cyh_fax
- 21st April 2007, 08:41
I translated the following PicBasic Code to ProBasic Pro. Could any one please check whether my translation is 100% correct since it does compile without an error but the actual circuit doesn't work. [The circuit does work with the code compiled from PicBasic].

--------------------------------------------------------------------------
'PicBasic
symbol porta = 5
symbol trisa = 133
symbol portb = 6
symbol trisb = 134
poke trisa, 255
poke trisb, 240
start:
peek portb, b0
if bit4 = 0 then trigger
goto start
trigger:
pause 500
peek portb, b0
if bit5 = 1 then send
goto start
send:
peek porta, b0
if bit4 = 1 then eleven
poke portb, b0
goto start
eleven:
if bit0 = 0 then ten
poke portb, 11
goto start
ten:
poke portb, 10
goto start
end
--------------------------------------------------------------------------

--------------------------------------------------------------------------
'PicBasic Pro
trisa = 255
trisb = 240
p var byte
start:
p = portb
if p.4 = 0 then trigger
goto start
trigger:
pause 500
p = portb
if p.5 = 1 then send
goto start
send:
p = porta
if p.4 = 1 then eleven
portb = p
goto start
eleven:
if p.0 = 0 then ten
portb = 11
goto start
ten:
portb = 10
goto start
end
--------------------------------------------------------------------------

paul borgmeier
- 21st April 2007, 09:04
they sure look the same to me - are you using the same PIC?

cyh_fax
- 21st April 2007, 09:14
they sure look the same to me - are you using the same PIC?
Yes, but I am not using any "Official Programmer". I made a very simple one from http://pic16f84.hit.bg [and I am using PIC16F84A from Microchip] Does that matter?

Also, I just realised that I could have

"p var byte" or "p var bit"

but then the "p var bit" compiled with many errors. Why? Which one should I use. Even after reading the manual, I still don't really know. Please help.

Archangel
- 22nd April 2007, 07:59
I translated the following PicBasic Code to ProBasic Pro. Could any one please check whether my translation is 100% correct since it does compile without an error but the actual circuit doesn't work. [The circuit does work with the code compiled from PicBasic].

--------------------------------------------------------------------------
'PicBasic
symbol porta = 5
symbol trisa = 133
symbol portb = 6
symbol trisb = 134
poke trisa, 255
poke trisb, 240
start:
peek portb, b0
if bit4 = 0 then trigger
goto start
trigger:
pause 500
peek portb, b0
if bit5 = 1 then send
goto start
send:
peek porta, b0
if bit4 = 1 then eleven
poke portb, b0
goto start
eleven:
if bit0 = 0 then ten
poke portb, 11
goto start
ten:
poke portb, 10
goto start
end
--------------------------------------------------------------------------

--------------------------------------------------------------------------
'PicBasic Pro
trisa = 255
trisb = 240
p var byte
start:
p = portb
if p.4 = 0 then trigger
goto start
trigger:
pause 500
p = portb
if p.5 = 1 then send
goto start
send:
p = porta
if p.4 = 1 then eleven
portb = p
goto start
eleven:
if p.0 = 0 then ten
portb = 11
goto start
ten:
portb = 10
goto start
end
--------------------------------------------------------------------------

You might try:


trisa = 255
trisb = 240
p var byte

start:
p = portb
if p.4 = 0 then goto trigger
goto start

trigger:
pause 500
p = portb
if p.5 = 1 then goto send
goto start

send:
p = porta
if p.4 = 1 then goto eleven
portb = p
goto start

eleven:
if p.0 = 0 then goto ten
portb = 11
goto start

ten:
portb = 10
goto start
end

I know some will object to goto's as sloppy, but if it works . .

jessey
- 23rd April 2007, 01:52
I know some will object to goto's as sloppy, but if it works . .

Why not set a variable bit, say A to equal 0 then use "IF A = 0 THEN Start", then don't use the bit variable for nothing else. Thats what I do instead of using GOTO's and the IF - THEN's only uses 2 words. Good approach I think, if your not really tight for code space.

jessey

paul borgmeier
- 23rd April 2007, 06:08
Also, I just realised that I could have

"p var byte" or "p var bit"

but then the "p var bit" compiled with many errors. Why? Which one should I use. Even after reading the manual, I still don't really know. Please help.

You want p var byte
(B0 was a byte in your PBC version)

if p where a bit, it could be "1" or "0"
if p is a byte, it can be "%00000000" -"%11111111" ;(0-255)

since you have stuff like "if p.4 = 0 then"
you are asking if the 5th bit from the right is 0 (bit counting starts at 0). Since a bit only has one place and a byte has 8, you want a byte,

Hi Joe,

Thanks for chiming it - however, it is not clear to me what your version fixes or why one would want to add a goto when the IF command already "gotos"? Are you suggesting this to make it more readable?

Archangel
- 23rd April 2007, 08:15
Hi Joe,

Thanks for chiming it - however, it is not clear to me what your version fixes or why one would want to add a goto when the IF command already "gotos"? Are you suggesting this to make it more readable?
Hi Paul,
Er, ah yes . . .
the code looks convoluted with the label following THEN without a goto or gosub, I am sure it only looks that way to me. But as skimask might point out to me on page 80 of the little green book, at the top it really is ok. My Bad :( must sleep more and respond less . . .

paul borgmeier
- 23rd April 2007, 08:48
My Bad :( must sleep more and respond less . . .

Actaully, I recommend you do the opposite - that is what I do and it seems to work (for me).

skimask
- 23rd April 2007, 14:11
But as skimask might point out to me on page 80 of the little green book, at the top it really is ok.

I might....but I won't....'cause I know from experience that you're all over that.... :)


A shorter version:

trisa = 255 : trisb = 240 : p var byte
start:
if portb.4 = 0 then goto trigger
goto start

trigger:
pause 500 : if portb.5 then goto send
goto start

send:
if porta.4 = 1 then goto eleven
portb = porta : goto start

eleven:
if porta.0 = 0 then goto ten
portb = 11 : goto start

ten:
portb = 10 : goto start
end


But I wonder if the original poster didn't mean to use this:

trisa = $FF : trisb = $F0 : p var byte
start:
if portb.4 = %0 then goto trigger
goto start

trigger:
pause 500 : if portb.5 = %1 then goto send
goto start

send:
if porta.4 = %1 then goto eleven
portb = porta : goto start

eleven:
if porta.0 = %0 then goto ten
portb = %11 : goto start

ten:
portb = %10 : goto start
end
Notice the 'special' characters added...