Chapter 11
! "
To use the transmit and received interrupts without using interrupt priority:
- In the PIE1 register, set TXIE = 1 and RCIE = 1.
- In the INTCON register, set GIE = 1 and PIE = 1.
To use the transmit and received interrupts with interrupt priority: - In the RCON register, set IPEN = 1.
- In the PIE1 register, set TXIE = 1 and RCIE = 1.
- In the IPR1 register, set the interrupt priority in RCIP and TXIP as desired.
- In the INTCON register, set GIEH and GIEH to enable interrupts as appro-
priate for the IPR1 settings.
To transmit a byte, firmware performs these tasks:
- To enable transmitting, in the TXSTA register, set TXEN = 1.
- If using hardware flow control, check the state of the firmware-defined
flow-control input bit and wait as needed for permission to transmit. - Write a byte to transmit to TXREG. The byte transfers to the TSR. When
TXREG is empty, in the PIR1 register, TXIF = 1. On the TX pin, the TSR
transmits a Start bit, the byte of data, and a Stop bit.
Firmware can write another byte to TXEN as soon as TXIF = 1. If using inter-
rupts, firmware will jump to the ISR when TXIF = 1.
5
To receive a byte, firmware performs these tasks:
- To enable receiving, in the RCSTA register, set CREN = 1.
- If using hardware flow control, set the firmware-defined flow-control output
bit to enable receiving. - In the PIR1 register, wait for RCIF = 1, indicating the receive buffer contains
as least one byte. If using interrupts, firmware will jump to the ISR when RCIF
= 1. - In the RCSTA register, check the framing error (FERR) and overrun
(OERR) bits. - Read the received byte in RCREG. Reading the register clears RCIF. If FERR
= 1, firmware will likely want to discard the received byte.