The following steps outline the transmission process:
- 1.Configure the UxBRGH:UxBRGL register
pair and BRGS bit to achieve the desired baud rate.
- 2.Set the MODE<3:0> bits of
UxCON0 to the desired operation mode.
- 3.Set the TXPOL bit of UxCON2 if an
inverted TX output is desired.
- 4.Load the RxyPPS register with the
code associated with the TX output.
- 5.Clear the TRIS bit for the TX
pin.
- 6.If UART interrupts are desired, set
the appropriate interrupt enable bits, clear the associated interrupt flag bits, and
enable the global interrupts.
- 7.Enable the UART module by setting the
ON bit of UxCON1.
- 8.Set the TXEN bit of UxCON0 to enable
the transmitter.
- 9.Check the UxTXIF bit to ensure the
UxTXB is clear before writing.
- 10.When ready to begin transmission,
write one byte of data to UxTXB.
- 11.Repeat steps 9 and 10 until all the
data has been transmitted.
UART Transmit Mode Initialization for PIC18(L)FXXK42 shows the UART initialization sequence when operating in
Transmit mode.
UART Transmit Mode Initialization
for PIC18(L)FXXK42
void UART1_Initialize(void)
{
U1CON0 = 0x80; // BRGS normal; 8-bit mode; ABDEN disabled;
U1CON1 = 0x80; // ON enabled;
U1CON2 = 0x00; // TXPOL not inverted; FLO off;
U1BRGL = 0x19; // BRGL 25 = 9600 BR @ 1 MHz FOSC
U1BRGH = 0x00;
U1FIFO = 0x00; // STPMD in middle of first Stop bit;
U1UIR = 0x00; // Auto-baud not enabled
U1ERRIR = 0x00;
U1ERRIE = 0x00;
U1CON0bits.TXEN = 1; // Enable the transmitter
}