// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATD4_bit;
sbit LCD_D5 at LATD5_bit;
sbit LCD_D6 at LATD6_bit;
sbit LCD_D7 at LATD7_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_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 connections
char gsm_response[20];
void gsm_send_command(char *command)
{
while(*command)
{
uart1_write(*command++);
}
uart1_write(13);
uart1_write(10);
}
void gsm_read_line(char *buffer)
{
char uart_rd;
do
{ // Endless loop
if(UART1_Data_Ready()){
uart_rd = UART1_Read(); // read the received data,
*buffer++=uart_rd; }
} while (uart_rd != '\r\n');
}
void main()
{
ADCON1 = 0x0F;
CMCON=0; // comparator off
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(200); // Wait for UART module to stabilize
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
gsm_send_command("AT");
gsm_read_line(gsm_response);
if(memcmp("OK",gsm_response,2)!=0)
{
lcd_cmd(_lcd_clear);
lcd_out(1,1,"Error AT...");
while(1);
}
Lcd_cmd(_Lcd_clear);
Lcd_out(1,1,"FINE1");
lcd_OUT(2,1,GSM_RESPONSE);
gsm_send_command("AT+CMGF=1");
gsm_read_line(gsm_response);
if(memcmp("OK",gsm_response,2)!=0)
{
lcd_cmd(_lcd_clear);
lcd_out(1,1,"Error TEXT");
while(1);
}
Lcd_cmd(_Lcd_clear);
Lcd_out(1,1,"FINE2");
lcd_OUT(2,1,GSM_RESPONSE);
}