Binary Timer
Chris Palmer
Posts: 5
Hi, I am new with this stuff so my problem is probablly pretty obvious.
I am trying to make a binary timer, so far I am only trying to get to through the seconds part, then I'll move on to minutes and hours. I am using leds on on and off position to denote the 1 or 0. I have the cathodes connected to pin 14, and then the anodes are hooked up as follows:·32 is pin 13,·16 is pin 12,·8·is pin 11, 4·is pin 10,·2 is pin 9,·1 is PIn 8.
When I run the program all of the leds light up.
The codes is:
' {$STAMP BS2}
' {$PBASIC 2.5}
seconds VAR Byte
useableSeconds VAR Byte
LOW 14
PAUSE 1000
FOR seconds = 1 TO 60
· useableSeconds = seconds
· LOW 13
· LOW 12
· LOW 11
· LOW 10
· LOW 9
· LOW 8
· IF((useableSeconds - 32) >= 0) THEN
··· useableSeconds = useableSeconds - 32
··· HIGH 13
··· IF((useableSeconds- 16) >= 0) THEN
····· useableSeconds = useableSeconds - 16
····· HIGH 12
····· IF((useableSeconds- 8) >= 0) THEN
······· useableSeconds = useableSeconds - 8
······· HIGH 11
······· IF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ENDIF
····· ENDIF
··· ENDIF
··· ELSEIF((useableSeconds- 16) >= 0) THEN
····· useableSeconds = useableSeconds - 16
····· HIGH 12
····· IF((useableSeconds- 8) >= 0) THEN
······· useableSeconds = useableSeconds - 8
······· HIGH 11
······· IF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ENDIF
····· ENDIF
····· ELSEIF((useableSeconds- 8) >= 0) THEN
······· useableSeconds = useableSeconds - 8
······· HIGH 11
······· IF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ENDIF
······· ELSEIF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ELSEIF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
······· ELSEIF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
··········· PAUSE 950
···········
NEXT
Post Edited (Chris Palmer) : 11/22/2007 1:26:56 AM GMT
I am trying to make a binary timer, so far I am only trying to get to through the seconds part, then I'll move on to minutes and hours. I am using leds on on and off position to denote the 1 or 0. I have the cathodes connected to pin 14, and then the anodes are hooked up as follows:·32 is pin 13,·16 is pin 12,·8·is pin 11, 4·is pin 10,·2 is pin 9,·1 is PIn 8.
When I run the program all of the leds light up.
The codes is:
' {$STAMP BS2}
' {$PBASIC 2.5}
seconds VAR Byte
useableSeconds VAR Byte
LOW 14
PAUSE 1000
FOR seconds = 1 TO 60
· useableSeconds = seconds
· LOW 13
· LOW 12
· LOW 11
· LOW 10
· LOW 9
· LOW 8
· IF((useableSeconds - 32) >= 0) THEN
··· useableSeconds = useableSeconds - 32
··· HIGH 13
··· IF((useableSeconds- 16) >= 0) THEN
····· useableSeconds = useableSeconds - 16
····· HIGH 12
····· IF((useableSeconds- 8) >= 0) THEN
······· useableSeconds = useableSeconds - 8
······· HIGH 11
······· IF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ENDIF
····· ENDIF
··· ENDIF
··· ELSEIF((useableSeconds- 16) >= 0) THEN
····· useableSeconds = useableSeconds - 16
····· HIGH 12
····· IF((useableSeconds- 8) >= 0) THEN
······· useableSeconds = useableSeconds - 8
······· HIGH 11
······· IF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ENDIF
····· ENDIF
····· ELSEIF((useableSeconds- 8) >= 0) THEN
······· useableSeconds = useableSeconds - 8
······· HIGH 11
······· IF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ENDIF
······· ELSEIF((useableSeconds- 4) >= 0) THEN
········· useableSeconds = useableSeconds - 4
········· HIGH 10
········· IF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
········· ENDIF
······· ELSEIF((useableSeconds- 2) >= 0) THEN
··········· useableSeconds = useableSeconds - 2
··········· HIGH 9
··········· IF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
······· ELSEIF((useableSeconds - 1) >=0)· THEN
··········· useableSeconds = useableSeconds - 1
··········· HIGH 8
··········· ENDIF
··········· PAUSE 950
···········
NEXT
Post Edited (Chris Palmer) : 11/22/2007 1:26:56 AM GMT
Comments
This is ideal for your application because all you have to do is pass the OUT register a value and it will appear at the outputs in binary fashion.
When you connect your diodes connect the anode of each one to its respective output (as you have done) then connect a resistor of at least 220 ohms to the cathode of each diode (so 6 LED's = 6 resistors). Connect the other end of the resistors to VSS.
Heres an example to help you understand, it requires 4 diodes with resistors. Connect the anodes to P0,P1,P2,P3 respectively. The diodes should "count" to 15 binary then reset to 0 and start again. It will also display binary and decimal in a debug window.
DIRA=%1111·· '//SET I/O PINS 0-3 AS OUTPUTS
main:
IF OUTA =16 THEN OUTA=0
OUTA= OUTA+1
DEBUG CRSRXY,0,0,BIN4 OUTA,"· ",DEC2 OUTA
PAUSE 1000
GOTO main
Jeff T.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support