SlideShare a Scribd company logo
1 of 6
Interface GSM module with PIC..
The Global System for Mobile (GSM) communication is the Second Generation of mobile technology.
Although the world is moving towards Third and Fourth generation but GSM has been the most
successful and widespread technology in the communication sector. GSM technology paved a new way
for mobile communication.
This project explains the interfacing of a GSM Module with a PIC microcontroller. It also covers a way to
dial a particular GSM mobile number as well as send a message to it using AT Commands with the
help of PIC18F4550.
Objectives:
This project has following objectives which are fulfilled using AT Commands:
1. Test the simple AT Command.
2. Find out the IMEI number of the GSM Modem.
3. Connect a call to a GSM mobile number (Dial a number).
4. Send a text message to a mobile number.
The provision of these four operations has been provided by means of four tactile switches. Each switch
corresponds to each of the above functions. AT Commands used to perform the above operations have
been given below along with their output. (For complete list of AT Commands supported by GSM Modem,
refer the list in tutorial on AT Commands.
As explained earlier (refer GSM interfacing with 8051), a line converter MAX232 is employed to convert
the RS232 logic data of GSM Module to TTL logic so that it can be processed by the microcontroller. In
this project, instead of RS232 logic data, TTL logic output has been taken and thus PIC18F4550 has
been directly connected with GSM Modem without any line converter in between. The following diagram
shows the TTL input and output of GSM modem used.
Code:-
//Program to interface GSM Modem with PIC18F4550 Microcontroller
//This code takes four choices as four inputs
//Choice 1 : Test the simple AT Command.
//Choice 2 : Find out the IMEI number of the GSM Modem.
//Choice 3 : Connect a call to a GSM mobile number.
//Choice 4 : Send a text message to a mobile number.
#define FREQ 12000000
#define baud 9600
#define spbrg_value (((FREQ/64)/baud)-1)
#define rs LATA.F0
#define rw LATA.F1
#define en LATA.F2
#define lcdport LATB
void tx_data(unsigned char);
unsigned char rx_data();
void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void gsm_cmd(unsigned char *);
void output(void);
unsigned char value=0;
int i=0,j,k,temp,flag,choice;
unsigned char *starting_text="Enter choice=";
unsigned char *dial_text="Dialing...";
unsigned char *at_cmd="AT";
unsigned char *imei_cmd="AT+GSN";
unsigned char *call_cmd="ATD9xxxxxxxxx;"; // Provide a 10-Digit Mobile Number
unsigned char *sms_format="AT+CMGF=1";
unsigned char *sms_write="AT+CMGS="xxxxxxxxxx""; // 10-Digit Mobile Number
unsigned char *sms="Hello";
unsigned char *sms_report="SMS Sent...";
unsigned char sms_terminate=0x1A;
unsigned char enter=0x0D;
unsigned char *data;
void main()
{
TRISB=0; // Set Port B as output port
LATB=0;
TRISA=0;
LATA=0;
TRISD=0xFF;
LATD=0;
SPBRG=spbrg_value; // Fill SPBRG register to set the
baud rate
RCSTA.SPEN=1; // To activate serial port (Tx and
Rx pins)
TXSTA.TXEN=1; // Activate Transmissiom
RCSTA.CREN=1; // Activate Reception
PIE1.RCIE=1; // Enable Reception interrupt
INTCON.GIE=1; // Enable Global interrupt
INTCON.PEIE=1; // Enable Peripheral interrupt
lcd_ini();
while(1)
{
k=0;
lcdcmd(0x80);
while(starting_text[k]!='0')
{
lcddata(starting_text[k]);
k++;
}
//Check inputs
//Choice 1
if(PORTD.F0)
{
gsm_cmd(at_cmd);
output();
Delay_ms(1000);
}
//Choice 2
if(PORTD.F1)
{
gsm_cmd(imei_cmd);
output();
Delay_ms(1000);
}
//Choice 3
if(PORTD.F2)
{
gsm_cmd(call_cmd);
output();
Delay_ms(1000);
}
//Choice 4
if(PORTD.F3)
{
gsm_cmd(sms_format);
output();
Delay_ms(1000);
gsm_cmd(sms_write);
output();
Delay_ms(1000);
gsm_cmd(sms);
output();
tx_data(0x1A);
Delay_ms(1000);
}
}
}
void gsm_cmd(unsigned char *string)
{
i=0;j=0;
while(string[i]!='0')
{
temp=0;
if(string[i]==0x5C) // Not to send '' cahracter
i++;
tx_data(string[i]); // Send by serial communication
i++;
while(temp!=1);
}
temp=0;
tx_data(enter); // Send ASCII code for 'Enter' key
while(temp!=1);
}
void output(void) // To print data on LCD
{
lcdcmd(0x01);
i=-1;flag=0;
while(i<j)
{
if(flag>1)
{
flag=0;
Delay_ms(500);
lcdcmd(0x01);
lcdcmd(0x80);
}
if(data[i]==0x0A) // This condition is to avoid
double Enter
// during execution of a command
{
flag++;
lcdcmd(0xc0);
}
if(data[i]=='>'||data[i]=='"') // Not to print this character
{
i++;
lcdcmd(0xc0);
}
if(data[i]!=0x0D&&data[i]!=0x0A&&data[i]!=0x1A) // Condition to
print the data
// except 'Enter','New
line' and 'Submit'
{
lcddata(data[i]);
i++;
}
else
i++;
Delay_ms(300);
}
lcdcmd(0x01);
}
void tx_data(unsigned char serial_data) // Transmit data function
{
TXREG=serial_data;
while(PIR1.TXIF==0);
}
void interrupt()
{
data[j]=RCREG; // Store the data into array when Reception
interrupt occurs
value=RCREG;
j++;
temp=1;
}
void lcd_ini()
{
lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7
font
lcdcmd(0x0C); // Display On and Cursor Off
lcdcmd(0x01); // Clear display screen
lcdcmd(0x06); // Increment cursor
lcdcmd(0x80); // Set cursor position to 1st line, 1st column
}
void lcdcmd(unsigned char cmdout)
{
lcdport=cmdout; //Send command to lcdport=PORTB
rs=0;
rw=0;
en=1;
Delay_ms(10);
en=0;
}
void lcddata(unsigned char dataout)
{
lcdport=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
Delay_ms(10);
en=0;
}

More Related Content

What's hot

Introduction to Vortex86EX Motion Control Modules
Introduction to Vortex86EX Motion Control ModulesIntroduction to Vortex86EX Motion Control Modules
Introduction to Vortex86EX Motion Control Modules
roboard
 
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
Ruthvik Vaila
 

What's hot (20)

AVR_Course_Day8 motor drive and pwm techniques
AVR_Course_Day8 motor drive and pwm techniquesAVR_Course_Day8 motor drive and pwm techniques
AVR_Course_Day8 motor drive and pwm techniques
 
Introduction to Vortex86EX Motion Control Modules
Introduction to Vortex86EX Motion Control ModulesIntroduction to Vortex86EX Motion Control Modules
Introduction to Vortex86EX Motion Control Modules
 
Pdf tp3076 national
Pdf tp3076 nationalPdf tp3076 national
Pdf tp3076 national
 
Wireless UART Controller: XR18W750
Wireless UART Controller: XR18W750Wireless UART Controller: XR18W750
Wireless UART Controller: XR18W750
 
VOCODER LST 36 pin signal data
VOCODER LST 36 pin signal dataVOCODER LST 36 pin signal data
VOCODER LST 36 pin signal data
 
VOCODER LST 72 pin signal data
VOCODER LST  72 pin signal dataVOCODER LST  72 pin signal data
VOCODER LST 72 pin signal data
 
Chapter5 dek3133
Chapter5 dek3133Chapter5 dek3133
Chapter5 dek3133
 
Uart VHDL RTL design tutorial
Uart VHDL RTL design tutorialUart VHDL RTL design tutorial
Uart VHDL RTL design tutorial
 
Uart
UartUart
Uart
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
Xilinxaxi uart16550
Xilinxaxi uart16550Xilinxaxi uart16550
Xilinxaxi uart16550
 
伺服馬達控制
伺服馬達控制伺服馬達控制
伺服馬達控制
 
report cs
report csreport cs
report cs
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
 
Arm7 document
Arm7  documentArm7  document
Arm7 document
 
Imx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOKImx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOK
 
Dc40 d mk3
Dc40 d mk3Dc40 d mk3
Dc40 d mk3
 
131080111003 mci
131080111003 mci131080111003 mci
131080111003 mci
 
FPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLERFPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLER
 

Viewers also liked

Point to-point-protocol
Point to-point-protocolPoint to-point-protocol
Point to-point-protocol
amigurumi21
 
final projects
final projectsfinal projects
final projects
jayam19
 
Accident messaging system using GPS,GSM and MEMS
Accident messaging system using GPS,GSM and MEMSAccident messaging system using GPS,GSM and MEMS
Accident messaging system using GPS,GSM and MEMS
Jithin Prasad
 
Gps tracking system
Gps tracking system Gps tracking system
Gps tracking system
Sumit Kumar
 

Viewers also liked (14)

An Approach to Improve the Railway Crack Detection in the Tracks by Automated...
An Approach to Improve the Railway Crack Detection in the Tracks by Automated...An Approach to Improve the Railway Crack Detection in the Tracks by Automated...
An Approach to Improve the Railway Crack Detection in the Tracks by Automated...
 
Sim900
Sim900Sim900
Sim900
 
Point-to-Point Protocol(PPP) CCN ppt
Point-to-Point Protocol(PPP) CCN pptPoint-to-Point Protocol(PPP) CCN ppt
Point-to-Point Protocol(PPP) CCN ppt
 
Introduction to PPP
Introduction to PPPIntroduction to PPP
Introduction to PPP
 
Point to-point protocol (ppp), PAP & CHAP
Point to-point protocol (ppp), PAP & CHAPPoint to-point protocol (ppp), PAP & CHAP
Point to-point protocol (ppp), PAP & CHAP
 
Chapter 2 point-to-point protocol (ppp)
Chapter 2   point-to-point protocol (ppp)Chapter 2   point-to-point protocol (ppp)
Chapter 2 point-to-point protocol (ppp)
 
Point to-point-protocol
Point to-point-protocolPoint to-point-protocol
Point to-point-protocol
 
final projects
final projectsfinal projects
final projects
 
Fully automatic anti collision train signalling project
Fully automatic anti collision train signalling projectFully automatic anti collision train signalling project
Fully automatic anti collision train signalling project
 
GSM Module
GSM ModuleGSM Module
GSM Module
 
Password based door lock system using 8051 microcontroller final report
Password based door lock system using 8051 microcontroller final reportPassword based door lock system using 8051 microcontroller final report
Password based door lock system using 8051 microcontroller final report
 
Accident messaging system using GPS,GSM and MEMS
Accident messaging system using GPS,GSM and MEMSAccident messaging system using GPS,GSM and MEMS
Accident messaging system using GPS,GSM and MEMS
 
Gps tracking system
Gps tracking system Gps tracking system
Gps tracking system
 
Vehicle tracking system using GSM and GPS
Vehicle tracking system using GSM and GPSVehicle tracking system using GSM and GPS
Vehicle tracking system using GSM and GPS
 

Similar to Interface gsm module with pic

REAL-TIME VEHICLE LOCKING AND TRACKING SYSTEM USING GSM AND GPS TECHNOLOGY-A...
REAL-TIME VEHICLE  LOCKING AND TRACKING SYSTEM USING GSM AND GPS TECHNOLOGY-A...REAL-TIME VEHICLE  LOCKING AND TRACKING SYSTEM USING GSM AND GPS TECHNOLOGY-A...
REAL-TIME VEHICLE LOCKING AND TRACKING SYSTEM USING GSM AND GPS TECHNOLOGY-A...
Sandeep Kunsoth
 
Auto dial-er Home security
Auto dial-er Home securityAuto dial-er Home security
Auto dial-er Home security
vaibhav jindal
 
GSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLER
GSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLERGSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLER
GSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLER
Md. Moktarul Islam
 
Coral gsm cdma gateway
Coral gsm cdma gatewayCoral gsm cdma gateway
Coral gsm cdma gateway
Mohd Arif
 
1 PageAlarm Clock Design Using PIC18F45E.docx
1  PageAlarm Clock Design Using PIC18F45E.docx1  PageAlarm Clock Design Using PIC18F45E.docx
1 PageAlarm Clock Design Using PIC18F45E.docx
mercysuttle
 

Similar to Interface gsm module with pic (20)

G3602050055
G3602050055G3602050055
G3602050055
 
Vehicle tracting system
Vehicle tracting systemVehicle tracting system
Vehicle tracting system
 
Product catlog
Product catlogProduct catlog
Product catlog
 
CC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver ModuleCC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver Module
 
IRJET- Design and Implementation of Telemetry Encoder for Light- Weight Ballo...
IRJET- Design and Implementation of Telemetry Encoder for Light- Weight Ballo...IRJET- Design and Implementation of Telemetry Encoder for Light- Weight Ballo...
IRJET- Design and Implementation of Telemetry Encoder for Light- Weight Ballo...
 
REAL-TIME VEHICLE LOCKING AND TRACKING SYSTEM USING GSM AND GPS TECHNOLOGY-A...
REAL-TIME VEHICLE  LOCKING AND TRACKING SYSTEM USING GSM AND GPS TECHNOLOGY-A...REAL-TIME VEHICLE  LOCKING AND TRACKING SYSTEM USING GSM AND GPS TECHNOLOGY-A...
REAL-TIME VEHICLE LOCKING AND TRACKING SYSTEM USING GSM AND GPS TECHNOLOGY-A...
 
Auto dial-er Home security
Auto dial-er Home securityAuto dial-er Home security
Auto dial-er Home security
 
E notice board project report
E notice board project reportE notice board project report
E notice board project report
 
GSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLER
GSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLERGSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLER
GSM 1308 MODEM CONTROL USING PIC-16F877A MICROCONTROLLER
 
gsm based led scrolling board ppt
gsm based led scrolling board pptgsm based led scrolling board ppt
gsm based led scrolling board ppt
 
CHAPTERS
CHAPTERSCHAPTERS
CHAPTERS
 
P 6168--microcontroller based-lpg_gas_detector_using_gsm_module
P 6168--microcontroller based-lpg_gas_detector_using_gsm_moduleP 6168--microcontroller based-lpg_gas_detector_using_gsm_module
P 6168--microcontroller based-lpg_gas_detector_using_gsm_module
 
GSM Based Campus Display system
GSM Based Campus Display systemGSM Based Campus Display system
GSM Based Campus Display system
 
Implementation of MIL-STD1553 using Microcontroller Atmega 328P
Implementation of MIL-STD1553 using Microcontroller Atmega 328PImplementation of MIL-STD1553 using Microcontroller Atmega 328P
Implementation of MIL-STD1553 using Microcontroller Atmega 328P
 
Embedded system lab work
Embedded system lab workEmbedded system lab work
Embedded system lab work
 
PIC18F458_Ritula Thakur.pptx.pdf
PIC18F458_Ritula Thakur.pptx.pdfPIC18F458_Ritula Thakur.pptx.pdf
PIC18F458_Ritula Thakur.pptx.pdf
 
Coral gsm cdma gateway
Coral gsm cdma gatewayCoral gsm cdma gateway
Coral gsm cdma gateway
 
Home automation and securty using wireless networks
Home automation and securty using wireless networksHome automation and securty using wireless networks
Home automation and securty using wireless networks
 
gsm based Notice board
gsm based Notice boardgsm based Notice board
gsm based Notice board
 
1 PageAlarm Clock Design Using PIC18F45E.docx
1  PageAlarm Clock Design Using PIC18F45E.docx1  PageAlarm Clock Design Using PIC18F45E.docx
1 PageAlarm Clock Design Using PIC18F45E.docx
 

Recently uploaded

Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

Interface gsm module with pic

  • 1. Interface GSM module with PIC.. The Global System for Mobile (GSM) communication is the Second Generation of mobile technology. Although the world is moving towards Third and Fourth generation but GSM has been the most successful and widespread technology in the communication sector. GSM technology paved a new way for mobile communication. This project explains the interfacing of a GSM Module with a PIC microcontroller. It also covers a way to dial a particular GSM mobile number as well as send a message to it using AT Commands with the help of PIC18F4550. Objectives: This project has following objectives which are fulfilled using AT Commands: 1. Test the simple AT Command. 2. Find out the IMEI number of the GSM Modem. 3. Connect a call to a GSM mobile number (Dial a number). 4. Send a text message to a mobile number. The provision of these four operations has been provided by means of four tactile switches. Each switch corresponds to each of the above functions. AT Commands used to perform the above operations have been given below along with their output. (For complete list of AT Commands supported by GSM Modem, refer the list in tutorial on AT Commands. As explained earlier (refer GSM interfacing with 8051), a line converter MAX232 is employed to convert the RS232 logic data of GSM Module to TTL logic so that it can be processed by the microcontroller. In this project, instead of RS232 logic data, TTL logic output has been taken and thus PIC18F4550 has been directly connected with GSM Modem without any line converter in between. The following diagram shows the TTL input and output of GSM modem used.
  • 2. Code:- //Program to interface GSM Modem with PIC18F4550 Microcontroller //This code takes four choices as four inputs //Choice 1 : Test the simple AT Command. //Choice 2 : Find out the IMEI number of the GSM Modem. //Choice 3 : Connect a call to a GSM mobile number. //Choice 4 : Send a text message to a mobile number. #define FREQ 12000000 #define baud 9600
  • 3. #define spbrg_value (((FREQ/64)/baud)-1) #define rs LATA.F0 #define rw LATA.F1 #define en LATA.F2 #define lcdport LATB void tx_data(unsigned char); unsigned char rx_data(); void lcd_ini(); void lcdcmd(unsigned char); void lcddata(unsigned char); void gsm_cmd(unsigned char *); void output(void); unsigned char value=0; int i=0,j,k,temp,flag,choice; unsigned char *starting_text="Enter choice="; unsigned char *dial_text="Dialing..."; unsigned char *at_cmd="AT"; unsigned char *imei_cmd="AT+GSN"; unsigned char *call_cmd="ATD9xxxxxxxxx;"; // Provide a 10-Digit Mobile Number unsigned char *sms_format="AT+CMGF=1"; unsigned char *sms_write="AT+CMGS="xxxxxxxxxx""; // 10-Digit Mobile Number unsigned char *sms="Hello"; unsigned char *sms_report="SMS Sent..."; unsigned char sms_terminate=0x1A; unsigned char enter=0x0D; unsigned char *data; void main() { TRISB=0; // Set Port B as output port LATB=0; TRISA=0; LATA=0; TRISD=0xFF; LATD=0; SPBRG=spbrg_value; // Fill SPBRG register to set the baud rate RCSTA.SPEN=1; // To activate serial port (Tx and Rx pins) TXSTA.TXEN=1; // Activate Transmissiom RCSTA.CREN=1; // Activate Reception PIE1.RCIE=1; // Enable Reception interrupt INTCON.GIE=1; // Enable Global interrupt INTCON.PEIE=1; // Enable Peripheral interrupt lcd_ini(); while(1) { k=0; lcdcmd(0x80); while(starting_text[k]!='0') { lcddata(starting_text[k]);
  • 4. k++; } //Check inputs //Choice 1 if(PORTD.F0) { gsm_cmd(at_cmd); output(); Delay_ms(1000); } //Choice 2 if(PORTD.F1) { gsm_cmd(imei_cmd); output(); Delay_ms(1000); } //Choice 3 if(PORTD.F2) { gsm_cmd(call_cmd); output(); Delay_ms(1000); } //Choice 4 if(PORTD.F3) { gsm_cmd(sms_format); output(); Delay_ms(1000); gsm_cmd(sms_write); output(); Delay_ms(1000); gsm_cmd(sms); output(); tx_data(0x1A); Delay_ms(1000); } } } void gsm_cmd(unsigned char *string) { i=0;j=0; while(string[i]!='0')
  • 5. { temp=0; if(string[i]==0x5C) // Not to send '' cahracter i++; tx_data(string[i]); // Send by serial communication i++; while(temp!=1); } temp=0; tx_data(enter); // Send ASCII code for 'Enter' key while(temp!=1); } void output(void) // To print data on LCD { lcdcmd(0x01); i=-1;flag=0; while(i<j) { if(flag>1) { flag=0; Delay_ms(500); lcdcmd(0x01); lcdcmd(0x80); } if(data[i]==0x0A) // This condition is to avoid double Enter // during execution of a command { flag++; lcdcmd(0xc0); } if(data[i]=='>'||data[i]=='"') // Not to print this character { i++; lcdcmd(0xc0); } if(data[i]!=0x0D&&data[i]!=0x0A&&data[i]!=0x1A) // Condition to print the data // except 'Enter','New line' and 'Submit' { lcddata(data[i]); i++; } else i++; Delay_ms(300); } lcdcmd(0x01); }
  • 6. void tx_data(unsigned char serial_data) // Transmit data function { TXREG=serial_data; while(PIR1.TXIF==0); } void interrupt() { data[j]=RCREG; // Store the data into array when Reception interrupt occurs value=RCREG; j++; temp=1; } void lcd_ini() { lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font lcdcmd(0x0C); // Display On and Cursor Off lcdcmd(0x01); // Clear display screen lcdcmd(0x06); // Increment cursor lcdcmd(0x80); // Set cursor position to 1st line, 1st column } void lcdcmd(unsigned char cmdout) { lcdport=cmdout; //Send command to lcdport=PORTB rs=0; rw=0; en=1; Delay_ms(10); en=0; } void lcddata(unsigned char dataout) { lcdport=dataout; //Send data to lcdport=PORTB rs=1; rw=0; en=1; Delay_ms(10); en=0; }