UART / USART in PIC Microcontroller
UART / USART in PIC Microcontroller
UART / USART in PIC Microcontroller
Bit TXEN (bit 5) on TXSTA enables or disables transmission, SYNC ( bit 4) sets asynchronous
or synchronous mode while BRGH (bit 2) sets high speed or low speed mode.
The formula used to compute for the baud rate is different in high speed or low speed mode:
Here, X is the contents of the register SPBRG. So, for example, a baud rate of 9600 using
a 4 MHz oscillator at high speed and asynchronous mode will have SPBRG = 25 as
shown:
TRMT (bit 1) is a flag that sets if the data has been sent.
SPEN (bit 7) of the RCSTA register enables RC6 and RC7 as serial port pins. This is the
bit you need to set to enable serial communication.
The data to be transmitted must be placed inside the TXREG register while the data
received is placed inside the RCREG register.
Example program for UART in PIC Microcontroller