#include<reg51.h>
void nominee(char[],int);
void lcd_cmd(char);
void lcd_init();
void lcd_data(char[]);
void delay(int);
void lcd_dataint(int);
void results();
sbit start=P1^0;
sbit n1=P1^1;
sbit n2=P1^2;
sbit n3=P1^3;
sbit rs=P2^0;
sbit oe=P2^1;
sbit again=P1^4;
sbit result=P1^5;
int nom[3]={0,0,0};
int overallC=0,permission=0;
void main()
{
n1=n2=n3=start=1;
oe=rs=0;
P3=0x00;
TMOD=0x01;
lcd_init();
while(1)
{
while(!start)
{
lcd_cmd(0x01);
lcd_cmd(0x8a);
lcd_data("welcome");
lcd_cmd(0xc0);
lcd_data("Please wait-");
while(again==1 )
{
if (result==0) results();
}
permission=1;
if(permission==1)
{
lcd_cmd(0x01);
lcd_data("Now vote your nominee-");
}
while(permission==1)
{
if(n1==0)
nominee("nominee1",0);
if(n2==0)
nominee("nominee2",1);
if(n3==0)
nominee("nominee3",2);
}
}
}
}
void nominee(char name[],int value)
{
nom[value]++;
overallC++;
lcd_cmd(0x01);
lcd_data("you have voted for ");
lcd_data(name);
lcd_cmd(0xc0);
lcd_data("your registered ID is-");
lcd_dataint(overallC);
delay(25);
permission=0;
}
void results()
{
delay(24);
if(result==0)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_data("N1 N2 N3");
lcd_cmd(0xc0);
lcd_dataint(nom[0]);
lcd_cmd(0xc7);
lcd_dataint(nom[1]);
lcd_cmd(0xcf);
lcd_dataint(nom[2]);
}
while(again==1);
}
void lcd_dataint(int p)
{
int a[5],i=0,j=0;
if(p==1)
P3=0x31;
while((p/10)!=0)
{
a[i]=p%10;
i++;
p=p/10;
}
a[i]=p;
i=4;
while(i>=0)
{
rs=1;
P3=48+a[i];
oe=1;
for(j=0;j<1000;j++);
oe=0;
i--;
}
}
void lcd_cmd(char x)
{
rs=0;
P3=x;
oe=1; //creating a pulse
delay(1);
oe=0;
}
void lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x06);
lcd_cmd(0x0E);
}
void lcd_data(char x[])
{
int i,j;
for(i=0;x[i]!='\0';i++)
{
rs=1;
P3=x[i];
oe=1;
for(j=0;j<5000;j++);
oe=0;
}
}
void delay(int n)
{
int i=0;
for(i=0;i<n;i++)
{
TR0=1;
while(TF0!=1);
TF0=0;
TR0=0;
}
}
Friday, February 24, 2012
Electronic Voting Machine
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment