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

    Another way to do it

    Code:
    ButtonPressCounter = 0
    
    SWITCH-LOOP:
    IF PORTx.x = 0 THEN     'this is where your button is connected to, obviously
       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:
    ...do something
    RETURN
    
    Program2:
    ...do something
    RETURN
    
    Program3:
    ...do something
    RETURN
    Roger

  2. #2
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Thanks,Roger
    but can i ask you some!
    Is it finish code for compile,or some of combination,to I use!

    Can you write finish code for compile, because I am new in programing!

  3. #3
    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

  4. #4
    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?

  5. #5
    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.

  6. #6
    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?

  7. #7
    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.

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