Switch in PIC BASIC HELP!!!!


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dragan77 View Post
    Is it finish code for compile...
    Almost!

    Set the PORTx.x you are going to use for your button and program your routines and you're done.
    Roger

  2. #2
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Thanks,but when I use this code:

    ButtonPressCounter = 0

    SWITCH-LOOP:
    IF PORTA.2 = 0 THEN
    IF ButtonPressCounter = 3 THEN ButtonPressCounter = 0
    ButtonPressCounter = ButtonPressCounter + 1
    IF ButtonPressCounter = 1 THEN GOSUB Program1
    IF ButtonPressCounter = 2 THEN GOSUB Program2
    IF ButtonPressCounter = 3 THEN GOSUB Program3
    ENDIF
    GOTO SWITCH-LOOP:

    Program1:
    high portb.1
    RETURN

    Program2:
    high portb.2
    RETURN

    Program3:
    high portb.3
    RETURN

    WHEN I TRY COMPILE IN PIC BASIC,THEN GIVE ME THIS ERRORS!

    ERROR Line 1: Syntax error.
    ERROR Line 3: Syntax error.
    ERROR Line 4: IF without a matching ENDIF.
    ERROR Line 5: Bad expression.
    ERROR Line 5: Bad expression or missing THEN.
    ERROR Line 5: IF without a matching ENDIF.
    ERROR Line 6: Syntax error.
    ERROR Line 7: Bad expression.
    ERROR Line 7: Bad expression or missing THEN.
    ERROR Line 7: IF without a matching ENDIF.
    ERROR Line 8: Bad expression.
    ERROR Line 8: Bad expression or missing THEN.
    ERROR Line 8: IF without a matching ENDIF.
    ERROR Line 9: Bad expression.
    ERROR Line 9: Bad expression or missing THEN.
    ERROR Line 11: Syntax error.


    I DO NOT NOW WHY,WHAT IS HAPPENED?

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


    Did you find this post helpful? Yes | No

    Default

    Is that the whole code?

    Is the line
    Code:
    ButtonPressCounter VAR BYTE
    in there someplace?
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Thanks,for help,but can you give me one more answer!

    I write this code:

    ButtonPressCounter var byte

    SWITCHLOOP:
    IF PORTA.2 = 0 THEN
    IF ButtonPressCounter = 3 THEN ButtonPressCounter = 0
    ButtonPressCounter = ButtonPressCounter + 1
    IF ButtonPressCounter = 1 THEN GOSUB Program1
    IF ButtonPressCounter = 2 THEN GOSUB Program2
    IF ButtonPressCounter = 3 THEN GOSUB Program3
    ENDIF
    GOTO SWITCHLOOP:

    Program1:
    high portb.1
    PAUSE 500
    LOW PORTB.1
    PAUSE 500

    RETURN

    Program2:
    high portb.2
    PAUSE 500
    LOW PORTB.2
    PAUSE 500
    RETURN

    Program3:
    high portb.3
    PAUSE 500
    LOW PORTB.3
    PAUSE 500
    RETURN

    is Ok,code working,
    but how I do it,when I switch button,to change program,and stay work in this some of this program?

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


    Did you find this post helpful? Yes | No

    Default

    but how I do it,when I switch button,to change program,and stay work in this some of this program?
    Sorry, but I do not understand the question.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    I try ex plane,my question!
    I mean!

    I need when I press button one time,
    then in my case go to program1,
    and still working in program1!

    When I press button second time then
    go to program2,
    and still working in program2,

    When I press button 3.rd time then
    go to program3,
    and still working in program3,......

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


    Did you find this post helpful? Yes | No

    Default

    Maybe...
    Code:
    SWITCHLOOP:
    IF PORTA.2 = 0 THEN ButtonPressCounter = ButtonPressCounter + 1
    IF ButtonPressCounter = 1 THEN GOSUB Program1
    IF ButtonPressCounter = 2 THEN GOSUB Program2
    IF ButtonPressCounter = 3 THEN GOSUB Program3
    IF ButtonPressCounter = 4 THEN ButtonPressCounter = 0
    ENDIF
    GOTO SWITCHLOOP:
    maybe not... See what happens.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

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