PIC16F877A - UART Registers
Registers used for Serial Communication TXSTA
- RCSTA (Receive Status And Control Register)
- SPBRG (USART Baud Rate Generator)
- TXREG (USART Transmit Register)
- RCREG (USART Receiver Register)
TXSTA (Transmit Status And Control Register)
This register is used to configure the Serial communication for TX.

CSRC: Clock Source Select bit (Asynchronous mode: Don’t care).
TX9: 9-bit Transmit Enable bit
1 = Selects 9-bit transmission
0 = Selects 8-bit transmission
TXEN: Transmit Enable bit
1 = Transmit enabled
0 = Transmit disabled
SYNC: USART Mode Select bit
1 = Synchronous mode
0 = Asynchronous mode
BRGH: High Baud Rate Select bit
1 = High speed
0 = Low speed
TRMT: Transmit Shift Register Status bit
1 = TSR empty
0 = TSR full
TX9D: 9th bit of Transmit Data, can be a Parity bit
RCSTA (Receive Status And Control Register)
Register is used to configure the Serial communication for RX.

SPEN: Serial Port Enable bit
1 = Serial port enabled (configures RC7/RX/DT and RC6/TX/CK pins as serial port pins)
0 = Serial port disabled
RX9: 9-bit Receive Enable bit
1 = Selects 9-bit reception
0 = Selects 8-bit reception
SREN: Single Receive Enable bit (Asynchronous mode: Don’t care)
CREN: Continuous Receive Enable bit
Asynchronous mode:
1 = Enables continuous receive
0 = Disables continuous receive
ADDEN: Address Detect Enable bit
Asynchronous mode 9-bit (RX9 = 1):
1 = Enables address detection, enables interrupt and load of the receive buffer when RSR is set
0 = Disables address detection, all bytes are received and the ninth bit can be used as a parity bit
FERR: Framing Error bit
1 = Framing error (can be updated by reading RCREG register and receive next valid byte)
0 = No framing error
OERR: Overrun Error bit
1 = Overrun error (can be cleared by clearing bit CREN)
0 = No overrun error
RX9D: 9th bit of Received Data (can be parity bit but must be calculated by user firmware)
SPBRG (USART Baud Rate Generator)
The main criteria for UART communication are its baud rate. Both the devices Rx/Tx should be set to the same baud rate for successful communication. This can be achieved by the SPBRG register. SPBRG is an 8-bit register that controls the baud rate generation. The SPBRG register controls the period of a free-running 8-bit timer. In Asynchronous mode, bit BRGH (TXSTA<2>) also controls the baud rate. In Synchronous mode, bit BRGH is ignored.
Given the desired baud rate and FOSC, the nearest integer value for the SPBRG register can be calculated using the below formula.

Calculation:
My Fosc = 11.0592MHz (You can put your board Fosc)
Baud Rate = 9600
9600 = 11059200 / ( 64X + 64)
64X+64 = 1152
X = 17.
If you want to generate 9600 Baudrate (Fosc = 11.0592MHz) you have to set 17 to SPBRG Register.
TXREG (USART Transmit Register)
This is like a transmit buffer. But it is only an 8-bit register. So we have to place the character whatever we want to transmit via USART.
RCREG (USART Receiver Register)
This is like a receiver buffer. But it is only an 8-bit register. So we can take the character whatever we microcontroller received via USART.
My Fosc = 11.0592MHz (You can put your board Fosc)
Baud Rate = 9600
9600 = 11059200 / ( 64X + 64)
64X+64 = 1152
X = 17.
If you want to generate 9600 Baudrate (Fosc = 11.0592MHz) you have to set 17 to SPBRG Register.
TXREG (USART Transmit Register)
This is like a transmit buffer. But it is only an 8-bit register. So we have to place the character whatever we want to transmit via USART.
RCREG (USART Receiver Register)
This is like a receiver buffer. But it is only an 8-bit register. So we can take the character whatever we microcontroller received via USART.
Comments
Post a Comment