Dual LED Display Counter 00-99
Caine
Posts: 4
First off, forgive the bold and larger font, my eyes see better with it this way.
Hi everyone, i'm just wondering how you would go about making a counter from 00 - 99 and repeat itself infinitely. I am doing this for a final exam in my class, and the first method i used was a sub routine method, i'll attach the code. But for my final exam, the teacher wants me to use 1 lookup table to accomplish the same task as i did with sub routines.
Thanks for looking.
~Caine
Sub-Routine Code I Made (teacher called it a brute force method, hehe)
Okay, i have the single digit 7 segment display connected to I/0 pins 8 - 15 and the tens digit 7 segment display connected to I/O pins 0 - 7. The #3 common cathode is connected to VSS (ground) on each display and the #8 common cathode is left un-used on both LED displays. I've run all power connections through a 1k (brown-black-red) Resistor.
Hi everyone, i'm just wondering how you would go about making a counter from 00 - 99 and repeat itself infinitely. I am doing this for a final exam in my class, and the first method i used was a sub routine method, i'll attach the code. But for my final exam, the teacher wants me to use 1 lookup table to accomplish the same task as i did with sub routines.
Thanks for looking.
~Caine
Sub-Routine Code I Made (teacher called it a brute force method, hehe)
' {$STAMP BS2} ' {$PBASIC 2.5} OUTH = 000000 OUTL = 000000 DIRH = 111111 DIRL = 111111 GOSUB First_Subroutine GOSUB Second_Subroutine First_Subroutine: '[SIZE=1]BAFG.CDE[/SIZE] OUTH = 100111 PAUSE 250 OUTH = 000100 PAUSE 250 OUTH = 010011 PAUSE 250 OUTH = 010110 PAUSE 250 OUTH = 110100 PAUSE 250 OUTH = 110110 PAUSE 250 OUTH = 110111 PAUSE 250 OUTH = 000100 PAUSE 250 OUTH = 110111 PAUSE 250 OUTH = 110110 PAUSE 250 RETURN Second_Subroutine: '[SIZE=1]BAFG.CDE[/SIZE] OUTL = 000100 GOSUB First_Subroutine OUTL = 010011 GOSUB First_Subroutine OUTL = 010110 GOSUB First_Subroutine OUTL = 110100 GOSUB First_Subroutine OUTL = 110110 GOSUB First_Subroutine OUTL = 110111 GOSUB First_Subroutine OUTL = 000100 GOSUB First_Subroutine OUTL = 110111 GOSUB First_Subroutine OUTL = 110110 RETURN
Okay, i have the single digit 7 segment display connected to I/0 pins 8 - 15 and the tens digit 7 segment display connected to I/O pins 0 - 7. The #3 common cathode is connected to VSS (ground) on each display and the #8 common cathode is left un-used on both LED displays. I've run all power connections through a 1k (brown-black-red) Resistor.
Comments
Look in the Basic Stamp Syntax and Reference Manual in the sections describing the READ and DATA statements. The DATA statement will allow you to create tables, one table for each digit with a byte value for either each display column or row depending on how you have the display wired. You either output a row at a time or a column at a time with all the bits coming from one byte. The READ statement will let you read a byte from the table, then you'd output it by assigning the value to OUTL as you've shown above.
Regarding what you posted ... I assume these numbers are supposed to be in binary, not decimal. If so, they need to have a % in front of them to tell the Stamp Editor that the numbers are binary.
When you want some feedback on a program, you need to say something about what's connected to what. We can guess that I/O pins 0-7 are somehow connected to your LEDs as are I/O pins 8-15, but it's not at all clear how or what.
Ok, so you have the least significant digit connected to I/O pins 8-15 and the most significant digit connected to I/O pins 0-7. There are lots of ways you can do this so you can get the right digits to the right places.
Remember that, if you have a value in the variable NUMBER, then the least significant digit is NUMBER DIG 0 and the tens digit is NUMBER DIG 1. Look up the description of the DIG operator in the Manual.
If you have a 16-bit word like OUTS, you can also look at it as two 8-bit bytes by using .BYTE(x) where x is a 0 or 1. Unfortunately, you've wired the digits so they'll be backwards, so you can write OUTS.BYTE(1-x) to refer to the tens digit by setting x to 1 and the ones digit by setting x to 0.
You'll need a for loop with x (or something else) going from 0 to 1 and a LOOKUP statement with the index NUMBER DIG x. The selected lookup value gets put into OUTS.BYTE(1-x). Try it.
Here is a binary number using the [ code ] tags as described in "How to Post Code".
If you get an error message from your code, it helps to show or tell us what line the message referred to.
Sometimes the forum software messes up percent signs even when in code tags. I've had this happen several times but never when I've tried to reproduce it on purpose.
[code]
' {$STAMP BS2}
' {$PBASIC 2.5}
index VAR Byte
DEBUG " Counting 00-99 ", CR
OUTH = 000000
OUTL = 000000 'OUTH & OUTL initialized to low.
DIRH = 111111
DIRL = 111111 'Set P0-15 to all out-put low.
DO
FOR index = 0 TO 9
LOOKUP index, [ 100111, 000100, 010011, 'Count 10, 20, 30...90
010110, 110100, 110110,
110111, 000100, 110111,
110110 ], OUTL
OUTH = 000100
PAUSE 150
OUTH = 010011
PAUSE 150
OUTH = 010110 'Count 1,2,3,4...9
PAUSE 150
OUTH = 110100
PAUSE 150
OUTH = 110110
PAUSE 150
OUTH = 110111
PAUSE 150
OUTH = 000100
PAUSE 150
OUTH = 110111
PAUSE 150
OUTH = 110110
PAUSE 150
OUTH = 100111
PAUSE 150
NEXT
LOOP
You want it to go from 0-99, using one lock-up table that will have a list of what pin should be low/high to show a led zero, one, two......
I think you could do (pseudo code and not tested)
A=0
loop forever
B =A %10 ' modulo
set OUTL(B) ' B point to table.
B =(A %100 -B) /10
set OUTH(B) ' B point to table.
A=A+1
http://www.ebay.com/itm/0-56-4-Digital-Red-LED-Digital-Frequency-Meter-Electronic-Counter-Multimeter-/251197986175?pt=LH_DefaultDomain_0&hash=item3a7c91157f