will actually send [0x31,0x32,0x33,0x34,0x0d,0x0a] ascii 1,2,3,4,cr,lfUsing serial communicator (Microcode Studio tool) I send "1234", BUT LCD displays "Received = 3846"
how is your pc serial port connected to your pic ?
will actually send [0x31,0x32,0x33,0x34,0x0d,0x0a] ascii 1,2,3,4,cr,lfUsing serial communicator (Microcode Studio tool) I send "1234", BUT LCD displays "Received = 3846"
how is your pc serial port connected to your pic ?
I think Richard is correct. This from the manual:
SERIN begins storing data in the variables associated with each Item. If the variable name is used alone, the value of the received ASCII character is stored in the variable.
Meaning, in my mind, that you are actually receiving "3" "8" "4" "6" rather than 3846. If the LCD character codes are different than the ASCII character codes...
The manual goes on to say:
If variable is preceded by a pound sign ( # ), SERIN converts a decimal value in ASCII and stores the result in that variable.
This seems to indicate you will receive 3, 8, 4, 6 if you modify your statement. You can receive your data as byte array, and then use multiplication to expand the value into a word variable.
Editing to include this, a snippet from a recent project of mine that accepts a serial command in the format: CC*HR:MN to reset the time via serial input.
IF (CO[0] ="T") AND (CO[1]="I") THEN
REG_VAL[2] = (CO[3]-48) * 10 + (CO[4]-48)
REG_VAL[1] = (CO[6]-48) * 10 + (CO[7]-48)
GOSUB CLK_WRITE
CO[3] and CO[4] are the hour value of the time - I had to subtract 48 from the serial input to convert from the string value to the numeric value and multiply. I suspect you will need to do something similar.
Last edited by Amoque; - 20th November 2014 at 02:46.
Is this what you want?
it works using debug a little faster tooCode:mainloop: serin2 porta.1,84, [STR buffer\5] pause 200 serout2 PortA.0,84,[ "Received = ",STR buffer\5] pause 500 goto mainloop
Last edited by Archangel; - 20th November 2014 at 06:50.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
I think, Archangel, that it exactly the opposite of what he wants - though your code demonstrates the issue perfectly. The OP, it seems from my read, is transmitting the value 3846, but receiving the ASCII character codes of the digits, rather than the single numeric value he desires. Rereading my own post, I was not as clear as I'd wish to be in explaining this - and how to recover the actual value. Your use of STR demonstrates more clearly that it is actually 5 STRing characters received, rather than 1 numeric value.
Hi Amoque,
If he wants the Decimal number he will run into a problem at 65535 as that completely fills a WORD variable, requiring the use of a LONG variable.
His OP didn't indicate this need, at least that's how I read it. Still ASCII can be the medium for transport, doing the MATH (dirty 4 letter word) after receiving the number. LCD isn't going to display actual numbers as the first 47 are commands and symbols dating back to RTTY for which ASCII was invented, and that is what LCDs display (ASCII)
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Bookmarks