How To Interface GSM Module With 8051 Microcontroller
How To Interface GSM Module With 8051 Microcontroller
i.
ii.
The microcontroller program involves the following complexities to display data coming
from the GSM/GPRS module on LCD.
The data coming from the GSM module is stored in a character array. This character
array is shifted to left every time character is read and deleted. This is important to
maintain room for the incoming data and ensure that no character in an information
response or result code is lost.
The information response and the result codes have carriage return and line feed
characters in the beginning as well as end. These characters need to be monitored and
removed by the controllers program.
This project is first step towards making and independent system using the GSM
module and a microcontroller. Here the HyperTerminal (computer) has been replaced
with LCD at the output end. In the next project (MC076), the AT Commands will be
transmitted to the GSM module by the microcontroller itself thus avoiding the need of
using HyperTerminal entirely.
#include<reg51.h>
#define port P1
#define dataport P2
sbit rs = port^0;
sbit rw = port^1;
sbit en = port^2;
int count,i;
unsigned char check,str[15];
bit check_space ;
void init_serial()
{
TMOD=0x20;
TH1=0xfd;
SCON=0x50;
Start bit, Receiving on
TR1=1;
}
// Mode=2
// 9600 baud
// Serial mode=1, 8-Bit data, 1 Stop bit, 1
// Start timer
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0; j<1275; j++);
}
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}
{
int i=0;
while(str[i]!='\0')
{
lcd_data(str[i]);
i++;
delay(10);
}
return;
}
void lcd()
{
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0F);
delay(5);
lcd_cmd(0x80);
of lcd
delay(5);
}
{
str[++count]=SBUF;
RI=0;
}
//Read SBUF
{
switch(str[0])
{
case 0x0a:
{
return 0x00;
break ;
}
case 0x0d:
{
return 0x1;
break ;
}
default:return 0x02 ;
new line and carriage return
}
}
void main()
{
lcd();
// Initialize LCD
init_serial();
count=(-1);
lcd_data_string("Ready");
delay(10);
lcd_cmd(0x01);
IE=0x94;
while(1)
{
if(count>=0)
{
check=byte_check();
if(check!=0x00)
{
if(check==0x01)
{
if(check_space==1)
//Check previous
character
{
lcd_data(0x20);
check_space=0;
}
}
else
{
lcd_data(str[0]);
check_space=1;
}
}
count--;
for(i=0;i<count;i++)
array to one left
{
str[i]=str[i+1];
}
}
}
}