serout str array\7 doesn't behave as expected
blittle
Posts: 19
This is just a simple project with a 4x4 keypad, 2x16 serial lcd, and an inductive proximity sensor to count metal pieces.
The keypad key values are stored in a byte array, and I want to send the string to the lcd.
I'm not sure what the lcd is seeing (hex?) but it doesn't work as-is.
What am I doing wrong please?
Bill
update: oops forgot: the problem part is at line 65.
p.s. Should the code tag on the forum preserve the code formatting? i.e. fixed width
The keypad key values are stored in a byte array, and I want to send the string to the lcd.
I'm not sure what the lcd is seeing (hex?) but it doesn't work as-is.
What am I doing wrong please?
Bill
update: oops forgot: the problem part is at line 65.
' {$STAMP BS2} ' {$PBASIC 2.5} db VAR Bit ' keypad debounce bit press VAR Bit ' Flag to indicate keypress. sdb VAR Bit ' sensor debounce bit schanged VAR Bit ' sensor trigger flag for display update scount VAR Word ' Sensor count mo VAR Byte(8) ' manufacturing order number moidx VAR Nib ' mo array index key VAR Nib ' Key number 0-15. row VAR Nib ' Counter used in scanning keys. i VAR Nib ' generic counter var cols VAR IND ' Input states of pins P4-P7. time VAR Word TX PIN 0 ' serial output to LCD baud VAR Word ' baud rate for Serial LCD dark CON 50 ' rctime high value to turn on backlight T19K2 CON 32 ' con for baud var LcdCls CON $0C ' clear LCD (use PAUSE 5 after) LcdCr CON $0D ' carriage return LcdBLon CON $11 ' backlight on LcdBLoff CON $12 ' backlight off LcdOn1 CON $16 ' LCD on; cursor off, blink off HIGH TX ' setup TX pin for LCD PAUSE 100 ' allow LCD to intialize baud = T19K2 scount = 0 ' zero the counter key = 0 ' zero the key buffer moidx = 0 ' zero the mo index SEROUT TX, baud, [noparse][[/noparse]LcdOn1, LcdCls, LcdBlOn] ' initialize lcd PAUSE 5 SEROUT TX, baud, [noparse][[/noparse]"MO ", LcdCr, DEC scount] ' initialize display main: HIGH 2 PAUSE 100 RCTIME 2, 1, time IF (time > dark) THEN SEROUT TX, baud, [noparse][[/noparse]LcdBlOn] ELSE SEROUT TX, baud, [noparse][[/noparse]LcdBlOff] ENDIF GOSUB checkSensor IF schanged = 1 THEN SEROUT TX, baud, [noparse][[/noparse]LcdCls] PAUSE 5 'SEROUT TX, baud, [noparse][[/noparse]"MO ", STR mo\7, LcdCr, DEC scount] SEROUT TX, baud, [noparse][[/noparse]"MO ", LcdCr, DEC scount] schanged = 0 ENDIF GOSUB keyScan IF press = 0 THEN main mo(moidx) = key IF moidx < 7 THEN moidx = moidx + 1 ENDIF SEROUT TX, baud, [noparse][[/noparse]LcdCls] PAUSE 5 SEROUT TX, baud, [noparse][[/noparse]"MO ", STR mo\7, LcdCr, DEC scount] FOR i = 0 TO 7 DEBUG "-", DEC mo(i) NEXT DEBUG CR 'DEBUG "MO ", STR DEC mo\7, CR press = 0 GOTO main keyScan: FOR row = 8 TO 11 LOW row key = ~cols key = NCD key IF key <> 0 THEN push INPUT row NEXT db = 0 RETURN push: IF db = 1 THEN done db = 1: press = 1 key = (key-1)+(row*4) LOOKUP key,[noparse][[/noparse]1,2,3,10,4,5,6,11,7,8,9,12,14,0,15,13],key done: INPUT row RETURN checkSensor: IF IN1 = 1 THEN IF sdb = 1 THEN RETURN sdb = 1 schanged = 1 scount = scount+1 ELSE 'sensor went low so we can reset debounce sdb = 0 ENDIF RETURN
p.s. Should the code tag on the forum preserve the code formatting? i.e. fixed width
Comments
Jeff T.
I tried it anyway and still got the lcd junk and the debug keys where wrong somehow.
Thanks for the suggestion though.
Bill
Jeff T.
EDIT I also notice you have cols described as IND P4 - P7 when P4 - P7 is actually INB
Post Edited (Unsoundcode) : 9/29/2007 8:36:29 PM GMT
http://www.parallax.com/detail.asp?product_id=27944
I used the example code from listing 22.1 in this Nuts and Volts article mostly:
http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv22.pdf
Yeah, I noticed the comment error after IND after I posted it. [noparse]:)[/noparse]
It would have been helpful of me to add that the keypad code works fine if I just send key to the lcd.
The problem is trying to stick key into the mo array and then send the array to the lcd.
The lcd becomes corrupted.
Bill
Post Edited (blittle) : 9/29/2007 9:05:33 PM GMT
IF moidx < 7 THEN
··· moidx = moidx + 1
·· ENDIF
·· SEROUT TX, baud, [noparse][[/noparse]LcdCls]
·· PAUSE 5
SEROUT TX, baud, [noparse][[/noparse]128]
PAUSE 5
SEROUT TX, baud, [noparse][[/noparse]"TEST ", mo(0)]
PAUSE 10000
what do you get if you run the above
Jeff T
-Phil
Just to clear it up in my mind you do have P8 to P15 connected to the keypad·and quotes around the lookup values yes?
Jeff T.
EDIT nice catch Phil.....the example code uses 0 to 3 for rows keeping it with bounds
Post Edited (Unsoundcode) : 9/29/2007 9:33:25 PM GMT
I pressed number 1 for the test.
Yep, the keypad is on P8-P15.
I do not have the lookup values quoted because I get the wrong values if I do.
1,2,3 return correct. A returns 1, B returns 6, C returns 8, D returns 1, 5 returns 44, etc.
If I leave them unquoted, the debug in the FOR block visualy returns the array as I would expect.
Testing what Phil is saying would be real quick. Add a NIB variable ·and call it TEST and add the following code to see what happens.
·FOR·row·=·8·TO·11
TEST=row-8· 'add this line
then adjust
key·=·(key-1)+(row*4) to read key·=·(key-1)+(TEST*4)
Jeff T
I pressed 1,2,3,4,A,4,5,6,B in order and got this in the debug window:
-1-0-0-0-0-0-0-01
-1-2-0-0-0-0-0-02
-1-2-3-0-0-0-0-03
-1-2-3-1-0-0-0-01
-1-2-3-1-0-0-0-00
-1-2-3-1-0-4-0-04
-1-2-3-1-0-4-5-05
-1-2-3-1-0-4-5-66
The LCD shows garbage.
Try the attached mod of your code
Jeff T.
LOOKUP key,[noparse][[/noparse]49,50,51,65,52,53,54,66,55,56,57,67,69,48,70,68],mo(moidx)
LOOKUP key,[noparse][[/noparse]"1","2","3","A","4","5","6","B","7","8","9","C","E","0","F","D"],mo(moidx)
BTW the modified code in the last post has two typos in the lookup table, the zero and the F were given the wrong values. The above is correct.
Jeff T.
EDIT: another possible problem in your code is the statement IF key <> 0 THEN push I believe should be IF key <> 0 THEN GOSUB push
Post Edited (Unsoundcode) : 9/30/2007 8:52:45 PM GMT
Thanks for your help.
I'll post the final code and schematic back here after I add some features and get it cleaned up.
It's going to be a simple keypad, lcd, and mountable sensor so a worker can key a Manufacturing Order number then count pieces produced, that will be sent to a pc for data collection.
A basic commercial sensor counter can be quite expensive, around $300.
This project costs somewhere around half that, including the prox sensor, and of course it's hackable and has a pc interface.
So people in manufacturing (like me) might appreciate it.
Thanks again.
Bill