Ok... How to access the PINS as an array
Kaos Kidd
Posts: 614
Greets everyone.· Now that my new laptop and I have been aquainted, and thusly tought how to communicate with the BS2P that I own, A simmingly small thing, but apperently something I cant quite get·the grasp of issue has arrised.
What I'm trying to do is duplicate Beau's "shaker" program.· Sounds simple enough.· NOT!
First off all, I can't figure out how to address the output pins as if they are an array.
Once I get that right, I might be able to get the rest worked out, but my application is based on the following...
#· 1: Get the current time in 24 hour format· (not implimented yet, using a temp "00:00:00" string).
#· 2: For each character in the output string:
#· 3:··· compute the correct offset to the first bit in the array of bits containing the bit maps of the numbers· (each number is 5X7 bits long)
#· 4:··· For each Column in the character's bit array:· (there are 5 columns)
#· 5:····· For each Row in the character's bit array:··· (there are 7 rows)
#· 6:······· Set the correct PIN to the state found in the array at this offset.·· <--- this step is the one giving me the achs right now!
#· 7:····· Next Row············
#· 8:···Pause slightly so the entire column can be viewed
#· 9:·· Next Column
#10: Pause slightly so there is a space between each charactor being displayed
#11: Loop
Ok, this sounds simple enough, but I can't get past the first hump, addressing the PINs as if there were bits in an array.
The next hump I'll need to jump is taking the output from the RTC, ensure it's formatted in "00:00:00" format, and send it to this routine.
I've put the code inline here, as well as an attachment.· I'm sure you grueus will spot a number of errors, and I welcome any and all crits and comments on it, as well as shortcuts or better ways to do things (for example, the MOD command at the bottom of the loop, I know there's a better way, I·just cant find it [noparse]:)[/noparse] ), Please let me know.· I also think I need to work on my method of decoding what number to display (look at the lookdown / up combination).· Again, once I can get the heart of the program working, I'll get lots more done.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
What I'm trying to do is duplicate Beau's "shaker" program.· Sounds simple enough.· NOT!
First off all, I can't figure out how to address the output pins as if they are an array.
Once I get that right, I might be able to get the rest worked out, but my application is based on the following...
#· 1: Get the current time in 24 hour format· (not implimented yet, using a temp "00:00:00" string).
#· 2: For each character in the output string:
#· 3:··· compute the correct offset to the first bit in the array of bits containing the bit maps of the numbers· (each number is 5X7 bits long)
#· 4:··· For each Column in the character's bit array:· (there are 5 columns)
#· 5:····· For each Row in the character's bit array:··· (there are 7 rows)
#· 6:······· Set the correct PIN to the state found in the array at this offset.·· <--- this step is the one giving me the achs right now!
#· 7:····· Next Row············
#· 8:···Pause slightly so the entire column can be viewed
#· 9:·· Next Column
#10: Pause slightly so there is a space between each charactor being displayed
#11: Loop
Ok, this sounds simple enough, but I can't get past the first hump, addressing the PINs as if there were bits in an array.
The next hump I'll need to jump is taking the output from the RTC, ensure it's formatted in "00:00:00" format, and send it to this routine.
I've put the code inline here, as well as an attachment.· I'm sure you grueus will spot a number of errors, and I welcome any and all crits and comments on it, as well as shortcuts or better ways to do things (for example, the MOD command at the bottom of the loop, I know there's a better way, I·just cant find it [noparse]:)[/noparse] ), Please let me know.· I also think I need to work on my method of decoding what number to display (look at the lookdown / up combination).· Again, once I can get the heart of the program working, I'll get lots more done.
' {$STAMP BS2p} ' {$PBASIC 2.5} ' Shaker clock by Fred Kerber ' Special thanks to David and Beau for posting and coding the SPIN equevlent! 'Program vars Pointer VAR Byte 'pointer into current number being displayed Offset VAR Byte 'Index into output string CurrentChr VAR Byte 'index into current char we are displaying Columns VAR Byte 'Holds current column Rows VAR Byte 'holds the current row Text DATA "00:00:00" 'Temp data (soon to be RTC data) InterCharPause CON 50 'pause for inter charactor display InterColumnPause CON 10 'pause for inter column display SpacerPause CON 100 'Pause for the ":" in the time format OutLength CON 8 'Length of output string INIT: DIRS = %1111111000000000 'Set pins 0~7 = outputs OUTH = %0000000000000000 'set all pins to low Pointer = 0 'Set pointer to first char in Text MAIN: DO 'Main program loop CurrentChr = Text[noparse][[/noparse]Pointer] 'Get the next position into the array 'text' LOOKDOWN CurrentChr, [noparse][[/noparse]48,49,50,51,52,53,54,55,56,57,58],Offset 'Get ascii to index offset LOOKUP Offset,[noparse][[/noparse]Numbers],Offset 'Convert index FOR Columns = 0 TO 4 '5 columns FOR Rows = 0 TO 6 '7 rows OUTH[noparse][[/noparse]Rows] = Numbers[noparse][[/noparse] ((Offset * 34) + ( Columns * 5 ) + Rows) ] 'Set the pin NEXT Rows 'Finish all 7 rows... PAUSE InterColumnPause 'temp pause to verify NEXT Columns 'Finish all the columns PAUSE InterCharPause 'Pause for a space between each char Pointer = (Pointer + 1) // OutLength 'move to next char, looping at end LOOP 'Display data. Each number is a 5 X 7 array Numbers DATA "01110100011000110001100011000101110" 'Number 0 DATA "00100011000010000100001000010011111" 'Number 1 DATA "01110100010000100010001000100011111" 'Number 2 DATA "01110100010000100110000011000101110" 'Number 3 DATA "00010001100101010010111110001000010" 'Number 4 DATA "01111100001000001110000010000101110" 'Number 5 DATA "01110100011000010110110011000101110" 'Number 6 DATA "11111000100010001000100001000010000" 'Number 7 DATA "01110100011000101110100011000101110" 'Number 8 DATA "01110100011001101101000011000101110" 'Number 9 DATA "00000001000010000000001000010000000" 'Character ':'
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
Comments
I think you are doing more than you have to to get the character patterns. You have a list of numbers in your data statements and although they "look" like binary to our eyes, each of those ones and zeros take up a whole byte of space. I notice you are looking at the character matrix as horizontal slices 7 times for the whole character. You may try to think of things a little differently. Imagine the character as 5 vertical slices. 7 bits fit nicely in a byte and it only takes 5 bytes to represent one character.
For example the character "0" can be represented by, $3E, $41, $41, $41, $3E.
0 0 0 0 0
0 1 1 1 0
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
0 1 1 1 0
See each of the hexidecimal bytes above will represent all the leds in a column. You can just ignore the data in the MSB. Lots less data to store. Also it takes less time to display 5 columns than it does to display 7 rows.
Hope this helps.
Lee
But still, the actual setting of the outputs I can't seem to fine the answer... but I'll pump more time into it later today...
THanks again!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
By adjusting the way I stored the bit patterns, It makes better usage of memory, is easier to read, and I bet I can figure out how to set the pins now... [noparse]:)[/noparse]
Thanks...
(Ok, I've done a lot of editing, and later I'll repost the code... even if I get it to work..· [noparse]:)[/noparse]· )
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
Post Edited (Kaos Kidd) : 3/9/2006 9:49:11 PM GMT
I've added vars to assist in the debugging of the app, but still I'm somewhat lost.
I can get it to compile, but It's not doing the lookup correctly.
In particular, the line:
LOOKUP Pointer,[noparse][[/noparse]Text],CurrentChr····'Get current char
What I was expecting is the ASCII number of the at the position Pointer.
WHat I get, no matter how I try it, its returning·0, which is causing the rest of the app to misbehave.
Now, if I change the line to:
LOOKUP Pointer,[noparse][[/noparse]"00:00:00"],CurrentChr··········································· 'Get current char
It works as expected.
I'm sure it's how I'm dealing with the data, but I'm not sure how else to proceede.·
The end result is I think need the ASCII for each digit so I can display them.· The last stages of this app is to insert the RTC and have it supply the time, then make the bottom mouted pendulum to hold the leds.· It's for this reason I think· I need the ascii, so I can break down the output of the RTC correctly.·
BTW, the app does work, I recenty started working on the pauses to get it to look right, but I ran out of time.
For what it's worth, here's the code.· Any crits or comments, OR HELP would be great!
KK
And just for the record, can someone point out the ovious 'Mask' needed to AND my output with the OUTS var so as to NOT change any of the other pins ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
See if this helps...· The problem that I saw was that the data was indexed incorrectly.
Your·line that reads...
LOOKUP Pointer,[noparse][[/noparse]Text],CurrentChr····'Get current char
...Does NOT point to what is in Text.· In fact, you don't even need to use the LOOKUP command.
All you need to do is use the READ command with the proper·pointer locations.· By changing your
LOOKUP command to this...
READ (Text + Pointer),CurrentChr
...was all that was really necessary.· The only other line I changed was the line that reads...
BaseIndex = Offset * 5
...I changed this to...
BaseIndex = Offset * 5 + Numbers
...in case you added more DATA above "Numbers" you would still be able to maintain a reference.
As far as getting it to "look right", I had originally made mention the use of an accelerometer, so that you had some sort of reference
in space as to when you switched direction (shaking).· Without some sort of reference point, you will be limited to symmetrical patterns
that you can display and be able to perceive with any meaning.· "00:00:00" <--Seems to work, because it looks the same forward as it
does backward, thus it is a symmetrical pattern.
Typically you OR the data to not change any of the other pins.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thanks for pointing the OR and the incorrect indexing. That did the trick. What I did next was move the whole thing to scratchpad ram (out of eeprom) so when the rtc starts updating it, I don't endup killing the eeprom cell. Well, your indexing 'fix' works here as well. I'v coded my first BCD to ASCII routine, and made the allocations for the RTC (PFC8583). Once I get this done, it's time for the 'hardware' of the project...
At some point I'll recover some VAR ram and recycle some of the VAR's used, to make room for the last two code segments (motor control for the pendulem) and sensor
inputs (to indicate the start of a left-> right swing, or the start of a right<-left swing).
Thanks again for the help... I'll include you in the credits!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·