Você está na página 1de 6

Electronic voting machine using seven segment multiplexing with 8051 microcontroller (AT89C51)

This topic presents a basic approach to develop an electronic machine. The idea is to display the count of votes on a set of seven segment displays. A set of switches are provided through which a user can cast vote. After every cast of vote, the subsequent count can be seen on the seven segments. The segments and switches are controlled through AT89C51. For every candidate, a segment has been provided.
This voting machine is designed for four candidates. The provision of casting vote has been provided by means of four tactile switches. These switches take manual inputs from the user and transfer them to the pins of controller. Based on these inputs, the vote count for different candidates is increased byAT89C51. To display the vote count, four seven segment displays are also connected to the microcontroller (refer seven segment interfacing with AT89C51). The count value for each candidate is sent to the corresponding segment. The four counts appear continuously by multiplexing these segments through AT89C51. Pins 2-5 of the port P3 are configured to take inputs through switches connected to them. The data pins of the seven segments are connected to port P2. Pins 0-3, of port P1, are configured as output to act as control/enable pins of the seven segments.

Program: // Program to make voting machine using seven segment #include <reg51.h> #define msec 1

sbit switch_1=P3^2;//Input pins for four candidates sbit switch_2=P3^3;

sbit switch_3=P3^4; sbit switch_4=P3^5;

sbit dig_ctrl_4=P1^0;//Declare the control pins of seven segments sbit dig_ctrl_3=P1^1; sbit dig_ctrl_2=P1^2; sbit dig_ctrl_1=P1^3;

unsigned int vote_1,vote_2,vote_3,vote_4;

unsigned int digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10}; unsigned int dig_1,dig_2,dig_3,dig_4;

void delay(unsigned int count)// Time delay function { unsigned int j,k; for (j=0;j<=count;j++) for (k=0;k<=50;k++); }

void digi_out(unsigned int current_num)// Funtion to display total votes { unsigned int dig_disp; dig_disp=current_num; P2 = digi_val[current_num]; delay(msec);

void calc_vote()// Funtion to count the number of votes { while(1) { if (switch_1==0) { while (switch_1 == 0);//check if switch 1 is pressed { vote_1 = vote_1 + 1; if(vote_1==10) vote_1=0; } }

if (switch_2==0)//check if switch 2 is pressed { while (switch_2 == 0); { vote_2 = vote_2 + 1; if(vote_2==10) vote_2=0; } }

if (switch_3==0)//check if switch 3 is pressed {

while (switch_3 == 0); { vote_3 = vote_3 + 1; if(vote_3==10) vote_3=0; } }

if (switch_4==0)//check if switch 4 is pressed { while (switch_4 == 0); { vote_4 = vote_4 + 1; if(vote_4==10) vote_4=0; } }

dig_ctrl_1 = 1; dig_ctrl_3 = dig_ctrl_2 = dig_ctrl_4 = 0; digi_out(vote_1); dig_ctrl_2 = 1; dig_ctrl_4 = dig_ctrl_3 = dig_ctrl_1 = 0; digi_out(vote_2); dig_ctrl_3 = 1; dig_ctrl_2 = dig_ctrl_4 = dig_ctrl_1 = 0; digi_out(vote_3); dig_ctrl_4 = 1; dig_ctrl_3 = dig_ctrl_2 = dig_ctrl_1 = 0;

digi_out(vote_4); } }

void main() { vote_1 = vote_2 = vote_3 = vote_4 = 0; switch_1 = switch_2 = switch_3 = switch_4 = 1;// Initialize the input pins while(1) { calc_vote(); } }

Components:

Transistor BC547

BC547 is an NPN bi-polar junction transistor. A transistor, stands for transfer of resist current. A small current at its base controls a larger current...

22,065-Reads

Seven Segment Display

A seven segment display is the most basic electronic display device that can disp

application in devices that display numeric information like digital clocks, radio, microw
21,300-Reads

AT89C51 Microcontroller

AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. ATMEL 89C5 and erasable read only memory (...

52,408-Reads

Você também pode gostar