8051 – GSM Interfacing

Hi Guys 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

Components Required

  • GSM SIM900A module
  • 8051 Development Board

Connection

GSM interfacing with 8051

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

Code

SMS Sending Code

This code is used to send the message to the 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 to the 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();
}

If you have any doubt please comment below.

5 4 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
Ads Blocker Image Powered by Code Help Pro
Ad Blocker Detected!!!

Dear User,

Thanks for visiting the site. Unfortunately, we have noticed that you are using an Ad Blocker extension in your browser.

We charge advertisers instead of the audience. We depend on Ad revenue to keep creating quality content for you. We guarantee clean ads. 

HERE IS HOW YOU CAN KEEP READING!

Click the AdBlock icon on your browser and click Enabled on this site to Disable AdBlock in embetronicx.com or whitelist our website.

If you still want to hide the ads, please become a Premium member. If you are a premium member already, then please log in.

Thank you for understanding.

If you are seeing this even after disabling all the ad blockers, Please report us the False Positive to [email protected]

Refresh