deep0177
Newbie level 6
- Joined
- May 31, 2013
- Messages
- 11
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,354
How you interface GSM modem to 8051 ? Did you use MAX232 ?
Post circuit.
Hi to all when i give command AT+CPMS? it gives reply as follows
+CPMS: "SM",40,40,"SM",40,40,"SM",40,40
Code C - [expand] 1 2 3 4 5 6 void recieve() interrupt 4 Function to recieve data serialy from RS232 { msgIN[i++]=SBUF; RI=0; // Reset the serial interrupt after recieving the byte msgIN[i] = '\0'; }
#include <REGX52.H>
//LCD Declaration//
#define LCD P1
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
void delayms(unsigned char);
void delayus(unsigned char);
void lcd_init();
void lcd_reset();
void lcd_cmd (char);
void lcd_data(unsigned char);
void lcd_str (unsigned char *);
void clear(void);
void tx0(unsigned char);
void delay_sms (unsigned int);
void ms_delay(unsigned int itime);
void SMSString(char*text) ;
void init();
void read_text(unsigned char * , unsigned char * , unsigned char *);
unsigned char j,abc;
unsigned char idata msg1[150];
unsigned char rec_no[20];
unsigned char time_date[20];
void serial () interrupt 4
{
msg1[abc]=SBUF;
abc++;
RI=0;
}
void main (void)
{
/*
if u do not want to check "OK" response after each AT command then
enable interrupt IE=0X90 ; after last AT command of
SMSString( "AT+CMGR=1\r"); // AT command to read sms
so after that u recieve a no of bytes from modile if u disable it then u do not reieve
it even data comes
use a virtual terminal in Proteus
run a Proteus and right click on virtual terminal and click on option echo character display.
in Proteus there is no mobile model so u should enter text in hyper terminal to suppose gsm Modem is responding.
use serial receive interrupt to receive data
check here
*/
clear();
init();
lcd_init();
SMSString("AT\r"); // AT commands to initialize gsm modem
delay_sms(1000);
SMSString( "ATe0\r"); // turn off echo
delay_sms(1000);
SMSString( "AT&W\r"); // save settings
delay_sms(1000);
SMSString( "AT+CMGF=1\r"); // select text mode for sms
delay_sms(1000);
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
delay_sms(1000);
SMSString( "AT+CMGR=1\r"); // AT command to read sms
IE=0X90; // Enable serial interrupt
delay_sms(5000);
/* i get a response like this
// +CMGR: "REC READ" ,"+2347060580383","10/10/23,14:29:33+04"
// device1 off
// Ok. */
// read sms and store in buffer msg1
read_text(msg1,rec_no,time_date);
clear();
IE=0X00; // Disable all interrupt
while(1);
}
void init(void)
{
j=0;
abc=0;
TL1=0XFD; //9600 @ 11.0592
TH1=0xFD;
TMOD=0x20;
SCON=0x50;
TR1=1;
}
void SMSString(unsigned char* text) //function to send SMS using GSM modem
{
while (*text)
{
tx0(*text++);
}
}
void tx0(unsigned char x) //send data to serial port 0
{
EA=0;
SBUF=x;
while(TI==0);
TI=0;
EA=1;
}
void delay_sms (unsigned int count)
{
unsigned int i; // Keil v7.5a
while(count) {
i = 115;
while(i>0) i--;
count--;
}
}
void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time)
{
unsigned char *temp;
temp=msg;
do
msg++;
while(*msg!='+');
do
msg++;
while(*msg!='+'); // reaching at no
do
*no++=*msg++;
while(*msg!='"'); // reaching at time
*no++='\0';
msg++;
msg++;
msg++;
do
*time++=*msg++;
while(*msg!='+'); // raching at message
*time='\0';
do
msg++;
while(*msg!='\n');
msg++;
do
*temp++=*msg++;
while(*msg!='\r'); // reaching at end of message
*temp='\0';
lcd_cmd(0x80); // ist line address
lcd_str(rec_no); // array having receipt no
lcd_cmd(0xC0); // 2nd line address
lcd_str(time_date); // array having date and time
lcd_cmd(0x94); // 3rd line address
lcd_str(msg1); // array having message
}
void lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x0F);
lcd_cmd(0x01);
lcd_cmd(0x06);
lcd_cmd(0x80);
}
void lcd_cmd(unsigned char value)
{
LCD=value;
rs=0;
rw=0;
en=1;
ms_delay(1);
en=0;
}
void lcd_data(unsigned char value)
{
LCD=value;
rs=1;
rw=0;
en=1;
ms_delay(1);
en=0;
}
void ms_delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++){
for(j=0;j<1200;j++);
}
}
void clear(void)
{
unsigned char a;
for(a=0;a<100;a++)
msg1[a]=0x00;
}
void lcd_str (unsigned char *str)
{
while(*str){
lcd_data(*str++);
}
}
[COLOR="silver"][SIZE=1]- - - Updated - - -[/SIZE][/COLOR]
i am also working on this code but also getting garbage value
#include <reg52.h>
#include <stdio.h>
//Delay Functions Declarations ********************************
void ms_delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++){
for(j=0;j<1200;j++);
}
}
void delay()
{
int i,j;
for(i=0;i<1000;i++)
for(j=0;j<5000;j++);
}
// Delay functions declaration********************************
//LCD Function Declarations------------------------
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
#define LCD P1
void lcd_cmd(unsigned char value)
{
LCD=value;
rs=0;
rw=0;
en=1;
ms_delay(1);
en=0;
}
void lcd_data(unsigned char value)
{
LCD=value;
rs=1;
rw=0;
en=1;
ms_delay(1);
en=0;
}
void string_lcd (unsigned char* ptr)
{
unsigned int h,j=0;
while(*ptr)
{
h++;
if(h<15)
{
lcd_data(*ptr++);
}
if(h>=15)
{
lcd_cmd(0xc0+j);
lcd_data(*ptr++);
j++;
}
// *(ptr++);
}
}
void lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x0F);
lcd_cmd(0x01);
lcd_cmd(0x06);
lcd_cmd(0x80);
}
// LCD Functiond End----------------------------
//Gsm Functions
void String_Gsm(unsigned char*);
void Write_Gsm(unsigned char);
void Read_Gsm(unsigned int);
//
unsigned char mysms;
unsigned char buffer[20];
void main (void)
{
unsigned char at[]="at";
unsigned int i=0;
TMOD = 0x20;
SCON = 0x50;
TH1 = -3;
TR1 = 1;
TI=1;
lcd_init();
string_lcd("Testing GSM");
lcd_cmd(0xc0);
string_lcd("Reading SMS");
ms_delay(500);
lcd_cmd(0x01);
lcd_cmd(0x06);
lcd_cmd(0x80);
String_Gsm("at");
ms_delay(2);
Write_Gsm(0x0d);
ms_delay(1);
read_Gsm(2);
ms_delay(50);
lcd_cmd(0x01);
String_Gsm("at+cmgf=1");
ms_delay(10);
Write_Gsm(0x0d);
ms_delay(1);
read_Gsm(2);
ms_delay(50);
lcd_cmd(0x01);
String_Gsm("at+cnmi=2,1,0,1,0");
ms_delay(10);
Write_Gsm(0x0d);
ms_delay(1);
read_Gsm(2);
ms_delay(50);
lcd_cmd(0x01);
String_Gsm("at+cmgr=1");
ms_delay(2);
Write_Gsm(0x0d);
ms_delay(1);
read_Gsm(20);
}
void String_Gsm(unsigned char *s)
{
while(*s)
Write_Gsm(*s++);
}
void Write_Gsm(unsigned char c)
{
SBUF=c;
lcd_data(c);
while(TI==0);
TI=0;
ms_delay(2);
}
void read_Gsm(unsigned int count)
{
int i=0;
while(count>0)
{
while(RI==0);
while(RI==0);
while(RI==0);
if(RI==1)
{
i=0;
buffer[i]=SBUF;
lcd_data(buffer[i]);
RI=0;
i++;
}
if(count==0)break;
count --;
}
}
void serial_intr(void) interrupt 4 //interrupt service routine for serial interrupt
{
if(TI==1) //if transmit interrupt, clear TI
{
TI=0;
}
if(RI==1) //if receive interrupt
{
mysms=SBUF;
lcd_data(mysms);
RI=0;
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?