PDA

View Full Version : HSERIN/OUT Dec to HEX convertion problem..



N6VMO_
- 26th July 2010, 17:52
Hello,

My project uses a 16F627 to poll a Thunderbolt GPS Disapplined Oscillator for status via its
RS232 port. The TBolt GPS data packets are transmitted in decimal words. Unfortuantely, this
causes problems for most terminal displays will display these decimal numbers as ASCII and
ASCII special characters (Bell, SOH and some unknown, etc). I would like to make the conversion
using HSERIN and HSEROUT if possible.

With all the knowledge on this forum, someone will undoutedly point out my problem. :)

Thank you,

John N6VMO

Here is my theory test code:

INCLUDE "BS2DEFS.BAS"

DEFINE HSER_TXSTA 24H
DEFINE HSER_RCSTA 90H
DEFINE HSER_BAUD 9600
define HSER_SPBRG 25

char Var BYTE ' Storage for serial character
cnt Var Byte ' Storage for character counter

TRISB = %11001111 ' Set PORTB.4,5 to outputs
PORTB = 0 ' Turn off LEDs
cnt = 0 ' Zero character counter

mainloop:
Hserin [dec char] ' Get a char from serial port
Hserout [hex char] ' Send char out serial port
'Debug status
cnt = cnt + 1 ' Increment
PORTB = cnt << 4 ' Send count to LED
Goto mainloop ' Do it all over again

End

aerostar
- 26th July 2010, 19:14
If I understand correctly that each input character is in the range of zero to 9, then just add 48 to the outgoing character, this gives the correct ascii character to display on your terminal. so try:

You get 7 = Bell, add 48 = 55 = 7 see link below

http://www.asciitable.com/


HSERIN char
HSEROUT char+32

N6VMO_
- 26th July 2010, 19:57
If I understand correctly that each input character is in the range of zero to 9, then just add 48 to the outgoing character, this gives the correct ascii character to display on your terminal. so try:

You get 7 = Bell, add 48 = 55 = 7 see link below

http://www.asciitable.com/


HSERIN char
HSEROUT char+32

Hi, I am receiving ASCII data bytes anywhere from 0 to 255. The results can display any
ASCII character and Extended ASCII character from 0 to 255. Example: 142 172 2 16....I need to
convert them into 8E AC 02 10...

aerostar
- 26th July 2010, 21:48
Not sure why you have dec on hserin, have you tried it with just HSERIN CHAR ?, other line stays the same