Hello,
I have been having problems with the HSERIN instruction on a 16F88 and after too many hours on Google I hope someone can help me.
I have written a program that will take serial data and output it to an LCD. The program works at 1200 baud but doesn't work at any speed above this. Ideally I would like the baud rate to be 9600 but 1200 is too slow.
Here is my code:
Code:
'-------------------------------------
' STARTUP CODE
'-------------------------------------
@ DEVICE PIC16F88,XT_OSC
@ DEVICE PIC16F88,PROTECT_OFF
@ DEVICE PIC16F88,WDT_OFF
@ DEVICE PIC16F88,PWRT_ON
@ DEVICE PIC16F88,MCLR_ON
@ DEVICE PIC16F88,BOD_OFF
@ DEVICE PIC16F88,LVP_OFF
@ DEVICE PIC16F88,CPD_OFF
@ DEVICE PIC16F88,DEBUG_OFF
@ DEVICE PIC16F88,CCPMX_OFF
' *THIS SPEED DOESN'T WORK??
'DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
'DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
'DEFINE HSER_SPBRG 25 ' 9600 Baud @ 0.16%
'DEFINE HSER_CLROERR 1 ' Clear overflow automatically
' *THIS SPEED DOES WORK
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 51 ' 1200 Baud @ 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'Define the LCD
Define LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
'DEFINE LCD_COMMANDUS 1500
'DEFINE LCD_DATAUS 44
'Register setup
ADCON1 = %00000111 ' Disable A/D converter
ANSEL = %00000000 ' all analog pins to digital
CCP1CON = %00000000 ' Disable CCP Module
CMCON = %00000111 ' Turn off comparator
INTCON = %00000000 ' Interrupts disabled
'Clear the ports
TRISA = %00000000 'All O/P's
TRISB = %00001101 'All O/P's
PORTA = 0 'Zero PortA O/P's
PORTB = 0 'Zero PortB O/P's
'Var for RS232 data
RxData var byte
'-------------------------------------
' SPLASH SCREEN
'-------------------------------------
SplashScreen:
pause 60 'Power up delay
'Display a splash screen for 2 seconds
LCDOUT $FE,1,"RS232 to LCD"
LCDOUT $FE,$C0,"Display Test"
pause 2000
'Now ready for COMMS...
LCDOUT $FE,1,"Waiting for PC"
LCDOUT $FE,$C0,"to send data..."
'-------------------------------------
' RS232 TO LCD
'-------------------------------------
Main:
high PORTB.7 'This is just a test for diagnostics
hserin [RxData] 'Get the RS232 Data
low PORTB.7 'This is just a test for diagnostics
lcdout RxData 'Output the data to the LCD
goto Main 'Loop forever
I have looked at the RS232/LCD data with a digital logic probe and I have attached 2 screen shots from this. One shows 1200 baud and the other 9600 baud. At 1200 baud the timing looks ok but at 9600 it looks like there is not enought time to send the LCD data before another byte of data comes in.
Does anyone have any ideas how to resolve this issue?
Thanks,
robbrownuk
Bookmarks