Voting_Machine:
Code:
#include <avr/io.h>
#include"lcd_header.h"
#define bjp PD3
#define aap PD4
#define cong PD5
#define oth PD6
#define results PD2
#define party PIND
#define vote PORTC
#define buzzer PA7
unsigned int count1,count2,count3,count4;
unsigned char result1[3],result2[3],result3[3],result4[3];
int temp=0;
char rfid[13];
void clear();
void serialinit()
{
UCSRB=0x18;
UCSRC=0x86;
UBRRL=0x33;
}
void beep()
{
PORTA|=1<<buzzer;
_delay_ms(200);
PORTA&=~(1<<buzzer);
}
void beep_long()
{
PORTA|=1<<buzzer;
_delay_ms(1000);
PORTA&=~(1<<buzzer);
}
int main(void)
{
DDRB=0xff;
DDRD=0x00;
DDRC=0xff;
DDRA=0xff;
lcd_init();
lcdstring(" Electronic ");
lcdcmd(192);
lcdstring("Voting Machine");
beep_long();
beep();
_delay_ms(2000);
clear();
serialinit();
while(1)
{
lcdcmd(1);
lcdstring("Place UR Card:");
for(int i=0;i<12;i++)
{
while(!(UCSRA & (1<<RXC)));
rfid[i]=UDR;
}
rfid[12]='\0';
beep();
beep();
lcdcmd(1);
lcdstring("Your Card No is:");
lcdcmd(192);
lcdstring(rfid);
_delay_ms(2000);
if(strncmp(rfid, "1100006BB3C9",12)==0)
{
beep();
lcdcmd(1);
lcdstring("Authorized Voter");
lcdcmd(192);
lcdstring("Pls Cast UR Vote");
_delay_ms(2000);
//clear();
temp=1;
voting(temp);
}
else if(strncmp(rfid, "1600664C0E32",12)==0)
{
beep();
lcdcmd(1);
lcdstring("Authorized Voter");
lcdcmd(192);
lcdstring("Pls Cast ur Vote");
_delay_ms(2000);
//clear();
temp=1;
voting(temp);
}
else if(strncmp(rfid, "16006616C1A7",12)==0)
{
beep();
lcdcmd(1);
lcdstring("Please Press");
lcdcmd(192);
lcdstring("Result Button");
PORTD=0xFF;
while((party&(1<<results)));
if(!(party&(1<<results)))
{
beep();
if(count1 || count2 || count3 || count4)
{
if(count1 > count2 && count1>count3 && count1>count4)
Result("BJP Won");
else if(count2 > count1 && count2 > count3 && count2>count4)
Result("AAP Won");
else if(count3 > count2 && count3 > count1 && count3 > count4)
Result("Cong Won");
else if(count4 > count2 && count4 > count1 && count4 >count3)
Result("Oth Won");
else if(count1 == count2 || count3==count4 || count3 ==count1 || count2==count4)
Result("Tie");
}
else
{
beep_long();
lcdcmd(1);
lcdstring("No Voting...");
_delay_ms(2000);
clear();
}
beep();
}
_delay_ms(1000);
}
else
{
PORTA|=1<<PA7;
lcdcmd(1);
lcdstring(" UnAuthorised ");
lcdcmd(192);
lcdstring(" Voter ");
_delay_ms(2000);
PORTA&=~(1<<PA7); // buzzer
}
}
}
void voting(int temp)
{
lcdcmd(1);
lcdstring("BJP AAP Cong OTH");
while(temp)
{
PORTD=0xff;
lcdcmd(0xc1);
lcdstring(result1);
lcdcmd(0xc5);
lcdstring(result2);
lcdcmd(0xc9);
lcdstring(result3);
lcdcmd(0xcd);
lcdstring(result4);
if(!(party&(1<<bjp)))
{
beep();
count1++;
sprintf(result1,"%d",count1);
while(!(party&(1<<bjp)));
temp=0;
}
else if(!(party&(1<<aap)))
{
beep();
count2++;
sprintf(result2,"%d",count2);
while(!(party&(1<<aap)));
temp=0;
}
else if(!(party&(1<<cong)))
{
beep();
count3++;
sprintf(result3,"%d",count3);
while(!(party&(1<<cong)));
temp=0;
}
else if(!(party&(1<<oth)))
{
beep();
count4++;
sprintf(result4,"%d",count4);
while(!(party&(1<<oth)));
temp=0;
}
}
_delay_ms(1000);
}
void Result(char *str)
{
lcdcmd(1);
lcdstring(str);
clear();
}
void clear()
{
count1=0;
count2=0;
count3=0;
count4=0;
sprintf(result1, "%d", count1);
sprintf(result2, "%d", count2);
sprintf(result3, "%d", count3);
sprintf(result4, "%d", count4);
_delay_ms(2000);
lcdcmd(1);
lcdstring("BJP AAP Cong OTH");
}
lcd_header:
#define F_CPU 8000000UL
#include <util/delay.h>
#define rs 0
#define rw 1
#define en 2
void cmnd()
{
PORTB&=(~(1<<rs));
PORTB&=(~(1<<rw));
PORTB|=(1<<en);
_delay_ms(5);
PORTB&=(~(1<<en));
}
void lcdcmd(char ch)
{
PORTB=ch & 0xf0;
cmnd();
PORTB=(ch<<4) & 0xf0;
cmnd();
}
void lcd_init()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
void data()
{
PORTB|=(1<<rs);
PORTB&=(~(1<<rw));
PORTB|=(1<<en);
_delay_ms(5);
PORTB&=(~(1<<en));
}
void lcddata(char ch)
{
PORTB=ch & 0xf0;
data();
PORTB=(ch<<4) & 0xf0;
data();
}
void lcdstring(char *str)
{
while(*str)
{
lcddata(*str);
str++;
}
}
Simulation:
0 comments:
Post a Comment
if you have any doubt please let me know