so it isn't nothing new but i just cant understand where i making a mistake, try to catch usart data and display it on lcd 2x16, but sometimes it work sometimes not....any advice...
Code: Select all
int i;
char busdata[15];
void main() {
CM1CON0=0; //'disable COMPARATOR 1.
CM2CON0=0; //'disabl
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
Lcd_Config(&PORTB, 4, 5, 6, 3, 2, 1, 0); // Lcd_Init
LCD_Cmd(LCD_CLEAR); // Clear display
LCD_Cmd(LCD_CURSOR_OFF); // Turn cursor off
LCD_Out(1,1, "Poslani text:"); // Print text to LCD
USART_init(9600); // init USART
i=1;
while(1)
{
while (!Usart_Data_Ready ()) {} // Wait for a byte
if (Usart_Read() == '#') // When we get a #
{
busdata[0]='#'; // Load '#' to busdata Array
// Receive the "real" data
do
{
while (!Usart_Data_Ready ()) {} // Wait for a byte
busdata[i++]= Usart_Read(); // Add character to array
}while(busdata[i]!='\r');// Get to here when <CR> received
}
if (busdata[i]=='\r')
do{
busdata[i++]=' ';
}while (i!=16);
LCD_Out(2,1,busdata);
i=1;
// Delay_ms(200);
// LCD_Cmd(LCD_CLEAR);
// LCD_Out(1,1, "test");
}
}