317
void initialize_uart(void) { TRISC6 = 0; // TX pin as output TRISC7 = 1; // RX pin as input SPBRG = 129; // Baud rate set for 9600 with 20MHz crystal BRGH = 1; // High-speed baud rate SYNC = 0; // Asynchronous mode SPEN = 1; // Enable serial port TXEN = 1; // Enable transmission CREN = 1; // Enable reception } void uart_send_byte(uint8_t data) { while (!TXIF); // Wait for transmit buffer to be empty TXREG = data; // Send the byte } void uart_send_string(const char* str) { while (*str) { uart_send_byte(*str++); } }