// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;// End LCD module connectionschar i;int row=1,col=1;void main(){
uart1_init(115200);
delay_ms(1000);
Lcd_Init();
delay_ms(200);// Initialize LCD
Lcd_Cmd(_LCD_CLEAR);// Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);// Cursor off
Lcd_Cmd(_LCD_UNDERLINE_ON);//Underline fashion cursor
Lcd_Out(1,2,"LCD/UART TEST");
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);//Lcd_Cmd(_LCD_CLEAR);
delay_ms(5000);
uart1_write_text("AT");
uart1_write(0x0d);
uart1_write(0x0a);
delay_ms(2000);
uart1_write_text("AT+CMGF=1");
uart1_write(0x0d);
uart1_write(0x0a);
delay_ms(200);
uart1_write_text("AT+CMGR=1");
uart1_write(0x0d);
uart1_write(0x0a);
delay_ms(200);while(1){if(UART1_Data_Ready()==1){//If Data Ready,
i=UART1_Read();//Read it and store in variable i
Lcd_Chr(row,col,i);//Print it in co-ordinates specifiedif(i==27){//If ESC is pressed, clear display
Lcd_Cmd(_LCD_CLEAR);
col=1,row=1;}
col=col+1;}if(col==17&& row==1){//On end of row, goto second row
row=2;
col=1;}if(row==2&& col==17){//On end of display, clear display
Lcd_Cmd(_LCD_CLEAR);
col=1;
row=1;}}}
In any GSM application, UART should be used in interrupt mode, because whenever you apply SMS read command to GSM module, it immediately send SMS message as whole. So you must use Uart in interrupt mode.
If you want to use UART in polling mode, you should use Hardware flow control.