Counter in PIC 16f877a

Discussion in 'Embedded Systems and Microcontrollers' started by QMD, Mar 10, 2011.

  1. QMD

    Thread Starter Member

    Jun 30, 2010
    I am trying to implement a counter using a PIC16F877A

    I have a proximity sensor which will only output high when an object is within a certain range (I have set this range in the pic based on the output voltage of the rangefinder)

    I have a variable (double) x, which I set to increment every time the conditions are met. After I reach 5, I then wish for an LED to turn on. I tried this, but the LED is always on...and sometimes flickers.....any idea what the issue is?

  2. someonesdad

    Senior Member

    Jul 7, 2009
    You need to show your hardware connections (i.e., a schematic) and your software. Not doing so is kinda like saying "My car won't run -- what's wrong with it". :p

    By "(double)", do you mean you're programming in C? If so, why are you using a double for something that is inherently an integer?
  3. John P

    AAC Fanatic!

    Oct 14, 2008
    You're not going to tell us that "double" means a 2-byte quantity, are you? Please don't.
  4. QMD

    Thread Starter Member

    Jun 30, 2010
    Sorry for the lack of clarity...
    I am programming the PIC using C...but I figured out my problem...I needed to put a delay after each count. Since I am oscillating at 20mHz, it counts many times for each time a human perceives a count