Serial Port Complete - Latest Microcontroller projects

(lily) #1
Ports for Embedded Systems

 The OpenUSART function enables the receive interrupt by setting the second
parameter to USART_RX_INT_ON:
OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,
77);
Another way to enable the serial-port receive interrupt is to set the bit directly:
PIE1bits.RCIE = 1;
If not using interrupt priority (IPEN = 0), set these bits:
// Disable using interrupt priority.


RCONbits.IPEN = 0;

// Enable all unmasked interrupts.

INTCONbits.GIE = 1;

// Enable all unmasked peripheral interrupts.

INTCONbits.PEIE = 1;
If using interrupt priority (IPEN = 1) and the serial interrupt is high priority,
set these bits:
// Enable using interrupt priority.

RCONbits.IPEN = 1;

// Configure the receive interrupt as high priority.

IPIR1bits.RCIP = 1;

// Enable all high-priority interrupts.

INTCONbits.GIEH = 1;
Free download pdf