Discussion in "Embedded GSM Development" started by    kamal_nasir_2000    Dec 21, 2011.
Wed Dec 21 2011, 07:37 PM
#1
I am making "Sms based voting system" in which a voter will be give a 4 word password and and coice to select a candidate like 12345 in which 1234 is the user identity and 5 is theuser choice to select a candidate contesting in the election from a party. any invalid code will send an sms to the user with the notification of "vote not polled" i will very soon post the code any help will be warmely welcomed.

Thu Dec 22 2011, 04:56 AM
#2
Nice Concept,

All the best for ur coding.
Thu Dec 22 2011, 03:48 PM
#3
Can you plz answer me these questions

Fri Dec 23 2011, 04:27 AM
#4
Hi Kamal,

Ya off course you can check for OK msg.

Received msg is stored in array msg1[].Here they have used serial interrupt if you see in interrupt routine all SBUF is stored in msg1[].

read_text() is a funtion which segeregates the data present in msg1[] to date/time, mobile no, msg.

In above code its executed only once.

Check this link for more info.
http://www.8051projects.net/forum-t41321.html




Wed Jan 04 2012, 10:49 AM
#5
Here is my code for smsbased electronic voting system. plz evaluate it and do commants for any improvementsand if any one have GSM modem of mobile connected to protius plz test it. Thanks in advance. its a modification of array code givenin another thread. most of the coding is the same while adding new function for SMS BASED VOTING DEMONSTRATION.

#include <REGX52.H>

#define LCD P1
#define LCD_EN 0x80
#define LCD_RS 0x20

//LCD Commands

#define LCD_SETMODE 0x04
#define LCD_SETVISIBLE 0x08
#define LCD_SETFUNCTION 0x28
#define LCD_SETDDADDR 0x80


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 SMSString(char*text) ;
void init();
void read_text(unsigned char * , unsigned char * , unsigned char *);

void valid_user(unsigned char msg1[]);
unsigned char switch_func(unsigned char);

unsigned char j,abc;
unsigned char idata msg1[6];
unsigned char rec_no[20];
unsigned char time_date[20];

unsigned char invalid_vote[]="Vote Not Polled";
//unsigned char anp[]="ANP got = ";
//unsigned char ppp[]="PPP got = ";
//unsigned char mqm[]="MQM got = ";
unsigned char vote[]="Vote Polled";
unsigned char anpp;
unsigned char pppp;
unsigned char mqmm;
unsigned char choice;


void serial () interrupt 4
{
msg1[abc]=SBUF;
abc++;
RI=0;
}
/*
void show_result()
{

lcd_cmd(0x80); // ist line address
lcd_str(anp); // array having receipt no
lcd_cmd(0xC0); // 2nd line address
lcd_str(ppp); // array having date and time
lcd_cmd(0x94); // 3rd line address
lcd_str(mqm); // array having message
delay_sms(1000);
delay_sms(1000);
delay_sms(1000);

}
*/
void main (void)
{
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
delay_sms(2000);

IE=0X90; // Enable serial interrupt
delay_sms(500);

// i get a response like this
// +CMGR: "REC READ" ,"+923468117297","10/10/23,14:29:33+04"
// 1234.3(my messege in which 1234 it the voter pin number and 3 is the selection between contesters)
// Ok. */

// read sms and store in buffer msg1

read_text(msg1,rec_no,time_date);
clear();
IE=0X00; // Disable all interrupt
valid_user(msg1);
//show_result();
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';

valid_user(msg1); //fucntion is called to send the extracted messege 1234.5 in array MSG1 to valid_user function


//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_reset()
{
LCD = 0xFF;
delay_sms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delay_sms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delay_sms(5);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delay_sms(5);
LCD = 0x02+LCD_EN;
LCD = 0x02;
delay_sms(5);
}


void lcd_init ()
{
lcd_reset();
lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font.
lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink.
lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display shift.
lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h.
}

void lcd_cmd (char cmd)
{
LCD = ((cmd >> 4) & 0x0F)|LCD_EN;
LCD = ((cmd >> 4) & 0x0F);

LCD = (cmd & 0x0F)|LCD_EN;
LCD = (cmd & 0x0F);

delay_sms(1);
}

void lcd_data (unsigned char dat)
{
LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
LCD = (((dat >> 4) & 0x0F)|LCD_RS);

LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
LCD = ((dat & 0x0F)|LCD_RS);

delay_sms(1);
}

void clear(void)
{
unsigned char a;
for(a=0;a<6;a++)
msg1[a]=0x00;
}

void lcd_str (unsigned char *str)
{
while(*str){
lcd_data(*str++);
}
}

void valid_user(unsigned char msgrr[])
{

if(msgrr[0]=='1' && msgrr[1]=='2' && msgrr[2]=='3' && msgrr[3]=='4')// user 1
{
if((switch_func(msgrr[5]))==1){lcd_str(vote);}
else{lcd_str(invalid_vote);}

}
else if(msgrr[0]=='2' && msgrr[1]=='3' && msgrr[2]=='4' && msgrr[3]=='5')// user 2
{
if((switch_func(msgrr[5])==1)){lcd_str(vote);}
else{lcd_str(invalid_vote);}
}
else if(msgrr[0]=='3' && msgrr[1]=='4' && msgrr[2]=='5' && msgrr[3]=='6')// user 3
{
if((switch_func(msgrr[5]))==1){lcd_str(vote);}
else{lcd_str(invalid_vote);}
}
else if(msgrr[0]=='4' && msgrr[1]=='5' && msgrr[2]=='6' && msgrr[3]=='7')// user 4
{
if((switch_func(msgrr[5]))==1){lcd_str(vote);}
else{lcd_str(invalid_vote);}
}
else
{
lcd_cmd(0x80); // ist line address
lcd_str(invalid_vote); // Print Vote not Polled the error is here it always come yo this point and never gose to the other place why/
}
}
unsigned char switch_func(unsigned char contest)
{
if(contest=='1')
{
anpp = anpp+1;
return(1);
}
else if (contest=='2')
{
pppp = pppp+1;
return(1);
}
else if(contest=='3')
{
mqmm = mqmm+1;
return(1);
}
else
{
//lcd_cmd(0x80); // ist line address
//lcd_str(invalid_vote); // Print Vote not Polled
return(0);
}
}

Thu Jan 05 2012, 04:38 AM
#6
U have to wait to receive msg first then u need to proceed for reading the msg.
Do like this
void main ()
{
        clear();
        lcdinit();
        init();
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
IE=0x90;
delay(10);

while(!NewMessage);
{
NewMessage = 0;
read_notification();
IE=0x90;
}
//New msg indication.
// +CMTI: "SM",3
}

void read_notification()
{
        IE=0x00;
        clear();
        SMSString("AT+CMGR=");
        tx0(MyBuff[12]);
        SMSString("\r");
        IE=0x90;
        delay(100);
        read_text(msg1,rec_no,time_date);
        clear();

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_flag);
        TI_flag = 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 received character is there in Response or i is >
 4 which means
              // you already have the right string...
           if(ch != 0x0D) // 0x0D means data received..
                   {
                  MyBuff[k++] = ch;
           }
                   else
                   {
                //seems like we have recieved our data
                //Now stop and indicate that new message has received
                        MyBuff[k] = '\0';
                NewMessage = 1;
                k = 0;
            }
       }
                else
                {
                        msg1[abc]=ch;//received msg is stored.
                        abc++;
                k = 0;
        }
        }
        if(TI)
                {
        //if its a tx interrupt
        //clear TI
                TI = 0;
        //set a flag to indicate tx has completed
            TI_flag = 1;
        }
}

}

Dont you have modem?
R else u can check on proteus only there is virtual terminal is avialiable.
Fri Jan 06 2012, 08:09 PM
#7
Thanks kirangowle ya i have gsm modem sim900d and have simulated it with protius. the result is in the picture. i think the messege is not extracted correctely.

Sat Jan 07 2012, 04:31 AM
#8
You try once in hardware and check the result. It ll definitely work. Many of them have tried those codes.
Sat Jan 07 2012, 10:07 PM
#9
message is extracted on the go..

are you testing in proteus using real modem? if not are you sure you're simulating everything correctly? i.e. \r and \n specially?
Sun Jan 08 2012, 08:11 AM
#10
i am testing it in protius with compim ie connecting the real modem through serial port to the protius. where is the fault? i think it is in the mesege extraction ie the messege 1234.5 have not been extracted correctely to the unsigned char idata msg1[6] by void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time); function. my messege was correct(1234.1) but still it show wote not polled why? thanks for the help, guiding me and takin keen interest.

Get Social

Information

Powered by e107 Forum System

Conversation

Sarvn
Sat Jul 22 2017, 05:12 PM
I wnt to learn embedded could anyone help me
Sarvn
Sat Jul 22 2017, 05:11 PM
Hi
Wed Jul 12 2017, 02:34 PM
Ushiwaka
Any good guides on how to interface an 8255 w/ an 8051?
Tue Jul 11 2017, 06:22 PM
Chiko
i need seconds added to this circuit, can you help me modify it and add codes too
ExperimenterUK
Thu Jul 06 2017, 01:25 AM
@martinsnc115877 The hex file is here http://www.8051projects.net/forum-t65048-post.html
martinsnc115877
Sun Jul 02 2017, 04:28 PM
sir, sorry for the disturbance I can find the small and capital letter,hex file, please send it to me
Sun Jul 02 2017, 11:45 AM
Sam Raj
Can I have the circuit of Simple Digital Voltmeter using 8051
ExperimenterUK
Sun Jul 02 2017, 02:09 AM
Read this http://www.8051projects.net/forum-t65048-post.html. The project download contains lower case letters. It is compiled in Keil
martinsnc115877
Sat Jul 01 2017, 10:45 PM
I mean scrolling massage display using 8051 by pratrik suthar, the hex file I have is just only the capital letters I need the capital letters and the small letters hex, and I will like to no the compiler name he used for the code thanks
ExperimenterUK
Sat Jul 01 2017, 09:13 PM
@martinsnc115877 which project..link ?

Downloads

Comments

Sarvn
Sat Jul 22 2017, 11:34 AM
diablom
Fri Jul 21 2017, 01:44 PM
Alihaider.007
Thu Jul 20 2017, 03:07 PM
Vijaykumarsharma
Fri Jul 14 2017, 11:08 AM
varma495
Tue Jul 11 2017, 01:55 AM
Ramweit
Sat Jul 08 2017, 01:42 PM
Ben_J1
Fri Jul 07 2017, 04:32 PM
labsdg
Fri Jul 07 2017, 02:58 AM

Online

Guests: 47, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37860
Newest member: Sarvn
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jul 20 2017, 04:08 PM
can it be possible ?? Alihaider.007No.You will nee...
Alihaider.007 Avatar
Posted By Alihaider.007
Thu Jul 20 2017, 03:14 PM
Sir I am using AT89S8253 I have trying to use this...
Utsavi Avatar
Posted By Utsavi
Mon Jul 17 2017, 09:57 AM
Hello Ajay_Bhargav,Thanks for your reply. Yes, you...
ajay_bhargav Avatar
Posted By ajay_bhargav
Mon Jul 17 2017, 06:41 AM
I do not think it would be a good idea to kind of ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Mon Jul 17 2017, 06:32 AM
Tasking EDE has linker script facility available y...
Ramweit Avatar
Posted By Ramweit
Thu Jul 13 2017, 06:58 AM
Thank you for response,Sim300 gsm Modem am using h...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jul 11 2017, 04:20 PM
After the SMS is sent the modem should respond+CMG...
Ramweit Avatar
Posted By Ramweit
Tue Jul 11 2017, 02:37 PM
From this code gsm modem sending SMS to mobiles mu...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jul 10 2017, 06:09 PM
@RamweitWhat is it you want to know ?
Ramweit Avatar
Posted By Ramweit
Sat Jul 08 2017, 02:12 PM
#include<reg51.h>#include<stdio.h>bit moreov...