PDA

View Full Version : Using HSEROUT to send decimal string



mel4853
- 18th January 2013, 02:18
I'm trying to send a string of 9 bytes out in decimal form see code below. I don't know if I can do the decimal string.Using PBP3 and a 16F690



define OSC 4

'-----------------------Enable EUSART------------------------------------

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 51 ' 4800 Baud @ 4MHz, 0.17%
SPBRGH = 0
BAUDCTL.3 = 1 ' Enable 16 bit baudrate generator

'-----------------------REGISTERS----------------------------------------

TRISA=%001000 ' RA0,RA3,RA4,RA5 inputs
ANSEL=%00000000 ' All digital
ANSELH=$0000 ' AN11, rest digital
TRISB=$00 ' All pins output
TRISC=%00000000 ' RC5 input
CM1CON0.7=0 ' Shut off comparators
CM2CON0.7=0 ' Shut off comparators
OPTION_REG.7=0
WPUA=%001000 ' Weak Pull Ups Enabled

track var PORTA.3

rottime var byte[9]
rot1time var rottime[0]
rot2time var rottime[1]
rot3time var rottime[2]
rot4time var rottime[3]
rot5time var rottime[4]
rot6time var rottime[5]
rot7time var rottime[6]
rot8time var rottime[7]
rot9time var rottime[8]
rot10time var rottime[9]

Main:
if track=0 then
rot1time=1
rot2time=2
rot3time=3
rot4time=4
rot5time=5
rot6time=6
rot7time=7
rot8time=8
rot9time=9
rot10time=10
hserout [str rottime\9,13,10]
pause 500
endif
goto main

Normnet
- 18th January 2013, 06:25
I'm trying to send a string of 9 bytes out in decimal form see code below. I don't know if I can do the decimal string.Using PBP3 and a 16F690


Try:


FOR i = 0 TO 8
HSEROUT [rottime[i]]
NEXT
HSEROUT [rottime[9],10]
Norm

HenrikOlsson
- 18th January 2013, 06:32
If the array is already containing the ASCII code for the character you want to send then that will work but by your description and code it sounds like the array can contain values from 0-255 and that it is the decimal representation of those values you want to send - as ASCII?

Ie. if the array contains the value 65 it's '65' you want to see on your terminal - not 'A' which is the ASCII character for the decimal value 65.

Perhaps what you're looking for is more in the line of:

Main:
if track=0 then
rot1time=1
rot2time=2
rot3time=3
rot4time=4
rot5time=5
rot6time=6
rot7time=7
rot8time=8
rot9time=9
rot10time=10

FOR i = 0 to 0
hserout [DEC rottime[i]]
NEXT
HSEROUT[10,13]

pause 500
endif

/Henrik.