SlideShare a Scribd company logo
GSM Modem Interfacing with PIC
Microcontroller
Hi to all...
I am doing a project in which i will be interfacing a gsm modem with PIC
microcontroller(16f877).. when i connect the gsm modem with PC i can able to send and
read the messages in the sim using AT commands in hyperterminal...Then i iniatized UART
in PIC send and received data to PC through hyperterminal its working properly...
When i interfaced PIC with GSM Modem i can able to send AT command to GSM modem but
the reply "OK " from GSM modem to PIC is not received by PIC...
Example:
AT (Enter)-----In Hyperterminal
OK ------Message from GSM Modem
Compiler:MikroC
Baud Rate:9600 bps
GSM MOdem:Wavecom HT-W2101
I can able to send AT and Enter command from UART to PIC... But i cant able see the reply
from GSM modem... but it works well when i interface GSM modem with PC hyperterminal...
Help me...
/*Header*****************************************************
Microcontroller=16f877
Clock=10 Mhz
Project Title:Air Pollution Control Using GSM/GPRS
Developed By:Sathiesh Kumar.V
Date:31/01/2010*/
void Calculation(unsigned int ) ;
void Gsm_SMS_Init();
void Gsm_SMS_Read();
void Gsm_SMS_Send();
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
unsigned char ch; //
char Receive;
unsigned int adc_rd; // Declare variables
char *text; //
long tlong; //
unsigned int i,j;
char return_gsm[2];
char Gsm_Receive[100];
char Gsm_Msg[10];
char uart_rd[]="AT";
char uart_rd1[]="AT +CMGF=1";
char uart_rd2[]="AT +CMGR=1" ;
char uart_rd3[]="AT +CMGS=";
char Mobile_No[]="+919444721638" ;
char Send_Msg[]="@ON";
void main()
{
INTCON = 0; // All interrupts disabled
ADCON1 = 0x82; // A/D voltage reference is VCC
TRISA = 0xFF; // All port A pins are configured as inputs
TRISC=0x01;
Delay_ms(2000); // Rest of pins are configured as digital
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
text = "Air Pollution "; // Define the first message
Lcd_Out(1,1,text); // Write the first message in the first line
delay_ms(500);
text = "Sensor Value"; // Define the second message
Lcd_Out(2,1,text); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
text = "GSM"; // Define the third message
while (1)
{
Lcd_Out(1,1,text); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
Gsm_SMS_Init();
}
}
void Gsm_SMS_Init()
{
if (UART1_Tx_Idle() == 1)
{
for(i=0;i<=1;i++)
{
UART1_Write(uart_rd); //AT
}
UART1_Write(0x0D); //Enter
Lcd_Out(2,1,"AT"); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
//delay_ms(5000);
while(1)
{
if (UART1_Data_Ready())
{ // If data is received,
for(i=0;i<=1;i++)
{
return_gsm = UART1_Read(); // read the received data, Received OK
}
Lcd_Out(2,1,"OK"); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
/* UART1_Write(return_gsm[0]);
Lcd_Out(2,1,"OK RESEND"); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR); */
// UART1_Write(return_gsm[1]);
}
}
/*if(return_gsm[0]==0x4F && return_gsm[1]==0x4B)
{
if (UART1_Tx_Idle() == 1)
{
for(i=0;i<=8;i++)
{
UART1_Write(uart_rd1); //AT+CMGF=1
}
UART1_Write(0x0D); //Enter
Lcd_Out(1,1,"AT+CMGF=1");
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
}
if (UART1_Data_Ready())
{ // If data is received,
for(i=0;i<=1;i++)
{
return_gsm = UART1_Read(); // read the received data,OK
}
Lcd_Out(2,1,"Received OK");
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
}
} */
}
}
Code (text):
/*Header*****************************************************
Microcontroller=16f877
Clock=10 Mhz
Project Title:Air Pollution Control Using GSM/GPRS
Developed By:Sathiesh Kumar.V
Date:31/01/2010*/
void Calculation(unsigned int ) ;
void Gsm_SMS_Init();
void Gsm_SMS_Read();
void Gsm_SMS_Send();
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
unsigned char ch; //
char Receive;
unsigned int adc_rd; // Declare variables
char *text; //
long tlong; //
unsigned int i,j;
char return_gsm[2];
char Gsm_Receive[100];
char Gsm_Msg[10];
char uart_rd[]="AT";
char uart_rd1[]="AT+CMGF=1";
char uart_rd2[]="AT+CMGR=1" ;
char uart_rd3[]="AT+CMGS=";
char Mobile_No[]="+919444721638" ;
char Send_Msg[]="@ON";
void main()
{
INTCON = 0; // All interrupts disabled
ADCON1 = 0x82; // A/D voltage reference is VCC
TRISA = 0xFF; // All port A pins are configured as inputs
TRISC=0x80;
Delay_ms(2000); // Rest of pins are configured as digital
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
text = "Air Pollution "; // Define the first message
Lcd_Out(1,1,text); // Write the first message in the first line
delay_ms(500);
text = "Sensor Value"; // Define the second message
Lcd_Out(2,1,text); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
text = "GSM"; // Define the third message
while (1)
{
Lcd_Out(1,1,text); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
Gsm_SMS_Init();
}
}
void Gsm_SMS_Init()
{
if (UART1_Tx_Idle() == 1)
{
Lcd_Out(2,1,"AT"); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
for(i=0;i<=1;i++)
{
UART1_Write(uart_rd[i]); //AT
}
UART1_Write(0x0D); //Enter
//delay_ms(5000);
while(1)
{
Lcd_Out(2,1,"In while"); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
if (UART1_Data_Ready())
{ // If data is received,
Lcd_Out(2,1,"In IF"); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
for(i=0;i<=1;i++)
{
return_gsm[i] = UART1_Read(); // read the received data, Received
OK
}
Lcd_Out(2,1,"OK"); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
/* UART1_Write(return_gsm[0]);
Lcd_Out(2,1,"OK RESEND"); // Define the first message
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR); */
// UART1_Write(return_gsm[1]);
}
}
/*if(return_gsm[0]==0x4F && return_gsm[1]==0x4B)
{
if (UART1_Tx_Idle() == 1)
{
for(i=0;i<=8;i++)
{
UART1_Write(uart_rd1[i]); //AT+CMGF=1
}
UART1_Write(0x0D); //Enter
Lcd_Out(1,1,"AT+CMGF=1");
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
}
if (UART1_Data_Ready())
{ // If data is received,
for(i=0;i<=1;i++)
{
return_gsm[i] = UART1_Read(); // read the received data,OK
}
Lcd_Out(2,1,"Received OK");
delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
}
} */
}
}
Code (text):
void sms_send();
void sms_del();
void sms_read();
char sms[11];
char output[65];
unsigned char* MSG4 = "AT+CNMI=2,1,0,0,0";
void main() {
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
// sms_del();
sms_read();
}
void sms_send()
{
int i;
/*UART1_Write_Text("ATnr");
delay_ms(500);
UART1_Write_Text("AT+CMGF=1nr");
delay_ms(500); */
UART1_Write_Text("AT+CMGS=");
UART1_Write(0x22);
UART1_Write_Text("+919444721638");
UART1_Write(0x22);
UART1_Write_Text("nr");
delay_ms(500);
for(i=0;i<64;i++)
{
if(output[i]=='0') break;//ask for null character of sms vector when find it go out
of for() loop
UART1_Write(sms[i]);
}
delay_ms(500);
UART1_Write(26);// send ctrl + Z
return;
}
void sms_del()
{
UART1_Write_Text("AT+CMGD=1nr");
delay_ms(500);
}
void sms_read()
{
int i;
//char sms[11];
UART1_Write_Text("ATnr");
delay_ms(500);
UART1_Write_Text(MSG4); //cpms
Delay_ms(1000);
UART1_Write(0X0D); // ENTER
Delay_ms(1000);
UART1_Write_Text("AT+CMGF=1nr");
delay_ms(500);
UART1_Write_Text("AT+CMGR=7nr");
//delay_ms(500);
while (UART1_Data_Ready() != 1);
UART1_Read_Text(output, "OK", 65); // reads text until 'OK' is found
sms_send();
//return;
}

More Related Content

PDF
IP security and VPN presentation
PDF
200 301-ccna
PPTX
Network interface card
PDF
Planejamento em Inteligência Artificial
PPT
Packet tracer
PPT
Controller area network (CAN bus) ppt
PDF
Operating System fo IoT
PPTX
Routers.ppt
IP security and VPN presentation
200 301-ccna
Network interface card
Planejamento em Inteligência Artificial
Packet tracer
Controller area network (CAN bus) ppt
Operating System fo IoT
Routers.ppt

What's hot (16)

DOCX
Packet tracer practical guide
PPT
LIN protocol description
DOC
Lab 6.4.1 InterVLAN routing
PDF
IOS Zone based Firewall
PPTX
Ca npp t
PPTX
Local Interconnect Network
PPTX
Trace route
PPTX
Ccna PPT
PPTX
Switches on Networking
PPTX
ccna summer training ppt ( Cisco certified network analysis) ppt. by Traun k...
ODP
Control Area Network
PPT
Cisco Packet Tracer Overview
PPTX
Apache Storm - Real Time Analytics
PPTX
Overview of automotive network protocol
PPTX
PPTX
Digital parking system
Packet tracer practical guide
LIN protocol description
Lab 6.4.1 InterVLAN routing
IOS Zone based Firewall
Ca npp t
Local Interconnect Network
Trace route
Ccna PPT
Switches on Networking
ccna summer training ppt ( Cisco certified network analysis) ppt. by Traun k...
Control Area Network
Cisco Packet Tracer Overview
Apache Storm - Real Time Analytics
Overview of automotive network protocol
Digital parking system
Ad

Similar to Gsm modem interfacing with pic microcontroller (20)

DOC
Interface gsm module with pic
PPTX
131080111003 mci
DOCX
Vehicle tracting system
PDF
Combine the keypad and LCD codes in compliance to the following requ.pdf
PDF
CC2500 Wireless Trans-receiver Module
PDF
Product catlog
PPTX
Linux Serial Driver
ODP
Intel Quark HSUART
PDF
Gaztea Tech Robotica 2016
TXT
Atmega lcd programing_with_header_file
PDF
CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)
DOCX
Dam gate open close lpc prog
DOCX
codings related to avr micro controller
PPT
Home automation and securty using wireless networks
PPTX
gsm based Notice board
DOCX
(381877808) 102054282 5-listing-program
TXT
PIC and LCD
PPT
Data Acquisition
PPTX
LCD_Example.pptx
DOCX
m.tech esd lab manual for record
Interface gsm module with pic
131080111003 mci
Vehicle tracting system
Combine the keypad and LCD codes in compliance to the following requ.pdf
CC2500 Wireless Trans-receiver Module
Product catlog
Linux Serial Driver
Intel Quark HSUART
Gaztea Tech Robotica 2016
Atmega lcd programing_with_header_file
CAN interfacing on LPC1768 (ARM Cortex M3 based Micro controller)
Dam gate open close lpc prog
codings related to avr micro controller
Home automation and securty using wireless networks
gsm based Notice board
(381877808) 102054282 5-listing-program
PIC and LCD
Data Acquisition
LCD_Example.pptx
m.tech esd lab manual for record
Ad

Recently uploaded (20)

PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Introduction to Artificial Intelligence
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Transform Your Business with a Software ERP System
PPTX
L1 - Introduction to python Backend.pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Softaken Excel to vCard Converter Software.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction to Artificial Intelligence
Odoo Companies in India – Driving Business Transformation.pdf
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
Design an Analysis of Algorithms I-SECS-1021-03
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Understanding Forklifts - TECH EHS Solution
Internet Downloader Manager (IDM) Crack 6.42 Build 41
CHAPTER 2 - PM Management and IT Context
wealthsignaloriginal-com-DS-text-... (1).pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Transform Your Business with a Software ERP System
L1 - Introduction to python Backend.pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool

Gsm modem interfacing with pic microcontroller

  • 1. GSM Modem Interfacing with PIC Microcontroller Hi to all... I am doing a project in which i will be interfacing a gsm modem with PIC microcontroller(16f877).. when i connect the gsm modem with PC i can able to send and read the messages in the sim using AT commands in hyperterminal...Then i iniatized UART in PIC send and received data to PC through hyperterminal its working properly... When i interfaced PIC with GSM Modem i can able to send AT command to GSM modem but the reply "OK " from GSM modem to PIC is not received by PIC... Example: AT (Enter)-----In Hyperterminal OK ------Message from GSM Modem Compiler:MikroC Baud Rate:9600 bps GSM MOdem:Wavecom HT-W2101 I can able to send AT and Enter command from UART to PIC... But i cant able see the reply from GSM modem... but it works well when i interface GSM modem with PC hyperterminal... Help me... /*Header***************************************************** Microcontroller=16f877 Clock=10 Mhz Project Title:Air Pollution Control Using GSM/GPRS Developed By:Sathiesh Kumar.V Date:31/01/2010*/ void Calculation(unsigned int ) ; void Gsm_SMS_Init(); void Gsm_SMS_Read(); void Gsm_SMS_Send(); // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit;
  • 2. sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections unsigned char ch; // char Receive; unsigned int adc_rd; // Declare variables char *text; // long tlong; // unsigned int i,j; char return_gsm[2]; char Gsm_Receive[100]; char Gsm_Msg[10]; char uart_rd[]="AT"; char uart_rd1[]="AT +CMGF=1"; char uart_rd2[]="AT +CMGR=1" ; char uart_rd3[]="AT +CMGS="; char Mobile_No[]="+919444721638" ; char Send_Msg[]="@ON"; void main() { INTCON = 0; // All interrupts disabled ADCON1 = 0x82; // A/D voltage reference is VCC TRISA = 0xFF; // All port A pins are configured as inputs TRISC=0x01; Delay_ms(2000); // Rest of pins are configured as digital UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize Lcd_Init(); // LCD display initialization Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off) Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD) text = "Air Pollution "; // Define the first message Lcd_Out(1,1,text); // Write the first message in the first line delay_ms(500); text = "Sensor Value"; // Define the second message Lcd_Out(2,1,text); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); text = "GSM"; // Define the third message while (1) {
  • 3. Lcd_Out(1,1,text); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); Gsm_SMS_Init(); } } void Gsm_SMS_Init() { if (UART1_Tx_Idle() == 1) { for(i=0;i<=1;i++) { UART1_Write(uart_rd); //AT } UART1_Write(0x0D); //Enter Lcd_Out(2,1,"AT"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); //delay_ms(5000); while(1) { if (UART1_Data_Ready()) { // If data is received, for(i=0;i<=1;i++) { return_gsm = UART1_Read(); // read the received data, Received OK } Lcd_Out(2,1,"OK"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); /* UART1_Write(return_gsm[0]); Lcd_Out(2,1,"OK RESEND"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); */ // UART1_Write(return_gsm[1]); } } /*if(return_gsm[0]==0x4F && return_gsm[1]==0x4B) { if (UART1_Tx_Idle() == 1) { for(i=0;i<=8;i++)
  • 4. { UART1_Write(uart_rd1); //AT+CMGF=1 } UART1_Write(0x0D); //Enter Lcd_Out(1,1,"AT+CMGF=1"); delay_ms(500); Lcd_Cmd(_LCD_CLEAR); } if (UART1_Data_Ready()) { // If data is received, for(i=0;i<=1;i++) { return_gsm = UART1_Read(); // read the received data,OK } Lcd_Out(2,1,"Received OK"); delay_ms(500); Lcd_Cmd(_LCD_CLEAR); } } */ } } Code (text): /*Header***************************************************** Microcontroller=16f877 Clock=10 Mhz Project Title:Air Pollution Control Using GSM/GPRS Developed By:Sathiesh Kumar.V Date:31/01/2010*/ void Calculation(unsigned int ) ; void Gsm_SMS_Init(); void Gsm_SMS_Read(); void Gsm_SMS_Send(); // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections
  • 5. unsigned char ch; // char Receive; unsigned int adc_rd; // Declare variables char *text; // long tlong; // unsigned int i,j; char return_gsm[2]; char Gsm_Receive[100]; char Gsm_Msg[10]; char uart_rd[]="AT"; char uart_rd1[]="AT+CMGF=1"; char uart_rd2[]="AT+CMGR=1" ; char uart_rd3[]="AT+CMGS="; char Mobile_No[]="+919444721638" ; char Send_Msg[]="@ON"; void main() { INTCON = 0; // All interrupts disabled ADCON1 = 0x82; // A/D voltage reference is VCC TRISA = 0xFF; // All port A pins are configured as inputs TRISC=0x80; Delay_ms(2000); // Rest of pins are configured as digital UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize Lcd_Init(); // LCD display initialization Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off) Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD) text = "Air Pollution "; // Define the first message Lcd_Out(1,1,text); // Write the first message in the first line delay_ms(500); text = "Sensor Value"; // Define the second message Lcd_Out(2,1,text); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); text = "GSM"; // Define the third message while (1) { Lcd_Out(1,1,text); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); Gsm_SMS_Init(); } } void Gsm_SMS_Init() { if (UART1_Tx_Idle() == 1) { Lcd_Out(2,1,"AT"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR);
  • 6. for(i=0;i<=1;i++) { UART1_Write(uart_rd[i]); //AT } UART1_Write(0x0D); //Enter //delay_ms(5000); while(1) { Lcd_Out(2,1,"In while"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); if (UART1_Data_Ready()) { // If data is received, Lcd_Out(2,1,"In IF"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); for(i=0;i<=1;i++) { return_gsm[i] = UART1_Read(); // read the received data, Received OK } Lcd_Out(2,1,"OK"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); /* UART1_Write(return_gsm[0]); Lcd_Out(2,1,"OK RESEND"); // Define the first message delay_ms(500); Lcd_Cmd(_LCD_CLEAR); */ // UART1_Write(return_gsm[1]); } } /*if(return_gsm[0]==0x4F && return_gsm[1]==0x4B) { if (UART1_Tx_Idle() == 1) { for(i=0;i<=8;i++) { UART1_Write(uart_rd1[i]); //AT+CMGF=1 } UART1_Write(0x0D); //Enter Lcd_Out(1,1,"AT+CMGF=1"); delay_ms(500); Lcd_Cmd(_LCD_CLEAR); } if (UART1_Data_Ready()) { // If data is received, for(i=0;i<=1;i++) { return_gsm[i] = UART1_Read(); // read the received data,OK
  • 7. } Lcd_Out(2,1,"Received OK"); delay_ms(500); Lcd_Cmd(_LCD_CLEAR); } } */ } } Code (text): void sms_send(); void sms_del(); void sms_read(); char sms[11]; char output[65]; unsigned char* MSG4 = "AT+CNMI=2,1,0,0,0"; void main() { UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize // sms_del(); sms_read(); } void sms_send() { int i; /*UART1_Write_Text("ATnr"); delay_ms(500); UART1_Write_Text("AT+CMGF=1nr"); delay_ms(500); */ UART1_Write_Text("AT+CMGS="); UART1_Write(0x22); UART1_Write_Text("+919444721638"); UART1_Write(0x22); UART1_Write_Text("nr"); delay_ms(500); for(i=0;i<64;i++) { if(output[i]=='0') break;//ask for null character of sms vector when find it go out of for() loop UART1_Write(sms[i]); } delay_ms(500); UART1_Write(26);// send ctrl + Z return; } void sms_del() { UART1_Write_Text("AT+CMGD=1nr"); delay_ms(500); }
  • 8. void sms_read() { int i; //char sms[11]; UART1_Write_Text("ATnr"); delay_ms(500); UART1_Write_Text(MSG4); //cpms Delay_ms(1000); UART1_Write(0X0D); // ENTER Delay_ms(1000); UART1_Write_Text("AT+CMGF=1nr"); delay_ms(500); UART1_Write_Text("AT+CMGR=7nr"); //delay_ms(500); while (UART1_Data_Ready() != 1); UART1_Read_Text(output, "OK", 65); // reads text until 'OK' is found sms_send(); //return; }