Return VS Goto?


Closed Thread
Results 1 to 7 of 7

Thread: Return VS Goto?

  1. #1
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187

    Default Return VS Goto?

    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?

    Code:
    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
    Code:
    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

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Never MInd
    Last edited by mackrackit; - 10th January 2008 at 20:45. Reason: MIs read
    Dave
    Always wear safety glasses while programming.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    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?

  4. #4
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187


    Did you find this post helpful? Yes | No

    Default

    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?
    Last edited by Fredrick; - 10th January 2008 at 20:58.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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/fil...update_2_6.zip
    Last edited by mister_e; - 10th January 2008 at 21:56.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187


    Did you find this post helpful? Yes | No

    Talking

    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.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    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.

Similar Threads

  1. Making a menu
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 12th November 2008, 20:54
  2. Replies: 14
    Last Post: - 26th September 2007, 06:41
  3. Comm example: Pic to Pic
    By Chadhammer in forum Code Examples
    Replies: 4
    Last Post: - 15th November 2006, 00:26
  4. Can I do this???
    By noobie in forum mel PIC BASIC
    Replies: 2
    Last Post: - 10th June 2006, 19:57
  5. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 21:10

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts