bbgil
Full Member level 2
lcd_cmd(130)
GUys, i want to convert received data from USART to control individual ports in PIC. i used the library functions in MikroC. the problem is how make the PIC read the individual data to compare them to the PIC char and then control their function. in this code, just simply turn on LED on porta bit 0 and bit1. really need to make this work. thanks in advance
unsigned short pos, i;
char lcdtext [41];
char *tc1 ="on";
char *tc2 ="ot";
void main (){
TRISA =0;
PORTA =0;
Usart_Init (9600);
Lcd_Init (&PORTB);
i=0;
while (1)
{
if(Usart_Data_Ready ())
{
lcdtext = Usart_Read ();
i++;
if (i==2)
{
i=0;
Lcd_Cmd (LCD_RETURN_HOME);
for (pos=0;pos<40;pos++ )
{
Lcd_Chr_CP (lcdtext[pos]);
if (lcdtext == tc1) portA.f0 = 1;
if (lcdtext == tc1) portA.f1 = 1;
if (pos==16) Lcd_Cmd (LCD_SECOND_ROW);
}
Usart_Write('Y');
}
}
}
}
Added after 1 hours 41 minutes:
i think i need to create a buffer register to contain all the receive data from USART then compare it to my text character. But how to do this in MikroC? need help
GUys, i want to convert received data from USART to control individual ports in PIC. i used the library functions in MikroC. the problem is how make the PIC read the individual data to compare them to the PIC char and then control their function. in this code, just simply turn on LED on porta bit 0 and bit1. really need to make this work. thanks in advance
unsigned short pos, i;
char lcdtext [41];
char *tc1 ="on";
char *tc2 ="ot";
void main (){
TRISA =0;
PORTA =0;
Usart_Init (9600);
Lcd_Init (&PORTB);
i=0;
while (1)
{
if(Usart_Data_Ready ())
{
lcdtext = Usart_Read ();
i++;
if (i==2)
{
i=0;
Lcd_Cmd (LCD_RETURN_HOME);
for (pos=0;pos<40;pos++ )
{
Lcd_Chr_CP (lcdtext[pos]);
if (lcdtext == tc1) portA.f0 = 1;
if (lcdtext == tc1) portA.f1 = 1;
if (pos==16) Lcd_Cmd (LCD_SECOND_ROW);
}
Usart_Write('Y');
}
}
}
}
Added after 1 hours 41 minutes:
i think i need to create a buffer register to contain all the receive data from USART then compare it to my text character. But how to do this in MikroC? need help