Bonjour,
Depending how you want to use the USART, the initialization setup will be different. Let's say you want to read/write from the PIC USART register (RCREG/TXREG) yourself, your setup above is almost what you need but not not 100% exact. for a 9600 baud @4MHZ, the setup will be
Code:
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 25 ' 9600 Baud @ 4MHz, 0.16%
But more than often we want to use the power of a PBP built-in command, hence HSERIN/HSEROUT. In that case the right setup will be.
Code:
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25 ' 9600 Baud @ 4MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
This also assume you're going to use the PIC dedicated I/Os (TX/RX)
I would suggest you to download and use my PicMultiCalc, yeah i know i sound like a broken record but... agreed it's an handy tool.
http://www.mister-e.org/pages/utilitiespag.html
Bonne chance!
Bookmarks