8051 – GSM Interfacing

Hi Guys, In our previous tutorial, we have seen how to interface the Ultrasonic sensor with 8051.  Today we will see GSM interfacing with 8051. Before that please take a look at GSM Module Introduction.  And you should know the Serial Communication of 8051. I’ve posted that also. Please go through that (Serial Communication).

GSM interfacing with 8051

SIM900A

GSM/GPRS Modem-RS232 is built with Dual Band GSM/GPRS engine- SIM900A works on frequencies 900/ 1800 MHz. The Modem is coming with an RS232 interface, which allows you to connect PC as well as a microcontroller with RS232 Chip(MAX232). The baud rate is configurable from 9600-115200 through AT command. The GSM/GPRS Modem is having an internal TCP/IP stack to enable you to connect with the internet via GPRS. It is suitable for SMS, Voice as well as DATA transfer applications in the M2M interface. You can read more about SIM900a.

Components Required

  • GSM SIM900A module
  • 8051 Development Board

Connection

GSM interfacing with 8051

Micro controller’s RX (P3.0) is connected to GSM module’s TX and Micro controller’s RX is Connected to GSM module’s RX pin.

Code

SMS Sending Code

This code is used to send the message to a particular number. You can also download this code from Github.

#include <reg51.h>

#define NUMBER 0123456789         //Here insert your number where you want to send message

void ser_init();
void tx(unsigned char send);
void tx_str(unsigned char *s);
unsigned char rx();

void sms(unsigned char *num1,unsigned char *msg);
void gsm_delay();

unsigned int dell;

int main()
{
        ser_init();
        
        sms(NUMBER, "Welcome to the Embetronicx");
        while(1);
}

void ser_init()
{
	SCON=0x50;
	TMOD=0x21;
	TH1=0xFD;
	TL1=0xFD;
	TR1=1;
}

void tx(unsigned char send)
{
	SBUF=send;
	while(TI==0);
	TI=0;
}

void tx_str(unsigned char *s)
{
	while(*s)
		tx(*s++);
}

unsigned char rx()
{
	while(RI==0);
	RI=0;
	return SBUF;
}

void gsm_delay()
{
	unsigned int gsm_del;
	for(gsm_del=0;gsm_del<=50000;gsm_del++);
}

void sms(unsigned char *num1,unsigned char *msg)
{
	tx_str("AT");
	tx(0x0d);
	gsm_delay();

	tx_str("AT+CMGF=1");
	tx(0x0d);
	gsm_delay();

	tx_str("AT+CMGS=");
	tx('"');
	while(*num1)
		tx(*num1++);
	tx('"');
	tx(0x0d);
	gsm_delay();

	while(*msg)
		tx(*msg++);
	tx(0x1a);
	gsm_delay();
}

Calling Code

This code is used to call a particular number. You can also download this code from Github.

#include <reg51.h>

#define NUMBER 0123456789         //Here insert your number where you want to call

void ser_init();
void tx(unsigned char send);
void tx_str(unsigned char *s);
unsigned char rx();

void sms(unsigned char *num1,unsigned char *msg);
void gsm_delay();

unsigned int dell;

int main()
{
        ser_init();
        
        call(NUMBER);
        while(1);
}

void ser_init()
{
	SCON=0x50;
	TMOD=0x21;
	TH1=0xFD;
	TL1=0xFD;
	TR1=1;
}

void tx(unsigned char send)
{
	SBUF=send;
	while(TI==0);
	TI=0;
}

void tx_str(unsigned char *s)
{
	while(*s)
		tx(*s++);
}

unsigned char rx()
{
	while(RI==0);
	RI=0;
	return SBUF;
}

void gsm_delay()
{
	unsigned int gsm_del;
	for(gsm_del=0;gsm_del<=50000;gsm_del++);
}

void call(unsigned char *num2)
{
	tx_str("AT");
	tx(0x0d);
	gsm_delay();

	tx_str("AT+CMGF=1");
	tx(0x0d);
	gsm_delay();

	tx_str("ATD");
	while(*num2)
		tx(*num2++);
	tx(';');
	tx(0x0d);
	for(dell=0;dell<=30;dell++)
		gsm_delay();

	tx_str("ATH");
	tx(0x0d);
	gsm_delay();
}

In our next tutorial, we will see how to interface the RFID with 8051.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
Bootloader Tutorials
5 5 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
2
0
Would love your thoughts, please comment.x