uart received data decoding in pic microcontroller

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
ayman morsy
Posts: 6
Joined: 12 Apr 2020 18:31

uart received data decoding in pic microcontroller

#1 Post by ayman morsy » 17 May 2020 10:12

I hope you are all well and have a good day. I am interfacing an HMI TFT screen with pic 16F877A, and this screen has a protocol to send and receive data. I want to decode the received data to read the required information without any extra values. I have thought about saving the received data by making an array and save data in it, and take the required byte that I want to read. this is the protocol of the TFT, and below is the designed code. AA 78 00 01 0F CC 33 C3 3C (I want to read the part of (0F) only)

Code: Select all

int uart_rd;  //UART read variable
typedef unsigned char INT8U;
typedef unsigned long INT32U;

void Read_Bytes(INT8U *str, INT32U Num) {
    INT32U i;
    for (i=0; i< Num; i++){
    str[i++] = UART1_Read();
    }
    }

void main() {
while (1) {          // Endless loop
UART1_Init(115200);  //Uart baud at 115200
 if (UART1_Data_Ready() == 1) {
Read_Bytes(str_read, 9);
uart_rd = str_read[3];
 if (uart_rd == 0x0F){
 PORTB.B2 = 1;
                  }
 else {
 PORTB.B2 = 0;
                        }
                             }

Post Reply

Return to “mikroC PRO for PIC General”