the up and dn button is read through the adc returning a value
up = 6 count up to (9999)
dn= 7 or countdown
normal status =8 no button pressed
both pressed =3 allows to zero count ( 0)
power <5v =9 allowing number to be writen to eeprom when power turned off
note may require a supply that drops off slowly i use a 12v plugpack feeding a 5v regulator
( the 12v holds up for a couple of secs)
if using standard picaxe 5v regulated supply should work ok
if using a battery add a 100uf capacitor across picaxe supply pins 1 and 20(if u dont already hav 1 lol)
for reliable write to eeprom operation should work ok lol.
a voltage between 5 and 5.4 is required for lower voltages different adc values wil be required
ie.for voltage between 4.6 and 4.9 approx change value 3 to 4 (both buttons pushed) others ok
ie.for lower voltages 4.6 vref of tl431 would have to be changed also
up = 6 count up to (9999)
dn= 7 or countdown
normal status =8 no button pressed
both pressed =3 allows to zero count ( 0)
power <5v =9 allowing number to be writen to eeprom when power turned off
note may require a supply that drops off slowly i use a 12v plugpack feeding a 5v regulator
( the 12v holds up for a couple of secs)
if using standard picaxe 5v regulated supply should work ok
if using a battery add a 100uf capacitor across picaxe supply pins 1 and 20(if u dont already hav 1 lol)
for reliable write to eeprom operation should work ok lol.
a voltage between 5 and 5.4 is required for lower voltages different adc values wil be required
ie.for voltage between 4.6 and 4.9 approx change value 3 to 4 (both buttons pushed) others ok
ie.for lower voltages 4.6 vref of tl431 would have to be changed also
Code:
' -- -- -- -- -- -- -- --
' B0-A | | | | | | | |
' B1-B
' B2-C | | | | | | | |
' B3-D -- -- -- -- -- -- -- -- MarkS
' B4-E | | | | | | | |
' B5-F
' B6-G | | | | | | | |
' B7-dp -- -- -- -- -- -- -- --
'
'Display 1 2 3 4
'Common anode C.3 C.2 C.1 c.0
eeprom 0,(192,249,164,176,153,146,130,248,128,144,255) 'character (0,1,2,3,4,5,6,7,8,9,blank)
SETFREQ M16
SYMBOL display1 = C.3
SYMBOL display2 = C.2
SYMBOL display3 = C.1
SYMBOL display4 = C.0
SYMBOL character = B10
SYMBOL number = W1
SYMBOL bounce = W2
SYMBOL pushbutton = W3
let dirsb = %11111111
let dirsc = %00111111
main: read 22,word number
start:bounce = 0
Display:
character = 10 : IF number < 1000 THEN dig1 'Display1 Zero blanking
LET character = number DIG 3
Dig1: READ character,pinsb : LOW display1 : PAUSE 1 : HIGH display1
IF number < 100 THEN dig2 'Display2 Zero blanking
LET character = number DIG 2
Dig2: READ character,pinsb : LOW display2 : PAUSE 1 : HIGH display2
IF number < 10 THEN dig3 'Display2 Zero blanking
LET character = number DIG 1
Dig3: READ character,pinsb : LOW display3 : PAUSE 1 : HIGH display3
LET character = number DIG 0
Dig4: READ character,pinsb : LOW display4 : PAUSE 1 : HIGH display4
readadc10 c.7,pushbutton let pushbutton= pushbutton/100 'check pushbutton status
if pushbutton =8 then start 'no buttons pressed
if pushbutton =3 then let number = 0 :endif 'both buttons pressed will zero number
inc bounce
if bounce >1 then display
if pushbutton =6 then IncrementCounter ' Up button pressed
if pushbutton =7 then DecrementCounter ' Dn button pressed
if pushbutton =9 then Remember ' Detects voltage <5v when powered off
IncrementCounter:
inc number
if number=10000 then : number = 0 :endif
goto display
DecrementCounter:
dec number
if number=65535 then : number = 9999 :endif
goto display
Remember:
write 22,word number
goto display
Attachments
-
215.7 KB Views: 182
Last edited: