[51] GSM interface with 8051

Status
Not open for further replies.

Kenny Parmar

Newbie level 1
Joined
Dec 6, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
6
hello i want to make project device controller through GSM modem by SMS.

so that i am try to code this 8051 controller used in this project

i am code a one code but is not working in hardware and its finallly work in simulation protues.

can any one help me to solve this problem?

i am post my code and protues design file both.
Please fine the attachment.

Code:
//Start of COde

#include<regx52.h>
#include<string.h>
#include<absacc.h>
#include<stdlib.h>
#include<ctype.h>
#define buffer 40

#define dataport P1  // Dataport for lcd

#define port1 P2
#define port2 P0
sbit rs = P3^6;
sbit en =P3^7;
bit NewMessage=0;

sbit dv1=port1^0;
sbit dv2=port1^1;
sbit dv3=port1^2;
sbit dv4=port1^3;
sbit dv5=port1^4;
sbit dv6=port1^5;
sbit dv7=port1^6;
sbit dv8=port1^7;

sbit dv9=port2^0;
sbit dv10=port2^1;
sbit dv11=port2^2;
sbit dv12=port2^3;
sbit dv13=port2^4;
sbit dv14=port2^5;
sbit dv15=port2^6;
sbit dv16=port2^7;

void txstr(char *str);
void txchar(char value);



unsigned char abc,apt=0,count=0;
unsigned char idata msg1[buffer];

unsigned char code Response[] = "+CMTI";
// Moblie no.of Owner
unsigned char code Mob_no[]= "9409122228"; 

unsigned char MyBuff[20], k = 0;

bit flag1=0;
unsigned char store[10];



void delay(unsigned int msec) //Time delay function
{
int i,j ;
for(i=0;i<msec;i++)
  for(j=0;j<1275;j++);
}

void lcd_cmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
rs= 0;

en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item) //Funtion to send data on LCD
{
dataport = item;
rs= 1;

en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str) // Function to send string on LCD
{
int i=0;
while(str[i]!='\0')
{
  lcd_data(str[i]);
  i++;
  delay(10);
}
return;
}

void lcdstr(unsigned char *s)
{
 unsigned int l,i;
 l = strlen(s);               // get the length of string
 for(i=1;i<=l;i++)
 {
  lcd_data(*s);              // write every char one by one
  s++;  
 }
}


void lcd(unsigned char str[10])  // Funtion to Initialize LCD
{
lcd_cmd(0x38);
lcd_cmd(0x0e);
delay(50);
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_data_string(str);
}

void lcd2(unsigned char str[10])  // Funtion to Initialize LCD
{
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_cmd(0xc0);
delay(50);
lcd_data_string(str);
}


void tx0(unsigned char x) //send data to serial port 0
{
	EA=0;
	SBUF=x;
	while(TI==0);
	TI=0;
	EA=1;
}

void SMSString(unsigned char* text) //function to send SMS using GSM modem
{
	while (*text)
	{
		tx0(*text++);
	}
}
void delete_msg(void)
{

	SMSString("AT+CMGD=1,4\r");
	delay(20);

}

void serial_init()
{	
	port2=0x00;
	TL1=0XFD; //9600 @ 11.0592
	TH1=0xFD;
	TMOD=0x20;
	SCON=0x50;
	TR1=1;
}
 

void check()
{
		if(SBUF=='1')
   		{
		dv1=1;
		lcd("Message Received");
		lcd2("device 1 is on");
		}
				
		if(SBUF=='2')
   		{
		dv2=1;
		lcd("Message Received");
		lcd2("device 2 is on");
		}
		if(SBUF=='3')
   		{
		dv3=1;
		lcd("Message Received");
		lcd2("device 3 is on");
		}
		if(SBUF=='4')
   		{
		dv4=1;
		lcd("Message Received");
		lcd2("device 4 is on");
		}if(SBUF=='5')
   		{
		dv5=1;
		lcd("Message Received");
		lcd2("device 5 is on");
		}
		if(SBUF=='6')
   		{
		dv6=1;
		lcd("Message Received");
		lcd2("device 6 is on");
		}
		if(SBUF=='7')
   		{
		dv7=1;lcd("Message Received");
		lcd2("device 7 is on");
		}
		if(SBUF=='8')
   		{
		dv8=1;
		lcd("Message Received");
		lcd2("device 8 is on");
		}

   
	  if(SBUF=='9')
   		{
		dv9=1;
		lcd("Message Received");
		lcd2("device 9 is on");
		}
		if(SBUF=='a')
   		{
		dv10=1;
		lcd("Message Received");
		lcd2("device 10 is on");
		}
		if(SBUF=='b')
   		{
		dv11=1;
		lcd("Message Received");
		lcd2("device 11 is on");
		}
		if(SBUF=='c')
   		{
		dv12=1;
		lcd("Message Received");
		lcd2("device 12 is on");
		}
		if(SBUF=='d')
   		{
		dv13=1;
		lcd("Message Received");
		lcd2("device 13 is on");
		}
		if(SBUF=='e')
   		{
		dv14=1;
		lcd("Message Received");
		lcd2("device 14 is on");
		}
		if(SBUF=='f')
   		{
		dv15=1;
		lcd("Message Received");
		lcd2("device 15 is on");
		}
		if(SBUF=='g')
   		{
		dv16=1;
		lcd("Message Received");
		lcd2("device 16 is off");
		}

		if(SBUF=='A')
   		{
		dv10=0;
		lcd("Message Received");
		lcd2("device 10 is off");
		}
		if(SBUF=='B')
   		{
		dv11=0;
		lcd("Message Received");
		lcd2("device 11 is off");
		}
		if(SBUF=='C')
   		{
		dv12=0;
		lcd("Message Received");
		lcd2("device 12 is off");
		}
		if(SBUF=='D')
   		{
		dv13=0;
		lcd("Message Received");
		lcd2("device 13 is off");
		}
		if(SBUF=='E')
   		{
		dv14=0;
		lcd("Message Received");
		lcd2("device 14 is off");
		}
		if(SBUF=='F')
   		{
		dv15=0;
		lcd("Message Received");
		lcd2("device 15 is off");
		}
		if(SBUF=='G')
   		{
		dv16=1;
		lcd("Message Received");
		lcd2("device 16 is off");
		}
		if(SBUF=='H')
   		{
		dv1=0;
		lcd("Message Received");
		lcd2("device 1 is off");
		}
		if(SBUF=='I')
   		{
		dv2=0;
		lcd("Message Received");
		lcd2("device 2 is off");
		}
		if(SBUF=='J')
   		{
		dv3=0;
		lcd("Message Received");
		lcd2("device 3 is off");
		}
		if(SBUF=='K')	
   		{		   
		dv4=0;
		lcd("Message Received");
		lcd2("device 4 is off");
		}
		if(SBUF=='L')
		
   		{
		dv5=0;
		lcd("Message Received");
		lcd2("device 5 is off");
		}
		if(SBUF=='M')
		
   		{
		dv6=0;
		lcd("Message Received");
		lcd2("device 6 is off");
		}
		if(SBUF=='N')
   		{
		dv7=0;
		lcd("Message Received");
		lcd2("device 7 is off");
		}
		if(SBUF=='O')
   		{
		dv8=0;
		lcd("Message Received");
		lcd2("device 8 is off");
		}
		if(SBUF=='P')
   		{
		dv9=0;
		lcd("Message Received");
		lcd2("device 9 is off");
		}
	return;
}


 void receive_data()  	// Function to recieve data serialy from RS232 into microcontroller
 {	
  		extern unsigned char j;
	   	lcd_cmd(0x01);
		EA=0;
		while(RI==0);
		RI=0;
	//	j=SBUF;
		lcd_data(SBUF);
		EA=1;
	   	check();
		txchar(0x1a);
		delay(300);
		txstr("ATD9429944944;\r");
		delay(300);
	

 }






	

void main()
{
port2=P1=port1=0x00;
lcd("home automation");
lcd2("system");	

	
serial_init();


   // Configure interrupt 0 for falling edge on /INT0 (P3.2)
SMSString("AT\r\n"); // AT commands to initialize gsm modem
delay(20);

SMSString( "ATe0\r\n"); // turn off echo
delay(20);

SMSString( "AT&W\r\n"); // save settings
delay(20);

SMSString( "AT+CMGF=1\r\n"); // select text mode for sms
delay(20);
  
SMSString( "AT+CNMI=1,1,0,0,0\r\n"); // notification of new sms
lcd_cmd(0x01); //Clear LCD display.

 
 while(1)
{
 
delay(20);
SMSString("AT+CMGL=REC UNREAD\r\n");   //new message indicate
SMSString("AT+CMGL=0\r\n");				//
SMSString("AT+CMGR=1\r\n"); 

receive_data();
SMSString("AT+CMGL=1\r\n");
 receive_data();
delay(20); 
}

}

void txchar(char value)
{
	SBUF=value;
	while(TI==0); // Pole TI flag for complete transmission
	TI=0;
}

void txstr(char *str)
{
 	while(*str)
	{
	 	txchar(*str);
		str++;
		delay(100);
	}
	*str='\0';
	return;
}
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…