No expert, but these are things I look at when having issues with serial coms.
Timing: The crystal and OSC value need to be right. On one project the code ran and the program functioned, but when communications was tested I got garbage streamed out to the PC. I then changed the xtal from 12mhz to a 10mhz and it worked fine.
Try something like this with a 10mhz crystal fitted
Code:
DEFINE OSC 20 ' 18F4520, 10mhz crystal
ADCON1 = $0F
clear
;----[UART Settings]------------------------------------------------------------
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 8 ' 9600 Baud @ SPBRGH = 2
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 8 ' 9600 Baud @ -0.03%
SPBRGH = 2
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
RCIF VAR PIR1.5 ' USART receive flag
Char VAR BYTE ' USART byte received
GIE VAR INTCON.7
Then try your HSEROUT routine
There was a useful calculator that worked out the settings based on the timings which might help http://www.picbasic.co.uk/forum/showthread.php?t=4994
Bookmarks