GSM Interfacing with 8051
What is a GSM?
GSM (Global System for Mobile Communications) in the 8051 microcontroller context refers to the use of a GSM module (such as SIM800 or SIM900) that enables the 8051 microcontroller to communicate over a cellular network to send and receive SMS, make calls, or access mobile data. Communication between the 8051 and the GSM module is typically done using UART serial communication and AT commands.
AT Command | Description |
---|---|
ATD+919029766790; |
Dial a voice call to the number +919029766790 . The ; specifies a voice call. |
ATA |
Answer an incoming call. |
ATH |
Hang up the current call. |
AT+CMGF=1 |
Set SMS message format to text mode. |
AT+CMGS="+919029766790" |
Send SMS to the specified number. |
0x0D (Carriage Return) |
Indicates end of command and sends it to the GSM module. |
0x1A (Ctrl+Z) |
Indicates end of SMS text and triggers sending of the SMS. |
Image of GSM:-
Task 1:- Write a code of GSM when switch 1 is pressed it should make a phone call, when switch 2 is pressed answer a call, when switch 3 is pressed it should hang up the call, and when switch4 is pressed it should send the messsage.
Code:-
#include<REG51.H>
void tx(unsigned char w);
//unsigned char d;
void display(unsigned char str[]);
void ser_init();
void delay(int t);
sbit sw1=P3^4;
sbit sw2=P3^5;
sbit sw3=P3^2;
sbit sw4=P3^3;
void main()
{
ser_init();
if(sw1==0)
{
display("ATD+919029766790;");
tx(0x0d);
delay(1);
}
if(sw2==0)
{
display("ATA");
tx(0x0d);
delay(1);
}
if(sw3==0)
{
display("ATH");
tx(0x0d);
delay(1);
}
if(sw4==0)
{
display("AT+CMGF=1");
tx(0x0d);
delay(1);
display("AT+CMGS=\"+ 919029766790\"");
tx(0x0d);
delay(1);
display("GSM ROCKS");
tx(0x1a);
delay(1);
tx(0x0d);
delay(1);
}
}
void ser_init()
{
SCON=0x50;
TMOD=0x20;
TH1=0xFD;
TR1=1;
}
void tx(unsigned char w)
{
SBUF=w;
while(TI==0);
TI=0;
}
void display(unsigned char str[])
{
int i;
for(i=0;str[i]!='\0';i++)
{
tx(str[i]);
}
}
void delay(int t)
{
int i,j;
for(i=0;i<=30*t;i++)
{
for(j=0;j<=1275;j++);
}
}
0 Comments