Discussion in "Project Doubts" started by    learneryet    Mar 12, 2014.
Wed Mar 12 2014, 11:17 pm
#1
Hey there,

My project is to control home appliances using GSM(SMS). i took code from this

website, of "GSM based noticeboard" and edited it a little bit.
I know basic programming, so i have many questions..(silly ones too)

1)There were headers (like absacc.h, stdlib.h and ctype.h) but none functions were

using 'em. let it be.

2)I didn't understand why 'buffer' is used(other than clearing msg1)
#define buffer 30

3)in statement:
"unsigned char idata msg1[buffer];"
whats 'idata', please explain.

4)there is comment line saying,
"//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"
please explain about interrupt 'IE=0x90' and 'IE=0x91'
and why '\r'is used in AT commands?

5)why 'mybuff' is used?
and why only 13th locations is checked while deleting msgs
"if(MyBuff[12]>='9')"
and later cleared entire 'mybuff' instead of only 13th locations.
if we're only using 13th location, would have taken simple variable. is there any

significance that, array must used?


6)please explain
void init()
{
P0=0x00;
abc=0;
TL1=0XFD; //9600 @ 11.0592
TH1=0xFD;
TMOD=0x20;
SCON=0x50;
TR1=1;
}



7)why 'interrupt 4' is mensioned in
"void serial () interrupt 4 {...}"


8)what is response(k) in
" if((ch == Response[k]) || (k > 4))"



project is, controller must read sms. And accordingly, particular port must turn

on/off. Right now, m gonna control only two appliances, fan and light
so the sms format is,
i] LIGHT ON
ii] LIGHT OFF
iii] FAN ON
iv] FAN OFF

and here's edited program:

#include<reg51.h>
#include<string.h>
//#include<absacc.h>
//#include<stdlib.h>
//#include<ctype.h>
#define buffer 30


void delay(unsigned int i);
void tx0(unsigned char);
void SMSString(unsigned char*text) ;
void init();
void clear(void);
void read_notification();
void clear_mybuff();
void delete_msg(void);
void read_no(unsigned char msg_array[]);
void store_msg(unsigned char msg_array[]);
unsigned char abc,apt=0,count=0;
unsigned char idata msg1[buffer];
//unsigned char rec_no[10];
//unsigned char time_date[10];
unsigned char code Response[] = "+CMTI";

// Moblie no.of Owner
unsigned char code Mob_no[]= "9632949290";
//unsigned char code Pass_array[]="1234";
unsigned char MyBuff[20], k = 0;
bit flag1=0;
unsigned char store[10];
bit NewMessage = 0;
bit TI_flag = 0;
bit flag=0;
bit No_correct=0;

void main ()
{

//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
// unsigned char t;

clear();
delay(10);
init();
IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2)
SMSString("AT\r"); // AT commands to initialize gsm modem
delay(50);

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

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

SMSString( "AT+CMGF=1\r"); // select text mode for sms
delay(50);

SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
while(1)
{

IE=0x91;
k=0;
delay(10);
flag=0;
while(!NewMessage);
{
IE=0X00;
delay(10);
NewMessage = 0;
read_notification();
}
//New msg indication.
// +CMTI: "SM",3
}

}
void read_notification()
{
clear();
SMSString("AT+CMGR=");
tx0(MyBuff[12]);
SMSString("\r");
IE=0x90;
delay(200);
read_no(msg1);
IE=0x00;
if(No_correct==1)
{
store_msg(msg1);

if((store[0]=='L')||(store[0]=='l'))
{
if((store[7]=='N')||(store[7]=='n'))
P1=0x01||P1;
else
P1=0xFE&&P1;
}
else if((store[0]=='F')||(store[0]=='f'))
{
if((store[5]=='N')||(store[5]=='n'))
P1=0x02||P1;
else
P1=0xFD&&P1;
}

}

clear();

if(MyBuff[12]>='9') //After 9 msgs recieved it clears the Msg index from SIM
{
delete_msg();
}

clear_mybuff();

return;
}

void store_msg(unsigned char msg_array[])
{
unsigned char i,j;
i=59;
j=0;
while(msg_array[i]!='\r')
{
store[j]= msg_array[i]
;
i++;
j++;
}
return;
}

void delete_msg(void)
{
SMSString("AT+CMGD=9\r");
delay(1);
SMSString("AT+CMGD=8\r");
delay(1);
SMSString("AT+CMGD=7\r");
delay(1);
SMSString("AT+CMGD=6\r");
delay(1);
SMSString("AT+CMGD=5\r");
delay(1);
SMSString("AT+CMGD=4\r");
delay(1);
SMSString("AT+CMGD=3\r");
delay(1);
SMSString("AT+CMGD=2\r");
delay(1);
SMSString("AT+CMGD=1\r");
delay(1);
return;
}

void init()
{
P0=0x00;
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 serial () interrupt 4
{
unsigned char ch;
if(RI)
{
ch = SBUF; //character is read
RI = 0; //clear flag
if((ch == Response[k]) || (k > 4))
{
if(ch != 0x0D) // 0x0D means data received..
{
MyBuff[k++] = ch;
}
else
{
MyBuff[k] = '\0';
NewMessage = 1;
k = 0;
}
}
else
{
msg1[abc]=ch;//received msg is stored.
abc++;
k = 0;
}
}
}

void clear_mybuff()
{
unsigned int a;
for(a=0;a<25;a++)
MyBuff[a]=0x00;
}
void clear(void)
{
unsigned int a;
for(a=0;a<buffer;a++)
msg1[a]=0x00;
abc=0;
}

void read_no(unsigned char msg_array[]) // reads the no from received msg and

compares it with stored msg, If found wrong then send a msg to owner.
{
//unsigned char i;
if(Mob_no[0]==msg_array[23]&&
Mob_no[1]== msg_array[24]&&
Mob_no[2]==msg_array[25]&&
Mob_no[3]== msg_array[26]&&
Mob_no[4]==msg_array[27]&&
Mob_no[5]== msg_array[28]&&
Mob_no[6]==msg_array[29]&&
Mob_no[7]== msg_array[30]&&
Mob_no[8]==msg_array[31]&&
Mob_no[9]== msg_array[32])
{
No_correct=1;
}
else
{
No_correct=0;

return;
}
}


void delay(unsigned int i)
{
unsigned int k, l;
for(k=0;k<i;k++)
for(l=0;l<1000;l++);
}
Sat Mar 15 2014, 07:44 pm
#2
Guys, ..urgent***

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

SamuelSmise
Thu Apr 25 2024, 09:56 am
DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
Malcolmaccek
Wed Apr 24 2024, 01:21 am