I am working on a project with C18 compiler and PIC18F4520.
I am having trouble using getcUSART. When I send characters over bluetooth module, at one point it would just hang.
int input(char Arr[])
{
Delay10KTCYx(400); // Delay between data transmissions
while(BusyUSART());
// wait for user input
while (!DataRdyUSART());
//get string from terminal
Arr[0] = getcUSART(); //read a byte from USART
Delay10KTCYx(400); // Delay between data transmissions
while(BusyUSART());
// wait for user input
while (!DataRdyUSART());
//get string from terminal
Arr[1] = getcUSART(); //read a byte from USART
Delay10KTCYx(400); // Delay between data transmissions
while(BusyUSART());
// wait for user input
while (!DataRdyUSART());
//get string from terminal
Arr[2] = getcUSART(); //read a byte from USART
Delay10KTCYx(400); // Delay between data transmissions
return 1;
}
Here is my code for when I am receiving characters from the terminal. The issue is that I'd like to be able the user to choose an option, such as RUN or SET, but then if it is any other option, it should ask the user for input again. The problem is that if I for example put POP in the terminal, it will indeed ask for the user to enter again, but then if I type RUN or SET, it will still think that it is not a command. Furthermore, If I type RUNbre for example, the bre will be read LATER when im using getcUSART again. I want to somehow be able to clear the buffer that determines what goes into getcUSART, but I don't know how to do that.
Any help would be appreciated, thank you.