K33rg4t3
Full Member level 3
Hey!
I am creating RS232 communication on PIC16F628A.
I am able to send a string to the computer and receive it in hyper terminal.
But I am haveing troubles with doing "Echo" application. It looks like Uart1_Data_Ready() is always returning true, and my PIC is spamming empty "Letter received" messages to PC.
Here is my code:
The problem is that I am getting "Letter: " messages all the time in the PC. Please help.
I am creating RS232 communication on PIC16F628A.
I am able to send a string to the computer and receive it in hyper terminal.
But I am haveing troubles with doing "Echo" application. It looks like Uart1_Data_Ready() is always returning true, and my PIC is spamming empty "Letter received" messages to PC.
Here is my code:
Code:
void main() {
int count;
char buff[64];
CMCON = 7; // Disable Comparators
UART1_Init(9600); // Baud Rate 9600
Delay_ms(100);
TRISA = 0;
TRISB = 0;
count = 0;
while(1) {
// every some time send the string
if(count >= 255) {
UART1_Write_Text(" UART Test Successful! "); // Character Message to be Sent
UART1_Write(10); // Line Feed
UART1_Write(13); // Carriage Return
count = 0;
PORTA ^= 0x7;
}
// if something is received
if(UART1_Data_Ready())
{
// read and reply
int r = UART1_Read();
buff[0] = r;
buff[1] = 0;
UART1_Write_Text("Letter: ");
UART1_Write_Text(buff);
UART1_Write(10); // Line Feed
UART1_Write(13); // Carriage Return
count = 0;
}
count++;
delay_ms(1);
}
}
The problem is that I am getting "Letter: " messages all the time in the PC. Please help.