Quantcast
Channel: Question and Answer » uart
Viewing all articles
Browse latest Browse all 57

Not able to perform operations based on the data received to MCU through UART?

$
0
0

I have been trying to do a simple operation based on the data byte received by the MCU(pic18F) from the PC terminal through UART. The operation is turning ON an LED depending on the content of the received data byte. So here is the code for the logic:

char data = 0;
unsigned char UARTReadByte()
{
   while(!PIR1bits.RCIF); //Wait until the receive buffer is full 
   return RCREG; //Return received byte 
}

void main()
{
   TRISAbits.TRISA1 = 0
   UARTInit(); //Initialize UART
   LCDInit(); //Initialize LCD
   while(1)
  {
     data = UARTReadByte(); //The received data from the virtual terminal (UART) is stored in another variable char 
     Write_Command(0x80); 
     Write_data(data); //Display the received data on the LCD
     if(data==1)  //check if the data is 1, if 1 turn ON the LED
     PORTAbits.RA0 = 1;
 }
}

The received number is displayed on the LCD, however the LED is not turning ON. I presume the MCU is not able to check and validate the received byte due to issues in the data format. Can anyone help me with solving this problem. Thank you all in advance.


Viewing all articles
Browse latest Browse all 57

Trending Articles