Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

2009-2013 Microchip Technology Inc. DS70000582E-page 25
UART
Example 7-1: UART1 Receive Only with Polling (Interrupts Disabled)
#define FP 40000000
#define BAUDRATE 9600
#define BRGVAL ((FP/BAUD RATE)/16) - 1
int main(void)
{
// Configure oscillator as needed
.
.
.
// Configure oscillator as needed
U1MODEbits.STSEL = 0; // 1-stop bit
U1MODEbits.PDSEL = 0; // No Parity, 8-data bits
U1MODEbits.ABAUD = 0; // Auto-Baud disabled
U1MODEbits.BRGH = 0; // Standard-Speed mode
U1BRG = BRGVAL; // Baud Rate setting for 9600
U1STAbits.URXISEL = 0; // Interrupt after one RX character is received;
U1MODEbits.UARTEN = 1; // Enable UART
while(1)
{
char ReceivedChar;
/* Check for receive errors */
if(U1STAbits.FERR == 1)
{
continue;
}
/* Must clear the overrun error to keep UART receiving */
if(U1STAbits.OERR == 1)
{
U1STAbits.OERR = 0;
continue;
}
/* Get the data */
if(U1STAbits.URXDA == 1)
{
ReceivedChar = U1RXREG;
}
}

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh