Try this code. If this doesn't work then connect your modem to PC and send AT from Terminal software. It should give response like >OK. Just post the screenshot of the response you get.
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
| // 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
unsigned char gsm_response[5], i = 0;
void main()
{
PORTB = 0x00;
LATB = 0x00;
ADCON1 = 0x0F; // Configure AN pins as digital
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
Lcd_Out(1,1,"Smart Home..."); // Write text in first row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
LCD_Out(1,1,"Testing com...");
while(1)
{
UART_Write_Text("AT\r\n");
while(gsm_response != ">OK"){
gsm_response[i++] = UART1_Read();
gsm_response[i] = '\0';
}
Lcd_cmd(_LCD_CLEAR);
Lcd_out(1, 1, gsm_response);
Delay_ms(5000);
}
} |