Pic16f88 JAL programming

Discussion in 'Embedded Systems and Microcontrollers' started by FFtravism, Apr 21, 2009.

  1. FFtravism

    Thread Starter Active Member

    Aug 21, 2008
    I am very new to PIC programming as a first off. I have a circuit I am working on with a PIC16F88 and I been programming it with JALv2. The circuit basically flashes a bunch of LED's. I have a program of flashes that run. I want to be able to hook up a SPTT switch. Switch it to the left side and it will run a set of code. Switch it to the right and it will run a separate set of code. Is this possible? I included my code it's missing the procedures as they are long but the main code and calls are in there.
    Thank you for any help

    Notes: I want the led flash coding to run until the switch is moved to the left or right pole.
    Last edited: Apr 21, 2009
  2. RiJoRI

    Well-Known Member

    Aug 15, 2007
    Yes, it is possible.
    First, I haven't look at you code, but I'm just working with general ideas.
    I would first hook up the switch (left & right) to two inputs of the uC.

    Then my pseudo-code would look like:
    ; Read and debounce switch input pins
    ; IF Left_Pin == 1
    ; Goto Left_Code
    ; IF Right_Pin == 1
    ; Goto Right_Code
    ; Goto Flash_LEDs
    ; Goto Loop ; not really needed, but Just In Case...

    All subroutines (Left_Code, Right_Code, and Flash_LEDs) would end with a Goto Loop.

    (For all those fainting at the sight of Gotos, Goto is a valid opcode in PIC assembler.)

    If the Flash_LEDs routine makes the response to the switch changing too slow, I would split it with a state counter before trying an interrupt.

  3. FFtravism

    Thread Starter Active Member

    Aug 21, 2008
    How do I continuously poll the pin while it is flashing the leds?
  4. FFtravism

    Thread Starter Active Member

    Aug 21, 2008
    I was looking for something more instant.. hrmm.. The application is a LED light bar for an emergancy vehicle. the led's will be flashing constant and I want to have a switch to make it change patterns in to a arrow stick where it flashes each section from left to right or right to left depending on the switch.

  5. atferrari

    AAC Fanatic!

    Jan 6, 2004
    If the switch you use has only two unique positions it goes to ONE pin only. Actions on that switch will materialize in "0" or "1" on a pin set as input during the initialization.

    Independently of how you blink your LEDs, whether controlling them within a continuous loop or by hardware running independent of the main loop, the testing of the switch would take few machine cycles. Even if forming part of that loop it will be not noticeable to the user.

    It seems that you are not actually aware of how much time takes a loop and how much could take the polling of that switch. When you realize that, you would be able to answer your question yourself.

    Buena suerte.
    Last edited: May 1, 2009