Menu

Help with some BASIC Code

Help
2011-12-05
2013-05-30
  • Nobody/Anonymous

    This is driving me Nuts, I don't seem to be able to get the outputs to advance properly. Can some kind person please show me the error of ways before I  blow a gasket!

    What seems to happen is the 'portstep' instruction steps from 0 to 1 and Port 1 goes high, but next time round it ignores thr portstep = portstep + 1  

    ;Chip Settings
    #chip 12F508,4
    #config MCLRE=OFF, CP=OFF, WDT=OFF, OSC=INTRC

    ;Defines (Constants)
    #define RX_Input GPIO.3
    #define Port_1 GPIO.0
    #define Port_2 GPIO.1
    #define Port_3 GPIO.2
    #define Port_4 GPIO.4
    #define LED GPIO.5

    'An RC Switch Program for 10F202 Pos Working
    dir GPIO b'001000'

    'make GPIO.3 a digital input
    goto Initialise

    Main:

    'This Do-Loop should be about 16 instrucions, or 16 us
    '1 instr BTFSS, 12 instr wait 12 us (or use 12 nop's), 1 instr incf, 2 instr goto
    Do While Rx_Input On
    wait 12 us
    Count = Count + 1
    Loop
    If count > 10 then
    newcount = count
    end if
    count = 0
    If newcount > 80 Then
    Set LED On
    Goto Port_Out
    End If
    goto Main

    Port_Out:
    portstep = portstep + 1
    wait 1 s
    Set LED Off
    newcount = 0

    If portstep = 1 Then
    Set Port_1 On
    End if
    Goto Main

    If portstep = 2 Then
    Set Port_1 Off
    End if
    portstep = 0
    Goto Main

    Initialise:
    count = 0
    portstep = 0
    Set Port_1 Off
    Set Port_2 Off
    Set Port_3 Off
    Set Port_4 Off
    Goto Main:

     
  • kent_twt4

    kent_twt4 - 2011-12-06

    Never gets to If portstep = 2 Then…. because it goes back to Main beforehand,  Put the "goto Main" inside the If portstep = 1 Then……..

     
  • Keith

    Keith - 2011-12-06

    Thanks again Kent,   it works just fine now!

    (what a Muppet am I )

     
  • lhatch

    lhatch - 2011-12-08

    I think if you line up your "end if" with your "if" statements you would have caught the mistake.  And it reads a lot better.

    If portstep = 1 Then
       Set Port_1 On
    End if
    Goto Main                               <-- stands out you never reach code after this goto with  no label or fall through

    If portstep = 2 Then
       Set Port_1 Off
    End if
    portstep = 0
    Goto Main

     

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.