Switch in PIC BASIC HELP!!!!


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hello again,
    I'm sorry but I missed the fact that you wasn't using PBP. In that case it get's a little more complicated, the Select Case (which I don't think PBC supports) can be substitutes with some If Then lines. But the reading and writing of the various register will have to be done with PEEK and POKE and you need to use the datasheet for your particular PIC to figure out which physical adresses the various registers are at.

    /Henrik.

  2. #2
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Switch in PIC BASIC HELP!!!!

    Thanks, a lot Henrik,
    but when I try compile your program,I have syntax error!
    I am new in programing,can you write me some new code,
    about PEEK OR POKE,how you write me last time,
    because I do no,t now how I do that!
    Thanks a lot again!!!

  3. #3
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    One question more!
    What you mean line
    OPTION.5=1
    AND
    OPTION.4=0

    WHAT I MUST WRITE IN THIS 2 LINES?
    Because I have syntax error.
    Last edited by dragan77; - 13th May 2010 at 13:27.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hello,
    OPTION.5 = 1 simply sets bit 5 in the option register but like I said in my previous post PBC doesn't support direct register access like that so you'll have to use POKE to write the registers and PEEK to read them. Look at the memory map of the device you're working with. You'll find at which adresses the various registers are. On the 16F628 the OPTION register is at location 80h for example.

    Look in the PBC manual on how to use POKE and PEEK.

    Why did I want to set bit5 in the option register? That's because it is the bit that select if TMR0 is a timer or counter and I found that information in the section of datasheet dedicated to TMR0.

    /Henrik.

  5. #5
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Hello,
    I don.t understood how I do that.
    I use device PIC16f628,

    I just need when I PUSH BUTTON ONE TIME,
    then working program 1,
    when I push button next time,
    go to next program 2,
    when I push button next time,
    go to next program 3,......

    Can you write me code in PIC BASIC code for that,
    if you cant,
    thanks anyway!!!

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


    Did you find this post helpful? Yes | No

    Default

    I have not used Pic Basic so I can not help much but here is a "not very good idea" you might play with while you are working out the register reading Henrik is pointing you to.


    Setup a BUT_CHECK routine with a RETURN at the end of it.
    In each of the program loops have a GOSUB BUT_CHECK.
    The BUT_CHECK routine will check if the button IS pressed and if it is increment a variable by one.
    When the code returns to the program running the next line will have something like.
    IF BUT_VAR = 2 GOTO PROG 2

    Lots of problems with doing it this way but if things are not critical....
    When you figure out the registers with Pic Basic you should see how bad of an idea this is.
    Dave
    Always wear safety glasses while programming.

  7. #7


    Did you find this post helpful? Yes | No

    Default Program selection on button press

    Try this idea, it works with PBP in a PIC18F4620 and should work with any PIC that has EEPROM.

    I set a byte variable "ProgramState" to 1 in a data statement and write this to EEPROM when the program is loaded into the PIC.

    At power up, the code reads the value stored in ProgramState, here set to 1, and jumps to the appropriate code block.

    MAIN:
    READ 0, ProgramState
    If ProgramState = 1 then RunCode1
    If ProgramState = 2 then RunCode2
    If ProgramState = 3 then RunCode3

    If ProgramState > 3 then
    write 0, 1 'reset ProgramState to first code block
    goto MAIN
    endif

    RunCode1:
    execute codeblock 1
    if ButtonDown = 1 then
    write 0, 2
    endif
    goto MAIN

    RunCode2:
    execute codeblock 2
    if ButtonDown = 1 then
    write 0, 3
    endif
    goto MAIN

    etc

    HTH
    BrianT
    Last edited by BrianT; - 14th May 2010 at 01:45. Reason: pushed TAB by mistake

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