After reading some of the book, I want to try this circuit out, but I need to build on it.
http://www.mikroelektronika.co.yu/engli ... ook/07.htm
What I need is the following:
A counter.
It is to start from 0 (minimum) & reach up to 63 (maximum).
This counter will be moving up and down within those limits.
If a button is pressed (please read below), then the counter will go either up, or down, but NOT beyond the limit, and an appropriate output will be activated. If the limit is reached, then it will not pass on the signal.
It will also keep on the display the number where the counter is.
Pin1 – RA2, to be a “Dual” input. There will be two buttons connected to it. One contact will be from earth, the other from the +5v rail.
Pin2 & 3 – RA3 & 4, to be simple outputs.
When pin 1 goes “low” (button pressed, that is connected to earth), to subtract “1” from the counter.
When it goes “high”, to add 1
Here is a a generic drawing I made.
The rest of the connection are the same as in the above mentioned page.
In "pseudo-basic" (does this still exist?) it would look something like this:
Code: Select all
dim A as byte ’accept a number from 0 to 255
Port RA2 = In ’pin #1 on Pic16F84
Port RA3 = Out ’pin #2
Port RA4 = Out ’pin #3
Let A = 0 ’initialise A to equal 0.
Main
If RA2 = High gosub HELLO-A
If RA2 = Low gosub HELLO-B
Goto main.
HELLO-A
While RA2 is high & A <=62 ’If button is still being pressed, do it again unless you reached the limit
A=A+1 ’this should loop until 62 + 1 = 63
Open port RA3
Gosub DisplayAmount
Delay_ms(250) ’ wait for ¼ of a second
Close port RA3
wend
Return
HELLO-B
While RA2 is high & A >=1
A=A-1 ’if it reaches 1 then " -1" = 0
Open port RA4
Gosub DisplayAmount
Delay_ms(250) ’ wait for ¼ of a second
Close port RA4
wend
Return
DisplayAmount
Display the value of A on both digits.
Return
Can someone please write the WHOLE - COMPLETE code, and explain how it is done?
Will it fit in the 16F84? Does it have enough memory?
I will try to build it over the weekend
I am just a beginner
Also are the transistors PN2222A? (PN100 – TO92 package)
Any help will be greatly appreciated.