PIC16F-4-UART-Main-Loop

by Marwen Maghrebi
// Main function
void main()
{
    // Initialize UART and LEDs
    UART_TX_Init();
    LED_Init();
    
    // Buffer to store received data
    char received_data[50];

    while (1) {
        // Transmit prompt message over UART
        UART_Write_Text("Please write your message and press enter \n");
       
        // Blink LED1 to indicate waiting for data
        LED1 = 1;
        __delay_ms(500);
        LED1 = 0;
      
        // Receive data via UART
        UART_Read_Text(received_data, sizeof(received_data));
        
        // Blink LED2 once to indicate data received
        LED2 = 1;
        __delay_ms(500);
        LED2 = 0;
        
        // Transmit received data back over UART with professional formatting
        UART_Write_Text("\r\n");
        UART_Write_Text("*********************************** \r\n");
        UART_Write_Text("Your message is: \n");
        UART_Write_Text(received_data);
        UART_Write_Text("\r\n");
        UART_Write_Text("********************************** \r\n");
    }
}
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00