Election Voting System using 8051(AT89C51) MicroController with Embedded C. This code is verified in Trainer Kit System Designed by ALS(Advanced Electronics Systems).
The Election Voting System is interfaced using keypad and LCD with 8051 Microcontroller.
; 8051 ASSEMBLY CODE -- CODESEXPLORER BLOG
; ELECTION VOTING SYSTEM
; PROGRAMMER NAME: ABHAY KAGALKAR
#include<at89c51xd2.h&rt;
sbit RS=P1^7;
sbit EN=P1^6;
void keypad();
void dispVote(int);
void dispResult();
void Lcd4_initialize();
void Lcd4_Print_String(unsigned char str[]);
void Lcd4_Clear();
void delay(int x);
void disp(void);
unsigned char j;
unsigned char i;
unsigned char cmdVar;
unsigned char dataVar;
unsigned char tempVar;
unsigned char ROW[4]={0xfe,0xfd,0xfb,0xf7}; // ROW
unsigned char r[9]={0xed,0xeb,0xe7,0x77}; // CONFUGURING PIN 1,2,3,F
int bjp=0,cong=0,aap=0; // VARIABLES FOR COUNTING VOTES
int main()
{
unsigned char wel[]={"Welcome to EVM"};
Lcd4_initialize(); // INITIALISE LCD AND TO ENABLE IT
Lcd4_Print_String(wel);
delay(5000);
disp();
while(1)
{
keypad(); // GETTING INPUT FROM KEYPAD
}
Lcd4_Clear(); // TO CLEAR LCD & BRING CURSOR TO FIRST
}
// FUNCTION TO DISPLAY INFO ABOUT CANDIDATES
void disp(void)
{
unsigned char inf1[]={"BJP - 1"};
unsigned char inf2[]={"CONG -2"};
unsigned char inf3[]={"AAP - 3"};
Lcd4_Print_String(inf1);
delay(5000);
Lcd4_Print_String(inf2);
delay(5000);
Lcd4_Print_String(inf3);
delay(5000);
}
// KEYPAD FUNCTION TO GET INPUT VOTE
void keypad()
{
while(1)
{
for(i=0;i<4;i++)
{
P0=ROW[i];
for(j=0;j<9;j++)
{
if(P0==r[j])
{
dispVote(j);
}
}
delay(100);
}
}
}
void dispVote(int vote)
{
unsigned char vot[]={"VOTED"};
unsigned char res[]={"Result..."};
if(vote==0)
{
++bjp;
Lcd4_Print_String(vot);
delay(100);
}
else if(vote==1)
{
++cong;
Lcd4_Print_String(vot);
delay(100);
}
else if(vote==2)
{
++aap;
Lcd4_Print_String(vot);
delay(100);
}
else if(vote==3)
{
Lcd4_Print_String(res);
dispResult();
}
else
{
delay(50);
}
}
// FUNCTION TO DISPLAY RESULT
void dispResult()
{
unsigned char err[]={"Same Vote"};
unsigned char res1[]={"BJP WON"};
unsigned char res2[]={"CONG WON"};
unsigned char res3[]={"AAP WON"};
if(bjp>cong && bjp>aap)
{
Lcd4_Print_String(res1);
delay(10000);
}
else if(cong>bjp && cong>aap)
{
Lcd4_Print_String(res2);
delay(10000);
}
else if(aap>bjp && aap>cong)
{
Lcd4_Print_String(res3);
delay(10000);
}
else
{
Lcd4_Print_String(err);
delay(1000);
}
}
// DELAY FUNCTION
void delay(int x)
{
int i=0;
for(i=0;i}
// FUNCTION TO SEND COMMANDS THE LCD IN 4 BIT MODE
void Lcd4_Commands()
{
tempVar=cmdVar;
cmdVar=cmdVar&0xF0;
P1=cmdVar>>4;
RS=0;
EN=1;
EN=0;
P1=tempVar&0x0F;
RS=0;
EN=1;
EN=0;
delay(60);
}
// LCD INITIALISE FUNCTION
void Lcd4_initialize()
{
unsigned int cmd[]={0x20,0x28,0x0e,0x06,0x80,0x01};
for(j=0;j<7;j++)
{
cmdVar=cmd[j];
Lcd4_Commands();
delay(500);
}
}
// FUNCTION TO SEND DATA TO LCD
void Lcd4_Data(void)
{
tempVar=dataVar;
dataVar=dataVar&0xF0;
P1=dataVar>>4;
RS=1;
EN=1;
EN=0;
P1=tempVar&0x0F;
RS=1;
EN=1;
EN=0;
delay(60);
}
// FUNCTION TO CLEAR LCD
void Lcd4_Clear()
{
cmdVar=0x01;
Lcd4_Commands();
delay(500);
}
void Lcd4_Set_Cursor()
{
cmdVar=0x80;
Lcd4_Commands();
delay(500);
}
// FUNCTION TO PRINT STRING, INPUT STRING
void Lcd4_Print_String(unsigned char str[])
{
Lcd4_Set_Cursor();
for(j=0;str[j]!=' ';j++)
{
dataVar=str[j];
Lcd4_Data();
delay(10000);
}
delay(20000);
Lcd4_Clear();
}