LCD based voting machine using 8051 microcontroller (AT89C51

)
Introduction:
Electronic voting machine has now replaced the traditional mechanism of voting due to several advantages like security, automatic counting etc. This project presents a way to develop an electronic voting machine which displays the count of votes on a 16x2 LCD interface. A user can get his/her vote register through a set of switches (one for each candidate). After every cast of vote, the subsequent count can be seen on LCD. The circuit uses AT89C51 microcontroller and the code for the project has been written in C.

Description:
This LCD based electronic voting machine is designed for four candidates. The input part consists of a set of six tactile switches. The switches and 16x2 LCD are interfaced to microcontroller AT89C51 for various operations and displays.

The provision of casting votes for the candidates has been provided through four of these switches. These switches are made active high and connected to pins 2-5 (P1^1 ± P1^4) of the controller. The remaining two switches (both active low) are to start and stop the voting procedure. They are connected to pins 1 and 6 (P1^0 and P1^5) respectively. The Init (start) switch initializes the voting system when pressed, while the Stop switch ends the voting and displays the poll results on LCD screen.

For more details on working with LCD, refer LCD interfacing with 8051. The data pins of the LCD (pins 7-14) are connected to the output port P2 of the microcontroller. The control pins (RS, R/W and EN) are connected to port P3 pins P3^0, P3^1 & P3^6 respectively.

Working:
The voting is started by pressing the Init switch after which the user is prompted to vote. The count of votes is stored in four different variables. As soon as the user votes for a candidate

Page 1

the result is displayed which could be either declaration of the winner candidate or the candidates with a clash of their number of votes. Circuit Diagram: Code: // Program to make a voting machine using LCD #include<reg51.h> Page 2 . After this a Thank you message is displayed on LCD to acknowledge the registration of user¶s vote.by pressing one of the switches. The message stays on the screen until the next user either presses the Init button to cast another vote or Stop switch is pressed get the poll results. When the stop button is pressed. After some delay. the names of the candidates are displayed along with their vote counts. the value of the corresponding variable is increased by one.

sbit candidate_4=P1^4.k++).#define msec 50 #define lcd_data_str_pin P2 sbit rs = P3^0. //Candidate1 //Candidate2 //Candidate3 //Candidate4 int vote_amt[3]. en = 1. rs = 0.j--) { vote_amt[j]=vote%10. int carry = 0. rw = 0. int max = 0.j>=0. } return. rw = 0. //Enable(EN) pin sbit ini_pin = P1^0. } void lcd_data_str(char str[50]) { int p. unsigned int vote_1. void delay(int delay_time) { int j. } //Function to send command to LCD //Function to send string void lcd_data_int(unsigned int vote) { char dig_ctrl_var. //Register select (RS) pin sbit rw = P3^1. sbit candidate_3=P1^3.k<=1000.k. } // Time delay function void lcd_cmd(unsigned char cmd_addr) { lcd_data_str_pin = cmd_addr.vote_2.vote_4.j. en = 0. // Stop voting pin sbit candidate_1=P1^1. delay(1).p++) { lcd_data_str_pin = str[p]. delay(1). //Function to send 0-9 character values Page 3 . en = 1. for(j=0. //Read write(RW) pin sbit en = P3^6.str[p]!='\0'. return.vote_3. for (p=0. sbit candidate_2=P1^2. // Start voting pin sbit stop_pin = P1^5. en = 0.j<=delay_time. int arr[4]. int p.j++) for(k=0. for (j=2. rs = 1.

rs = 1. } for (p=0. rw = 0. lcd_cmd(0x0E). { vote_2 = vote_2 + 1. { vote_3 = vote_3 + 1. lcd_cmd(0x01). { vote_1 = vote_1 + 1.vote=vote/10.p<=2. Page 4 . } } if (candidate_3==1) { while (candidate_3 == 1). en = 1. } } } void lcd_ini() { lcd_cmd(0x38). en = 0. { vote_4 = vote_4 + 1. delay(msec).p++) { dig_ctrl_var = vote_amt[p]+48. } } if (candidate_4==1) { while (candidate_4 == 1). delay(msec). } void vote_count() // Function to count votes { while (candidate_1==0 && candidate_2==0 && candidate_3==0 && candidate_4==0). lcd_data_str_pin = dig_ctrl_var. } return. } } if (candidate_2==1) { while (candidate_2 == 1). if (candidate_1==1) { while (candidate_1 == 1). delay(1).

delay(msec). delay(100). delay(msec). delay(msec). lcd_cmd(0x01).delay(msec). lcd_cmd(0x8C). delay(100). lcd_data_str("button"). lcd_data_str("P4"). lcd_cmd(0x80). lcd_data_str("P1"). lcd_data_str("vote"). lcd_cmd(0xC0). delay(msec). lcd_data_str("to"). lcd_data_str("Thank"). delay(msec). } void results() { // Function to show results Page 5 . delay(msec). lcd_cmd(0x14). delay(msec). delay(msec). vote_count(). lcd_cmd(0x01). delay(msec). delay(msec). lcd_cmd(0x88). lcd_cmd(0x14). delay(msec). lcd_cmd(0x81). lcd_cmd(0x85). lcd_data_str("Welcome!!!"). delay(msec). delay(msec). delay(msec). lcd_data_str("You!!"). lcd_data_str("P2"). delay(msec). delay(msec). delay(100). lcd_data_str("P3"). delay(msec). delay(msec). delay(msec). delay(msec). delay(msec). lcd_cmd(0x14). delay(msec). lcd_cmd(0x80). lcd_data_str( "Press" ). lcd_cmd(0x01). delay(msec). lcd_cmd(0x84).

lcd_cmd(0x14). Page 6 . delay(msec). lcd_cmd(0x88). lcd_data_int(vote_1). delay(msec). delay(100). delay(msec). delay(msec). lcd_data_str("P1"). lcd_cmd(0x8C). delay(msec). lcd_data_int(vote_4). lcd_data_str("P3"). lcd_cmd(0x01). lcd_data_int(vote_3). lcd_cmd(0xC4). arr[0] = vote_1. carry = 0. delay(msec). delay(msec). lcd_cmd(0xC0). delay(msec). lcd_data_str("P2"). delay(msec). delay(300). lcd_cmd(0x01). lcd_cmd(0xCC). delay(msec). delay(msec). arr[1] = vote_2. delay(msec). delay(msec). arr[2] = vote_3. delay(msec). delay(msec). lcd_cmd(0xC8). delay(msec). lcd_data_str("P4"). lcd_data_str("Out").int i. delay(msec). lcd_cmd(0x80). lcd_cmd(0x80). delay(msec). delay(msec). delay(msec). lcd_data_str("Results"). delay(msec). lcd_data_int(vote_2). delay(msec). lcd_data_str("Are"). lcd_cmd(0x14). lcd_cmd(0x84).

delay(msec). lcd_data_str("P1"). delay(50). } if ( (vote_1 == max) && ( vote_2 != max) && (vote_3 != max)&& (vote_4 != max) ) { carry = 1. lcd_cmd(0x01). lcd_cmd(0x82). lcd_cmd(0x01). delay(msec). } if ( (vote_3 == max) && ( vote_2 != max) && (vote_1 != max)&& (vote_4 != max) ) { carry = 1. lcd_data_str("wins"). i<4. delay(msec). } if ( (vote_2 == max) && ( vote_1 != max) && (vote_3 != max)&& (vote_4 != max) ) { carry = 1. delay(msec). lcd_cmd(0x82). delay(msec). i++) { if(arr[i]>=max) max = arr[i]. delay(msec). for( i=0. delay(msec). lcd_data_str("Hurray!!!"). delay(msec). delay(msec). lcd_cmd(0xC4). lcd_cmd(0x82). lcd_cmd(0xC4). lcd_cmd(0x14). delay(50). delay(msec). delay(msec). lcd_data_str("Hurray!!!"). lcd_cmd(0x01). lcd_data_str("P2"). lcd_cmd(0xC4). delay(50). lcd_cmd(0x14). lcd_data_str("Hurray!!!").arr[3] = vote_4. delay(msec). delay(msec). lcd_data_str("wins"). delay(msec). Page 7 .

lcd_data_str("wins"). delay(50). lcd_data_str("between!!!"). delay(msec). delay(msec). lcd_data_str("P4"). delay(50). lcd_data_str("P4"). lcd_cmd(0x14). delay(50). lcd_cmd(0x14). if(vote_2 == max) { lcd_cmd(0xC5). delay(msec). } if (carry==0) { lcd_cmd(0x01). lcd_data_str("clash"). delay(50). lcd_cmd(0xC4). lcd_data_str("wins"). lcd_data_str("P3"). delay(msec). delay(50). lcd_cmd(0x14). } if(vote_3 == max) { lcd_cmd(0xC9). delay(msec). } if(vote_4 == max) { lcd_cmd(0xCD). lcd_cmd(0x82). delay(msec). delay(msec). lcd_cmd(0x01). delay(msec). delay(50). lcd_data_str("P3"). delay(msec). delay(msec). lcd_data_str("Hurray!!!"). delay(msec).delay(msec). lcd_data_str("P2"). } if ( (vote_4 == max) && ( vote_2 != max) && (vote_3 != max)&& (vote_1 != max) ) { carry = 1. delay(msec). lcd_cmd(0x82). } Page 8 .

delay(msec). } while(1) { results(). lcd_cmd(0x38). delay(msec). lcd_cmd(0x0E). delay(100). lcd_data_str("init"). lcd_cmd(0x14). } if (stop_pin == 0) { break. lcd_cmd(0x80).} } void main() { ini_pin = stop_pin = 1. lcd_data_str("to"). } } Page 9 . delay(msec). vote_1 = vote_2 = vote_3 = vote_4 = 0. delay(msec). lcd_cmd(0x14). lcd_cmd(0x01). delay(msec). lcd_cmd(0xC0). lcd_data_str( "Press" ). delay(msec). while(1) { while(ini_pin != 0) { if (stop_pin == 0) break. delay(msec). delay(msec). } lcd_ini(). delay(msec). candidate_1 = candidate_2 = candidate_3 = candidate_4 = 0. lcd_data_str("begin"). delay(msec). delay(msec).

Sign up to vote on this title
UsefulNot useful