Help!! serin problem
danlo
Posts: 5
I want to receiver a string, and then write·it·into EEPROM
There is my code
'EEPROM
Totalprice··· DATA·· 0
price·········· VAR···· Byte(5)
'Program code
· SERIN 9,813, [noparse][[/noparse]STR price\5\"#"]
· DEBUG STR price
· WRITE totalprice,price
·· .....
·· .
For example,
price = 321, totalprice should be equal to 321
but the real result of totalprice = 3, only write the first character of price....why?
What wrong of my programming code? Please Help!!
Post Edited (danlo) : 1/23/2007 12:08:37 PM GMT
There is my code
'EEPROM
Totalprice··· DATA·· 0
price·········· VAR···· Byte(5)
'Program code
· SERIN 9,813, [noparse][[/noparse]STR price\5\"#"]
· DEBUG STR price
· WRITE totalprice,price
·· .....
·· .
For example,
price = 321, totalprice should be equal to 321
but the real result of totalprice = 3, only write the first character of price....why?
What wrong of my programming code? Please Help!!
Post Edited (danlo) : 1/23/2007 12:08:37 PM GMT
Comments
When you read in the string you did so this way:
SERIN 9,813, [noparse][[/noparse]STR price\5\"#"]
and you told SERIN you wanted up to 5 bytes (price\5\"#") as you should. However, when you went to WRITE the data, you didn't specify anything in your WRITE command, nor for that matter could you:
WRITE totalprice,price
The variable "price" is an array of single BYTES, of 5 in number. Why would you think that WRITE would presume to use more than one BYTE? Additionally "totalprice" (a rather odd name for a location index!) is never incremented, so you will only EVER WRITE into EEPROM location ZERO, and nowhere else.
The following would work (just as a simple example) but it's very cumbersome and not sufficiently universal:
WRITE totalprice,price(0), totalprice+1,price(1),totalprice+2,price(2),totalprice+3,price(3) ... etc.
You will need to perform an iterative WRITE for the proper number of BYTES based on the size of the individual input received each time AND you need to increment the EEPROM location for each BYTE to be written. Also remember to clear your array to some unused characters each time, so you can locate the end of the individual (unknown length) input strings.
Regards,
Bruce Bates
Post Edited (Bruce Bates) : 1/23/2007 12:52:10 PM GMT
Totalprice DATA 0
price VAR Byte(5)
price_data VAR Byte
index VAR Nib
· 'SERIN 9,813, [noparse][[/noparse]STR price\5\"#"]
·· DEBUGIN STR price\5
· DEBUG STR price,CR
· FOR index =0 TO 4
· WRITE totalprice+index,price(index)
· NEXT
· FOR index =0 TO 4
· READ totalprice+index,price_data
· DEBUG price_data
· NEXT
· READ Totalprice+2,price_data
· DEBUG CR,price_data
Jeff T.
thank you so much