accepting ascii numbers from rs232 port and storing to eeprom

Status
Not open for further replies.

mgbglasgow

Junior Member level 1
Joined
Jun 15, 2011
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,508
im having difficulty understanding how to store characters from rs232 to eeprom, i need to store values between 0 and 255, i wish to prompt my users to enter seconds, or days, say 200, but when i get my values, first value in eeprom is equivalent to ascii '2',, im not looking for clever 16 bit stuff, just the textual value into a hex number would do,,,

any assistance greatly appreciated,

steve
 

from RS232 is too vague
unless I am mistaken RS232 is a hardware protocol
it doesn't specify what format; BCD, or ASCII [even within ASCII there are variations], or whatever

do you know the format coming over your RS232 connection?
 

its ascii, '2' results in 32 in my 1st eeprom space, which confirms ascii,,
 

I assume that you are attempting to parse the incoming numeric string of 1 to 3 characters and store it as a single hex byte.

Is this correct?

Are you coding in C or assembler? And for what processor.
 
Last edited by a moderator:

Hi,

i assume sending [2] [0] [0] [enter]
= hex [32] [30] [30] [0D]

reset register value
check if incoming value is a number:
if yes, multiply your register x 10, then add your incoming number (incoming hex value - hex30).

***
example:
value is cleared (0)
then a "2" comes in (hex32) - hex(30) = 2
multiply value (0) by 10 --> still 0
add 2 --> value is 2

then a "0" comes in (hex30) - hex(30) = 0
multiply value (2) by 10 --> (20)
add 0 --> value is 20

then a "0" comes in (hex30) - hex(30) = 0
multiply value (20) by 10 --> (200)
add 0 --> value is 200

then [enter] comes in...
--> save the value to EEPROM

*****

Klaus
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…