Sorry for bothering, below is part of coding from PR16(Sending Data Using RF Module) and can someone explain to me the logic this code detailly ,thank you ^^
unsigned char read_packet(void)
{
unsigned char received_byte; // Buffer for received byte.
static unsigned char counter = 0; // Counter to indicate the current position of the received data packet.
unsigned char data; // Buffers for the data and checksum.
unsigned char checksum;
do {
// We will ignore the sync data and assume the header byte is the start of packet.
// Keep reading until the header byte is received.
while (uart_rec() != HEADER);
// The following byte shoulde be the data byte.
data = uart_rec();
// Then the last byte is the checksum.
checksum = uart_rec();
} while (checksum != (unsigned char)(HEADER + data));
// If the checksum is correct, return the data.
return data;
}