i'm relatively new to programing using picbasic. i want to program a 16f84 to count to 0 to 255 in binary with a pushbutton to advance count one step for each press of the button.
help greatly appreciated.
i'm relatively new to programing using picbasic. i want to program a 16f84 to count to 0 to 255 in binary with a pushbutton to advance count one step for each press of the button.
help greatly appreciated.
Counting is counting, whether it's Binary, Decimal, Hexadecimal or in Latin. It's how you finally OUTPUT it that counts. Here is a simple program that will count (add one) each time your Button is pressed, and output the status in BINARY to an array of LEDs.
Consider the following Program and circuit.
You have a PushButton connected between PortA.0 and Vss. A pull-up Resistor (say 10K) is connected between PortA.0 and Vdd. That means the pin is usually High (Logic 1) when NOT pressed, and goes Low (Logic Zero) when pressed.
PortB has an LED on each pin connected between the pin and Vss via a Resistor (one for each LED), lets say 330R.
The program variable CounterA is incremented once each time the PushButton is pressed, it's status is then sent to PortB so you can see it happen. The Pause is there to debounce the Pushbutton from giving you multiple counts on one press. The While-Wend pair is there to ensure you lift your finger off the button before a new count is registered. The rest you can figure yourself between the PICBasic manual and the Datasheet.
Code:' ' Program Hardware Defines ' ------------------------ PushButton var PortA.0 LEDArray var PortB ' ' Program software Defines ' ------------------------ CounterA var Byte ' ' Initialise Program ' ------------------ TRISA=%11111111 TRISB=%00000000 CounterA=0 ' ' Main Program Loop ' ----------------- Loop: If PushButton=0 then CounterA=CounterA+1 LEDArray=CounterA Pause 10 While Pushbutton=0:Wend endif Goto Loop end
the program you sent me work perfect.
greatly appreciated.
hope to become a lot smarter visiting your forum.
thanks again for an extremely quick response and for thinking about us "newbies"
dominic
Be confident Dominic. I get a big part of my knowledge here by trying to help other with their specific problem.
Have fun and good luck!
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks