Discussion in "Embedded GSM Development" started by    kamal_nasir_2000    Dec 22, 2011.
Thu Dec 22 2011, 01:07 am
#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, 10:26 am
#2
Nice Concept,

All the best for ur coding.
Thu Dec 22 2011, 09:18 pm
#3
Can you plz answer me these questions

Fri Dec 23 2011, 09:57 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, 04:19 pm
#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, 10:08 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.
Sat Jan 07 2012, 01:39 am
#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, 10:01 am
#8
You try once in hardware and check the result. It ll definitely work. Many of them have tried those codes.
Sun Jan 08 2012, 03:37 am
#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, 01:41 pm
#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

Downloads

Comments

AntoniaRoons
Fri Apr 19 2024, 09:59 pm
carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am