sathiieesh
Newbie level 5
Hi iam attaching a code which works perfectly when i interface PIC Microcontroller with PC hyperterminal to send and receive messages... But it doesnt give any output when i connect PIC with GSM Modem... The Hardware connections is also right... when i try to send sms from PIC it works perfectly... the problem in reading the message in Sim memory.. what might be the problem... check this code ....
Code:
void sms_read();
void sms_send();
char output[70];
void main() {
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
sms_read();
}
void sms_read()
{
UART1_Write_Text("AT\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGF=1\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGR=1\n\r");
delay_ms(500);
while (1) {
if (UART1_Data_Ready() == 1) { // if data is received
UART1_Read_Text(output, "OK", 80); // reads text until 'OK' is found
/*UART1_Write_Text(output); // sends back text
delay_ms(500);
UART1_Write_Text("\n");
delay_ms(500); */
sms_send();
}
}
}
void sms_send()
{
int i;
/*UART1_Write_Text("AT\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGF=1\n\r");
delay_ms(500); */
UART1_Write_Text("AT+CMGS=");
UART1_Write(0x22);
UART1_Write_Text("+919444721638");
UART1_Write(0x22);
UART1_Write_Text("\n\r");
delay_ms(500);
UART1_Write_Text(output);
UART1_Write(26);// send ctrl + Z
}