PDA

View Full Version : Serial problems



n0yox
- 30th September 2015, 03:46
PBP3, Here is my newest problem.

#config
__config _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_ON & _BODEN_OFF
#endconfig
CMCON = 7 'CHANGES PORTA TO DIGITAL
V1 VAR byte
V1 = 0
SETTINGS:
OVER:
SERIN2 PORTB.0,16468,3000,OVER,[V1]
serout PORTA.3,6,["V1 = ",#V1,10]
goto OVER

'When I send "50 why do I receive "v1 = 53"? I also get "v1 = 53" from "51"? I am missing something?

Thanks to anyone that can help!

HenrikOlsson
- 30th September 2015, 06:34
Hi,
Yes, you're missing somehing....
You get V1=53 because you're sending a string of two ASCII characters from the PC, a "five" and a "zero". You're telling the PIC to receive ONE byte, it grabs the first one, the "five" which happens to be ASCII code 53. Try sending 60 and you'll get 54 because 54 is the ASCII code for "six" or 93 and you'll get 57 because 57 is the ASCII code for "nine".

If you're sending decimal numbers as ASCII strings then tell SERIN you're doing just that

SERIN2 PORTB.0,16468,3000,OVER,[DEC V1]


BTW, please use code tags when posting code, it gets so much easier to read.

/Henrik.

n0yox
- 30th September 2015, 15:19
Thank you very much for your help. I added the DEC modifier and now receive nothing back when I send "50". So after a little reading I tried DEC2 and that seems to work. I really appreciate your help!

Thanks again!

HenrikOlsson
- 30th September 2015, 16:54
It depends on "how" you send it.
If you use the DEC it will grab as many digitis as you send provided you end the string with a non numeric character (like a character or, LF or CR), if you don't it doesn't know when to stop and will sit there waiting. If you ALWAYS send exactly two digits then DEC2 is the best aproach.

/Henrik.

n0yox
- 30th September 2015, 20:14
Thank You, That explains another problem I am having! Again,I really appreciate your help!

Thanks!