Shop OBEX P1 Docs P2 Docs Learn Events
Reading a string of characters from an array question. — Parallax Forums

Reading a string of characters from an array question.

JMLStamp2pJMLStamp2p Posts: 259
edited 2008-02-22 15:26 in Propeller 1
Good morning all,

I have a·(4 by 4) Matrix keypad·that I am using to input characters into a Serial LCD. The numbers are showing on the·LCD and I can access the numbers entered via the PUB HandleNumber_1 Method. The problem is every time I reset my program via the reset button on the Prop proto board.
I get a different value of numbers on the LCD. I believe that my problem may be in the rxStr(3,@datain) method code but I have not been able to solve it
and need some help. Can someone please look at this code and give me some advice. I have made comments under the commands as I understand them to this point·and·If any of these comments are not correct please let me know.
Thanks,
JMLStamp2p

PS: My serial LCD outputs ASCII characters representing the digits 0-9
and A,B,C,D,# AND THE *

========================================================
CON
·_CLKMODE = XTAL1 + PLL1X···
·_XINFREQ = 5_000_000

VAR
· Byte datain[noparse][[/noparse] 2]
· Long Timer_1,Timer_2,Timer_3
·
OBJ
· data : "FullDuplexSerial"
· Delay: "Clock"
·
PUB Main | Value············

·data.Stop···················
·data.start(3,2,0,19200)
···
·data.tx(254)·····································
·data.tx(88)··············
·data.tx(254)···
·data.tx(72)
'Clear LCD screen and goto home position.

·rxStr(3,@datain)
'Call rxStr and pass the number of characters
'to be recieved and
'Pass the address of the
'datain array.
·
·HandleNumber_1(@datain)
'After rxStr(3,@datain) has recieved 3 characters
'and exits back to Main jump to the HandleNumber_1
'method and pass the address of the datain array.


PUB RxStr(Num_of_Chars,strPtr) : char

·repeat
··
·· if Num_of_Chars-- == 0······
····· byte[noparse][[/noparse]strPtr] := 0·········
····· return
· 'Number of chars is set to 3 in its call
· 'so if Num_of_Chars does not = 0
· 'keep repeating and decrementing
· 'until it does. When it does, set the
· 'starting location of the datain array to
· '(0) and exitback to Main.

··char := data.rx
··'char is = to data recieved via FullDuplexSerial

··data.dec(char)

· 'Set char = the byte recieved via
· 'FullDuplexSerials rx method.
· 'And then show on LCD.
·····
· byte[noparse][[/noparse]strPtr++] := char
· 'Save the new character recieved
··'to the char varible and increment
· 'the datain array pointer·to the next
· 'location in memory·to hold the next
· 'byte recieved.

·
PUB HandleNumber_1(Location)| LocIndex, Value_in_array

·dira[noparse][[/noparse]16]~~

·LocIndex := byte [noparse][[/noparse]Location]
· 'Set LocIndex to the byte value
· 'of location "0"
· 'in the datain array.
·
·Value_in_array := LocIndex
·'Set "Value_in_array" to the
·'value of LocIndex

·· data.tx(254)·····································
·· data.tx(71)··············
·· data.tx(1)···
·· data.tx(2)
·· 'Location of Cursor on LCD.
··
·· data.dec(Value_in_array)
·· 'Print Value to LCD
··
·· waitcnt(5_000_000 + cnt)

·· data.tx(254)·····································
·· data.tx(71)··············
·· data.tx(1)···
·· data.tx(3)
· ''Move Location of Cursor on LCD.


·· data.dec(datain[noparse][[/noparse]1])

·· waitcnt(5_000_000 + cnt)
·· data.tx(254)·····································
·· data.tx(71)··············
·· data.tx(1)···
·· data.tx(4)
· ''Move Location of Cursor on LCD.

·· data.dec(datain[noparse][[/noparse]2])


·
Sign In or Register to comment.