Hi guys, this is not a 100% PIC/Hardware question, it's more of a doubt in how to efficiently send commands to a PIC through the serial interface.
My first approach, which I'm NOT happy with it, is to use a two bytes array like this :
As you can see, I save two byte read from serial into receive_buffer[2], and use it in the COMMAND-DATA form.
Like most of my codes, this started just to control a servo from serial, but now I attached a LCD also, and also want to write some info on it, like CPU temp, Wireless signal strength and so on.
I soon realized that wasn't the way of doing it, so how do you guys do it ?
Thanks in advance.
My first approach, which I'm NOT happy with it, is to use a two bytes array like this :
Code:
volatile unsigned char receive_buffer[2];
volatile unsigned char *p_receive_buffer = receive_buffer;
volatile unsigned char char_count = 0;
void serialinterrupt_handler(void) {
RCIF = 0;
*p_receive_buffer = (unsigned char)RCREG;
p_receive_buffer++;
char_count++;
}
void clear_receive_buffer(void) {
p_receive_buffer = receive_buffer;
*p_receive_buffer = '\0';
p_receive_buffer++;
*p_receive_buffer = '\0';
p_receive_buffer = receive_buffer;
char_count = 0;
}
unsigned char get_char_count(void) {
return(char_count);
}
unsigned char get_command(void) {
return(receive_buffer[0]);
}
unsigned char get_command_data(void) {
return(receive_buffer[1]);
}
As you can see, I save two byte read from serial into receive_buffer[2], and use it in the COMMAND-DATA form.
Like most of my codes, this started just to control a servo from serial, but now I attached a LCD also, and also want to write some info on it, like CPU temp, Wireless signal strength and so on.
I soon realized that wasn't the way of doing it, so how do you guys do it ?
Thanks in advance.