simple counting program - please help!!


Closed Thread
Results 1 to 4 of 4
  1. #1
    john meiers's Avatar
    john meiers Guest

    Default simple counting program - please help!!

    I'm new at this (obviously) - I need a program segment that will simply count button presses on a portA pin and flash an LED on portB when the count gets to 10, then reset the count and repeat. I've tried a bunch of things, but my LED always lights up after about 5-6 presses. Whats goin on here??

  2. #2
    john meiers's Avatar
    john meiers Guest


    Did you find this post helpful? Yes | No

    Default

    One more thing - I don't think this is a switch bounce issue. If I simply hold down the pushbutton for a good second my LED will come on. I think the PIC is counting the amount of time the switch is closed, rather than the transisitons from low to high.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The problem I have is I don't have PBC only PBP (which is also a reason I don't answer PBC problems too often!), so you might want to step through the code and ensure I've not slipped any 'PBP only' features or ways of doing things into my example...

    Lets assume the Button is on PortB.7 connected between PIC pin and Vss, with a pull-up Resistor (anywhere between 4K7 and 47K) connected between the PIC pin and Vdd).

    The LED is on PortB.0 connected between the PIC pin and Vss with a Resistor in series (any value between 220R and 330R).

    Code:
    	Symbol CounterA=B0		' Using B0 as our Button Press Counter
    
    	Input 7				' Button on this Pin
    	Output 0			' LED on this Pin
    	
    Start:
    	Low 0				' LED is OFF
    	CounterA=0			' Zero Counter
    MainLoop:
    	If Pin7=1 then MainLoop		' Do nothing when Button not pressed
    	CounterA=CounterA+1		' Button pressed so increment Counter
    	Pause 75			' Allow 75mS for Debounce
    WaitLoop:
    	If Pin7=0 then WaitLoop		' Kill time untill User releases Button
    	If CounterA<10 then MainLoop	' Count next Button Press
    	High 0				' Ten-Count reached, so turn on LED
    	Pause 2000			' Wait a couple of Seconds
    	Goto Start			' Reset for another run...
    I don't know what PIC you're using, whether it needs Comparators or ADC's disabled, but since you say you already have a partially working example I'm sure you can translate the Input to PortA. Just a reminder... please keep things on the forum.

  4. #4
    john meiers's Avatar
    john meiers Guest


    Did you find this post helpful? Yes | No

    Default

    Thank you so much! It works beautifully!

Similar Threads

  1. Simple Blink program doesnt work.
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 1st March 2009, 20:30
  2. Help with simple program
    By mykewl in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 31st July 2008, 08:58
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Simple Interrupt Program
    By eoasap in forum General
    Replies: 5
    Last Post: - 28th October 2005, 16:22
  5. simple program, what am i missing
    By scorpion in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th September 2005, 18:45

Members who have read this thread : 1

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