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

Fri Sep 29 2017, 02:45 AM
Maaz
i am doing the same project on verilog please contact me [email protected]
Wed Sep 20 2017, 12:36 AM
Ted
In a missing pulse detector using a 555 timer connected as a monostable vibrator with a PNP transistor,how does the positve input pulse turn on the PNP transistor?
Sun Sep 03 2017, 02:29 PM
martymarty
How do I connect an <NOKIA 1100 LCD > to an atmega328P ?
poojab51296
Sun Aug 20 2017, 10:23 AM
i am intending to interface sd card with STM32F4 and want to write a file in sd card using SPI protocol but using HAL only. Can anyone help me PLEASE!!!!
poojab51296
Sun Aug 20 2017, 10:22 AM
hello
rawat742
Fri Aug 18 2017, 11:37 AM
hi @ angel patel i will attach a file i hope it will be helpfull for you
ExperimenterUK
Mon Aug 14 2017, 09:57 PM
@ angel patel... just log in and post your problem
Mon Aug 14 2017, 01:45 PM
angel patel
hey any one help to make the led scrolling display
desuza6
Sat Jul 29 2017, 07:09 AM
I see the code for step motor h l 298 to rotate 45 degree, but all delay time, if I want to input sensor to h the pulses to stepmotor
rammichael
Thu Jul 27 2017, 12:05 PM
okay fine

Downloads

Comments

bvdb
Wed Oct 18 2017, 01:45 AM
TinkeringJoe
Sun Oct 15 2017, 02:23 AM
Tubai96
Thu Oct 12 2017, 05:30 PM
roberttku
Thu Oct 12 2017, 08:02 AM
Bdavid.sam
Mon Oct 09 2017, 02:23 PM
SUNSHINE
Thu Oct 05 2017, 03:54 AM
Dogg4live77
Wed Oct 04 2017, 01:58 AM
RajeSH190295
Mon Oct 02 2017, 10:08 AM

Online

Guests: 72, Members: 0 ...

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

Members: 37902
Newest member: bvdb
Forum Activity
bvdb Avatar
Posted By bvdb
Wed Oct 18 2017, 01:50 AM
I purchased the RKitL51 8051 C compiler from Raiso...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Oct 16 2017, 11:44 PM
That looks complicated.Is 8051_BLK a standard 80...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 15 2017, 07:29 PM
According to this, gmail should support POP3.https...
Help Avatar
Posted By Help
Sun Oct 15 2017, 03:21 AM
AT+POP3READ=? +POP3READ: (1-1460) OK AT+POP3READ=...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Oct 14 2017, 08:06 PM
What happens if you ask for the full email ieAT+PO...
Help Avatar
Posted By Help
Sat Oct 14 2017, 02:28 AM
Dear all, AT // OK // 3.1 Bearer profile // Conf...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Oct 12 2017, 01:04 AM
I don't think the 0804 works as it should in Prote...
Bdavid.sam Avatar
Posted By Bdavid.sam
Wed Oct 11 2017, 01:54 AM
Are you simulating in Orcad ?Please post your cod...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 10 2017, 09:43 PM
Are you simulating in Orcad ?Please post your cod...
Bdavid.sam Avatar
Posted By Bdavid.sam
Mon Oct 09 2017, 02:38 PM
Hello, This might be a beginner’s mistake but I a...