Menu

can't get out of sub

Help
2010-08-25
2013-05-30
  • Nobody/Anonymous

    here what i have, but when i send it a C to start sub colors it works, but i cannot get it to exit the sub when i send it a O?
    #chip 16F688, 18 'mhz
    #config MCLRE=off, WDT=off, bod=off

    #define USART_BLOCKING
    #define SerInPort PORTc.5
    #define USART_BAUD_RATE 2400 'the speed you want
    InitUsart
    On Interrupt UsartRX1Ready call getdata 'info
    main:
    goto main

    sub getdata
    hserreceive temp
    if temp = 67 then colors
    if temp= 79 then goto main
    end sub

    sub colors
    LoopCounter = 0
    For LoopCounter = 1 to 255
    pvalue = loopcounter/2
    pv1 = 128 - pvalue
    pv2 = 128 - pv1
    repeat 4
       pwmout 1, pv1, 1
    pwmout 2, 0, 1
    pwmout 3, pvalue, 1
    end repeat
    goto colors
    end sub

     
  • Mauried

    Mauried - 2010-08-26

    The problem is here.
    sub getdata
    hserreceive temp
    if temp = 67 then colors    <========= problems.
    if temp= 79 then goto main  <======= problems
    end sub

    When you enter a sub routine , you must exit the subroutine either by the end sub , or by exit sub statements.
    Having gotos in the Sub which leave the sub mean that the stack will slowly fill up with return addresses which never get removed.

    You can have gotos in the Sub provided they dont go outside of the Sub.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.