PIC16F690 I/O problem

Discussion in 'Embedded Systems and Microcontrollers' started by troto, Sep 19, 2009.

  1. troto

    Thread Starter New Member

    Sep 19, 2009
    Hi all,

    I made a small project in order to learn about PICs.
    On a a board i have two 7+1 segments displays that are controlled by the PIC.
    At the beginning it should display "0" on both displays.
    When I press a button it should increment display number 1 and when i press another button should increment the other display.

    When the counter reaches 10 it resets back to zero.

    My code is attached.

    At this point it shows the same number on both displays, but this is ok for now.
    What id doesn't do is when i press the button to change the number.
    And a bigger problem is that when the program starts it increments the numbers.

    the circuit board is ok, because at one point this code worked and after i changed some things in it (i don't remember what i changed) it stopped working.
    Also when i run this program on the PIC Kit 2 programmer i get the same effect. The LEDs on it start light up and they should not change state.

    Any help solving this problem would be appreciated.

  2. mik3

    Senior Member

    Feb 4, 2008
    Can you post only a text file with the code?
  3. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    The first thing I notice is that you do not have edge detection or debounce on the switch inputs, so the count will increment every pass through the main loop as long as the switch is pressed.

    The PIC has a far faster response than a mechanical switch, it will sometimes see multiple switch closes and opens for one press as the contact settles to the closed position, and possibly again some false changes as it is released.

    Typically you should look for it to be in the same state for around 10mS before taking any further action, to ensure you are seeing a genuine press, and likewise when it's released.

    I'd try running the code through MPLab's built-in simulator, if you enable Register view you can step through the program and see exactly what is happening for each instruction.

    Do you have pull-down resistors on the switch input pins to guarantee a clean logic level when the switches are not pressed?
  4. troto

    Thread Starter New Member

    Sep 19, 2009
    I figured this out today. it seems that i didn't got any email with your responses.
    Rjenkins you are right. My problem was that I didn't hooked the inputs with a resistor.

    I don't use debounce as this is the desired effect. as long as the button is pressed it will increment.
    Also i finished the code and now everything works perfectly.
    I might have another small problem with the code, but i will let you know tomorrow.

    thanks for your answer.