PDA

View Full Version : Return VS Goto?



Fredrick
- 10th January 2008, 19:36
Today i buyed PICBASIC Pro and made the first test program whit a PIC16F872

But when i use the code below the pic stops or hangs sometimes the (LEDīs stop flashing) when i press the button (PORTB.0) but whit code number 2 it works fine..

Why?



ADCON1 = 7
i var word

loop:

High PORTA.0
High PORTA.1

for i = 1 to 30
Pause 10
IF PORTB.0 = 1 then GOSUB but
next i

Low PORTA.0
Low PORTA.1

for i = 1 to 30
Pause 10
IF PORTB.0 = 1 then GOSUB but
next i
Goto loop

but:
high PORTA.2
pause 1000
low PORTA.2
RETURN




Code numer 2


ADCON1 = 7
i var word


loop:

High PORTA.0
High PORTA.1

for i = 1 to 30
Pause 10
IF PORTB.0 = 1 then but
next i

Low PORTA.0
Low PORTA.1

for i = 1 to 30
Pause 10
IF PORTB.0 = 1 then but
next i
Goto loop



but:
high PORTA.2
pause 1000
low PORTA.2
goto loop

mackrackit
- 10th January 2008, 19:43
Never MInd

skimask
- 10th January 2008, 19:44
Both code chunks are essentially identical (with the obvious RETURN vs GOTO exception), and both should function equally well (aside from the obvious program flow differences).

Do you have a pullup/pulldown resistor on PortB.0?

What's connected to MCLR?

Fredrick
- 10th January 2008, 19:50
The PIC is on a Velleman K8048 Programmer and Experiment board.
http://www.velleman.be/ot/en/product/view/?id=350903

Yes i have a pull up resistor..

If the code is identical why does it hangs with the first code?

mister_e
- 10th January 2008, 20:48
weird, it works here, none hangs. Maybe it has something to do with the on-board programmer.

Make sure it program & update the configuration fuses.

The minimum you need is XT_OSC and LVP_OFF and make sure you crystal jumpers are correctly set.

which software are you using to program your pic with the Velleman kit? (WinpicProg, ic-prog or else?)

did you tried their update?
http://www.velleman.be/downloads/files/downloads/k8048_update_2_6.zip

Fredrick
- 10th January 2008, 20:57
I use Velleman Progpic2 with the update installed..
I just reprogrammed the PIC with the "RETURN" code and now it works.. weird???

Maybe there is something wrong with my programmer?

Anyway it workīs now..

Thanx for a great forum. :D

skimask
- 11th January 2008, 00:13
The PIC is on a Velleman K8048 Programmer and Experiment board.
http://www.velleman.be/ot/en/product/view/?id=350903

Yes i have a pull up resistor..

If the code is identical why does it hangs with the first code?

Pull up resistor on MCLR?

What about PortB.0?
If you've got nothing on it, it might be floating and confusing your program somehow.

As far as the identical goes, what I meant was 'functionally identical', I didn't mean identical as in 'the same' or 'equal'.

And I don't know why.
If it works with the 2nd code, go with it.