Você está na página 1de 36

WOLLO UNIVERSITY

(KOMBOLCHA INSTITUTE OF TECHNOLOGY)

DEPARTMENT OF ELECTRICAL AND COMPUTER


ENGINEERING (ELECTRONIC COMMUNICATION)
SEMISTER PROJECT (ECEG 4302)
2015 SEMESTER II
PROJECT TITLE:
ELECTRONIC VOTING MACHINE

UNDER SUPERVISION OF
MR. AREBU D.

Acknowledgement
We would like to express our deepest appreciation to all those who
provided us the possibility to complete this report. A special gratitude we
give to our supervisor, Arebu D.whose contribute in stimulating suggestions
and encouragement, helped us to coordinate our project especially in
writing this report. We also would like to thanks our senior students(5th
year),We have to appreciate the guidance given by our seniors and friends
in our project presentation by giving their comments and advices. Last but
not least, we appreciate everyone who help us either directly or indirectly
to complete our mini project.

Abstract
Voting is most pivotal process of democratic society through which
people determine its decision. Nowadays electronic voting machine has
become an effective voting tool compare with traditional paper-based
voting schemes. Flawless voting is ensure by electronic voting machine.
This is the reason it became more widespread. People are make sure that
their vote is secured. One more feature is that it avoids any kind of
malpractice or invalid votes. Besides that, talking about economic benefits,
this system is more economical than traditional paper-based voting
schemes since the expenditure incurred on manpower is saved. It is also
make voter feels convenient because he or she has to press only one button
of the respective candidates to vote. Thus, we are decided to design an
electronic voting machine to replace the traditional paper-based voting
schemes due to several advantages like security, automatic counting,
economic etc.

This project presents a way to develop an electronic voting machine


by using a 16x2 LCD. The electronic voting machine contains 4 reset
switches which are New Entry switch, 2 switches for 2 candidates, and a
Result switch. The New Entry switch is to avoid any kind of malpractice or
invalid votes. The New Entry switch is under supervision and control of a
conservator and a user can only vote after the New Entry is pressed.
Besides that, the electronic voting machine only allows 1 vote for each user.
If any user tries to press the switch multiple times to vote more, only the
first vote will be registered. The 2 switches represent the respective
candidates, voter can vote to the candidate that he or she desired to vote by
press the switch that represents the candidate. The result will only display
on the LCD screen at the end when the Result switch is press. So that, the
result would not affect the decision of the voter during the voting process is
on the way. Of course, the Result switch also under supervision and control
of a conservator. Finally the number of votes of respective candidate will
display on LCD and we can know that which candidate is won when the
Result switch is pressed.

CONTENTS
Chapter one: Introduction
1.1 Introduction......................................................................................................................................................
1.2 Project overview............................................................................................................................................
1.3 Objective of project.......................................................................................................................................
Chapter two: Literature Review......................................................................................................................
Chapter Three: Methodology
3.1 How does the system work?....................................................................................................................
3.2 List of component...........................................................................................................................................
3.3 Hardware description..................................................................................................................................
3.4 Schematic diagram..........................................................................................................................................
3.5 Block diagram.....................................................................................................................................................
3.6 Flow chart..............................................................................................................................................................
Chapter Four: Software description
4.1 Keil u vision 4..............................................................................................................................
4.2 Proteus 8 professional.................................................................................................................
Chapter Five: Result and discussion
5.1 Problem statement and analysis................................................................................................
5.2 Result and discussion..................................................................................................................
Chapter Six: Conclusion
6.1 Conclusion...................................................................................................................................
6.2 Future work.................................................................................................................................
Appendix
References

Chapter one: Introduction


1.1 Introduction
This LCD based electronic voting machine is designed for two
candidates. The input part consists of a set of 4 switches. The switches and
16x2 LCD are interfaced to microcontroller for various operations and
displays. The provision of casting votes for the candidates has been
provided through 2 of these switches (one for each candidate). These
switches are made active high and connected to input pins of the controller.
The remaining 2 switches are New Entry and Result. The New Entry switch
initializes the voting system when pressed, while the Result switch ends
the voting and displays the result (total number of votes for respective
candidate) and winner on LCD screen. This system is set to 1 vote for each
voter. In other word, the voter cannot make the second vote even he or she
press the switch as long as the New Entry switch is press. Besides that, each
of the switches has connected to a 1k ohm resistor and a LED. The resistor
act as a pull down resistor which make the input normal LOW while the
LED is to indicate the switch is being press.
The main objective of this project is to design and create a general
electronic voting machine to replace the traditional paper-based voting
schemes so that we can take an advantages in term of economic and
convenient. Electronic voting machine is more economic because less
manpower is required and may save transportation cost due to its compact
size. It is also more convenient and time conscious as less time required for
voting and counting. Besides that, it is also more secure due to avoid invalid
voting such asa people make a vote twice. Other than that, paperbased voting can actually miss ballots due to human mistakes in placing
the paper-based ballot in the machine. But, this will be not happen at
electronic voting machine.
The following is the advantages of electronic voting machine:
1. It is economical
2. Less manpower required
3. Time conscious
4. Avoids invalid voting
5. Convenient

1.2 project overview


An embedded system is a combination of software and hardware
to perform a dedicated task. Some of the main devices used in embedded
products are Microprocessors and Microcontrollers. Microprocessors are
commonly referred to as general purpose processors as they simply accept
the inputs, process it and give the output. In contrast, a microcontroller not
only accepts the data as inputs but also manipulates it, interfaces the data
with various devices, controls the data and thus finally gives the result.
The Project Electronic Voting System based is an exclusive project that can
be used by the government instead of normal ballot paper system. By using
this system the saving of considerable printing stationery and transport of
large volumes of electoral material, easy transportation, storage, and
maintenance, no invalid votes, reduction in polling time, resulting in fewer
problems in electoral preparations, law and order, candidates' expenditure,
etc. and easy and accurate counting without any mischief at the counting
centre, Eco friendly.
The entire process is very easy to understand:
1.

Like in earlier system, your name is called and you are asked to sign
or put your thumb impression in a register.

2.

After your identification is done by Election Officer, an ink mark is


put on your finger, same as earlier.

3.

Then the Election Officer gives you a slip that bears the Voter register
number where you signed or put your thumb impression.

4.

You hand over this slip to the presiding officer who confirms the
serial number and permits you to vote by pressing the button of the
Control Unit of EVM.

5.

You are not given any ballot thereafter, and are sent to the EV
Machine placed behind a card board in a corner. The machine is
placed in such a way that your polled vote will be a secret.

6.

On the EVM, you press the switch placed in front of your favorite
candidate and release.

7.

As soon as the button is pressed, the LED indicator lights off and a
buzzer sound comes from the machine. This signifies that your vote
has been casted rightly. Now you can come out.

After the hour fixed for the close of the poll and the last voter has recorded
his vote, the EVM is closed so that no further recording of votes in the
machine is possible.

1.3 Objective of project


To program the Microcontroller 8051 to create an electronic voting
machine.
To interface the Microcontroller 8051 with 2x16 LCD screen.
To program the Microcontroller for automatic counting and secured
system
to define ballots
to cast and count votes

to report or display election results

to maintain and produce any audit


trail information

1.4 advantage and disadvantage of EVM


1.4.1 Advantages
It is economical.
Less manpower required
Time conscious, as less time required for voting & counting.
Avoids invalid voting.
Saves transportation cost due to its compact size.
Convenient on the part of voter.

1.4.2 Disadvantages
Security issues and unequal internet access.
We have to use external chip to store the votes.
We have provide continuous power supply,

Chapter Two: Literature Review


According to the electronic voting machine that designed by others,
we found that it is similar to our design. First of all, their security system
has control by 2 buttons. The first switch is New Entry switch to display the
Welcome from thanks after a vote has been casted. While the second
switch is Ready switch to indicate the voter ready to cast a vote. Then the
voter can only cast a vote after the New Entry is pressed and follow by
Ready button. Our security system is only control by one switch which is
New Entry switch. After a vote has been casted, our voting machine will be
display Welcome automatically from thanks after some delay. Then the
voter can only cast a vote after the New Entry switch has pressed.
Otherwise, any vote will not be counted. Besides that, their voting system is
designed for 4 candidates and the counter for number of votes for each
candidate can reach 3-digits number while we had designed for 2
candidates and the counter for number of votes for each candidate can only
reach 2-digits number. But, we can add the number of candidate and also
the counter by modified the program as well. Due to the time constraints
we designed this as a prototype.
Moreover, we had found that some weakness and flaw in their
system. We found that their electronic voting machine will display the
number of votes for respective candidates after a vote has been casted. This
phenomena may cause an unfair election happen due to the voter could tell
the next voter about the result. This may affect the decision of other voters.
Besides that, the guideline of the message that shown on LCD display not

really clear. The LCD screen will display nothing when the period for voter
ready to cast their vote. This may confused the users of this voting machine.
Thus, we are enhance the system by hide the number of votes for
each candidates as long as the Result button is pressed. Once the result are
out, the voting process is end and the LCD screen will declare the winner.
Next, we also enhance the guideline of the system by adding the message
Please vote during the period for voter ready to cast a vote. So that the
voter would not be confused.

Chapter Three: Methodology


3.1 How does it work?
First, the LCD screen will always display Welcome to vote! as long as the
voting is started by pressing the New Entry switch after which the user is
prompted to vote. Then, the LCD screen will display Please vote to
indicate the voter could start to cast a vote. The count of votes is stored in
two different variables. As soon as the user votes for a candidate by
pressing one of the switches, the value of the corresponding variable is
increased by one. After this, a Thank you message is displayed on LCD to
acknowledge the registration of users vote and the LCD screen will be
automatically display back Welcome to vote! after some delay. The
message will be stays on the screen until the next voter come and a
conservator presses the New Entry switch. Then the voter have to press the
switch to cast another vote and finally the Result switch is pressed to get
the poll results. When the Result button is pressed the names of the
candidates are displayed along with their vote counts. After some delay, the
result is displayed which could be either declaration of the winner
candidate or the candidates with a clash of their number of votes.

3.2 Component List


Component/Equipment

Quantity

8051 Development System

Light Emitted Diode (LED)

Reset Button Switch

1k ohm Resistor

2x16 LCD Screen

3.3 Hardware Description


Microcontroller board 8051
The 8051 Microcontroller was designed in
1980s by Intel. Its foundation was on
Harvard Architecture and was developed
principally for bringing into play in
Embedded Systems. At first it was created
by means of NMOS technology but as NMOS technology needs more power to
function therefore Intel re-intended Microcontroller 8051 employing CMOS
technology and a new edition came into existence with a letter C in the title
name, for illustration: 80C51. These most modern Microcontrollers need fewer
amount of power to function in comparison to their forerunners.
There are two buses in 8051 Microcontroller one for program and other for
data. As a result, it has two storage rooms for both program and data of 64K by
8 size. The microcontroller comprise of 8 bit accumulator & 8 bit processing
unit. It also consists of 8 bit B register as majorly functioning blocks and 8051
microcontroller programming is done with embedded C language using Keil
software. It also has a number of other 8 bit and 16 bit registers.
For internal functioning & processing Microcontroller 8051 comes with
integrated built-in RAM. This is prime memory and is employed for storing
temporary data. It is unpredictable memory i.e. its data can get be lost when
the power supply to the Microcontroller switched OFF.

8051 Pin Diagram & Description

For describing pin diagram and pin configuration of 8051, we are taking
into consideration a 40 pin DIP (Dual inline
package). Now lets go through pin configuration in
detail.
Pin-40 : Named as Vcc is the main power source.
Usually its +5V DC.
You may note some pins are designated with two
signals (shown in brackets).
Pins 32-39: Known as Port 0 (P0.0 to P0.7) In
addition to serving as I/O port, lower order
address and data bus signals are multiplexed with
this port (to serve the purpose of external memory
interfacing). This is a bi directional I/O port (the
only one in 8051) and external pull up resistors are
required to function this port as I/O.
Pin-31:- ALE aka Address Latch Enable is used to demultiplex the addressdata signal of port 0 (for external memory interfacing.) 2 ALE pulses are
available for each machine cycle.
Pin-30:- EA/ External Access input is used to enable or disallow external
memory interfacing. If there is no external memory requirement, this pin is
pulled high by connecting it to Vcc.
Pin- 29:- PSEN or Program Store Enable is used to read signal from external
program memory.

Pins- 21-28:- Known as Port 2 (P 2.0 to P 2.7) in addition to serving as I/O


port, higher order address bus signals are multiplexed with this quasi bi
directional port.
Pin 20:- Named as Vss it represents ground (0 V) connection.
Pins 18 and 19:- Used for interfacing an external crystal to provide system
clock.
Pins 10 17:- Known as Port 3. This port also serves some other functions
like interrupts, timer input, control signals for external memory interfacing
RD and WR , serial communication signals RxD and TxD etc. This is a quasi
bi directional port with internal pull up.
Pin 9:- As explained before RESET pin is used to set the 8051
microcontroller to its initial values, while the microcontroller is working or
at the initial start of application. The RESET pin must be set high for 2
machine cycles.
Pins 1 8:- Known as Port 1. Unlike other ports, this port does not serve
any other functions. Port 1 is an internally pulled up, quasi bi directional
I/O port.
Microcontroller board 8255
The Intel 8255A is a general purpose
programmable I/O device which is designed for
use with all Intel and most other
microprocessors. It provides 24 I/O pins which
may be individually programmed in 2 groups of
12 and used in 3 major modes of operation. In
MODE 0, each groups of 12 I/O pins may be programmed in sets of 4 and 8
to be inputs or outputs. In MODE 1, each group may be programmed to
have 8 lines of input or output. 3 of the remaining 4 pins are used for
handshaking and interrupt control signals. MODE 2 is a strobed bi-directional bus

configuration. The 8255 is a 40 pin integrated circuit (IC), designed to perform a variety
of interface functions in a computer environment. The 8255 wasnt originally designed
to be connected to the Z80. It was manufactured by Intel for the 8080 microprocessor.

D0 - D7 These are the data input/output lines for the


device. All information read from and written to the
8255 occurs via these 8 data lines.
CS (Chip Select Input). If this line is a logical 0, the
microprocessor can read and write to the 8255.
RD (Read Input) Whenever this input line is a logical 0
and the RD input is a logical 0, the 8255 data outputs
are enabled onto the system data bus.
WR (Write Input) Whenever this input line is a logical 0 and the CS input is
a logical 0, data is written to the 8255 from the system data bus
A0 - A1 (Address Inputs) The logical combination of these two input lines
determines which internal register of the 8255 data is written to or read
from.
RESET The 8255 is placed into its reset state if this input line is a logical 1.
All peripheral ports are set to the input mode.
PA0 - PA7, PB0 - PB7, PC0 - PC7 These signal lines are used as 8-bit I/O
ports. They can be connected to peripheral devices. The 8255 has three 8
bit I/O ports and each one can be connected to the physical lines of an
external device. These lines are labelled PA0-PA7, PB0-PB7, and PC0-PC7.
The groups of the signals are divided into three different I/O ports labelled
port A (PA), port B (PB), and port C (PC).

LCD2x16

The Serial LCDs are very functional,


liquid crystal displays that can be
easily interfaced to and controlled by a
microcontroller using an I/O pin. The LCD displays provide basic text wrapping
so that your text looks correct on the display. Full control over all of their
advanced LCD features allows you to move the cursor anywhere on the display
with a single instruction and turn the display on and off in any configuration.
They support the same visible characters as the Terminal (ASCII Dec 32-127). In
addition, you may define up to eight of your own custom characters to display
anywhere on the LCD. This device can be connected to a PC serial port using a
MAX232 line driver. The circuit isn't supported by us.
Resistor
Resistor

is

passive

two

terminal

components which widely use in the circuit.


Its function is to limit the current of the circuit. In this miniproject, we used
4 1k resistors as a pull down resistor for the 4 reset buttons.It also used
as a safety mechanism if a circuit exceeds safe margins.

LED

Light-Emitting Diode (LED) is a basic component we


widely use in the circuit. It usually connect in series
with resistor to emit light. We used the LED to
indicate the reset buttons have pressed.

Reset Button

In electronics and technology, a reset button is


a button that can reset a device. On video game
consoles. Reset buttons are found on circuit
breakers to reset the circuit. This button can cause
data corruption so this button often doesn't exist
on many machines. Usually, in computers and
other electronic devices, it is present as a small
button, possibly recessed into the case or only
accessible by a pin or similar thin object, to prevent
it being pressed accidentally.

3.4 SCHEMATIC DIAGRAM

3.5 BLOCK DIAGRAM FOR ELETRONIC VOTING


MACHINE
A block diagram is drawn to ease the understanding to connection of circuit
design. This block diagram explains roughly about the connection of the
microcontroller 8051, PPI 8255, 2x16 LCD screen and LEDs. Based on this
block diagram, we write the program code according to our circuit design.

4
switches/reset
buttons

8051

8255

4 LEDs
2x16 LCD
screen

3.6 Flow Chart


Start

LCD display:
WELCOME TO
VOTE!

Is the New Entry switch being press?

Is the Result switch being press?

NO

NO
YES

YES

LCD display:
PLEASE

LCD
display:
C1 C2

AFTER A

XX>Y
NO

Is the switch
that
represent
C1 being press?
YES

Is the switch that


NO
represent
C2 being press?

YES

The number of
votes for C1 +1

XX<Y

The number of
votes for C2 +1

LCD display:
CONGRATULATION
!!

LCD display:
CONGRATULATION
!!
C2 WINS!!!
XX=Y

LCD display:
DRAW!! PROCEED TO THE NEXT
VOTING...
AFTER A

LCD display:
THANK

Chapter Four: Software description


4.1 keil u vision4 compiler
Keil compiler is software used where the machine language code is written
and compiled. After compilation, the machine source code is converted into
hex code which is to be dumped into the microcontroller for further
processing. Keil compiler also supports C language code.
Its important that you know C language for microcontroller which is
commonly known as Embedded C. As we are going to use Keil C51
Compiler, hence we also call it Keil C.
Keil C is not much different from a normal C program. If you know
assembly, writing a C program is not a crisis. In Keil, we will have a main
function, in which all your application specific work will be defined. In case
of embedded C, you do not have any operating system running in there. So
you have to make sure that your program or main file should never exit.
This can be done with the help of simple while (1) or for (;;) loop as they
are going to run infinitely.
We have to add header file for controller you are using, otherwise you
will not be able to access registers related to peripherals.
#include <REG51.h> //header file for 89C51
To create a project, write and test the previous example source code, follow
the following steps:
1. Open Keil and start a new project
2. You will be prompted to choose a name for your new project, Create a
separate folder where all the files of your project will be stored, choose a

name and click save. The window will appear where you will be asked to
select a device for Target 'Target 1'
3. From the list at the left, seek for the brand name ATMEL, then under
ATMEL, select AT89S51. You will notice that a brief description of the
device appears on the right. Leave the two upper check boxes unchecked
and click OK. The AT89S52 will be called your 'Target device', which is the
final destination of your source code. You will be asked whether to 'copy
standard

8051

startup

code'

click

No.

4. Click File, New, and something similar to the following window should
appear. The box named 'Text1' is where your code should be written later.
5. Now you have to click 'File, Save as' and choose a file name for your
source code ending with the letter '.c'. You can name as 'code.c' for example
and click save. Then you have to add this file to your project work space at
the left as shown in the following
6. After right-clicking on 'source group 1', click on 'Add files to group...',
then you will be prompted to browse the file to add to 'source group 1',
choose the file that you just saved, eventually 'code.c' and add it to the
source group. You will notice that the file is added to the project tree at the
left.

7. In some versions of this software you have to turn ON manually the


option to generate HEX files. make sure it is turned ON, by right-clicking on
target 1, Options for target 'target 1', then under the 'output' tab, by
checking the box 'generate HEX file'. This step is very important as the HEX
file is the compiled output of your project that is going to be transferred to
the microcontroller.

8. You can then start to write the source code in the window titled 'code.c'
then before testing your source code; you have to compile your source
code, and correct eventual syntax errors. In KEIL IDE, this step is called
'rebuild all targets' and has this icon:

9. If after rebuilding the targets, the 'output window' shows that there is 0
errors, then you are ready to test the performance of your code. In keil, like
in most development environment, this step is called Debugging, and has
this icon:

. After clicking on the debug icon, you will notice that some part

of the user interface will change; some new icons will appear, like the run
icon circled in the following figure:

4.2 proteus 8 professional

Chapter five: Result and discussion


5.1 Problem statement and analysis
Problem 1:
When we display those message on LCD screen, we found that the
cursor on LCD screen keep on moving and it is too annoying for the user.
Solution:
We change the command to LCD from 0E(display on, cursor on) to
0C(display on, cursor off).

Problem 2:
We are going to display the number of votes of candidate that have
stored in register on LCD screen. Then, we realise that the LCD display the
other character instead of the number.
Solution:
We found that LCD can only read ASCII code and the number that
stored in the register is HEX code. By refer to the table of comparison
between ASCII code and HEX code, we found that we could convert the HEX
code to ASCII code by adding 30H for the numbering part. In other word,
30H will display 0 on LCD, 31H will display 1 on LCD.

Problem 3:
After we solved the problem 2, we are facing the other problem that
we can only display the single digit (0-9) to LCD screen due to only 0-9
available on ASCII code. Double digits such as 17, 23 will display the other
characters on LCD.
Solution:
First we move the number that stored in the register to Accumulator
and move 10H to register B. After that, we use the function DIV AB and
move the content of A and B to another 2 registers follow by add 30H for
both registers and finally display on LCD screen.
Example:
23H

A, 10H

DIV AB
A=2, B=3
A
R5+30H, B
R6+30H

5.2 result and discussion


First of all, the electronic voting machine will be starting by display
WELCOME TO VOTE! as shown in figure below as long as the New Entry
switch is being pressed. The switch 1 represented New Entry switch and
switch 4 represented Result switch. While the switch 2 and 3 represented
candidate 2 and 3.

After that, the LCD screen will display PLEASE VOTE immediately to
indicate the voter could start to cast their vote. The result is shown in
figure below.

After the voting process is ended, the Result


Result switch is being pressed by a
conservator. Then all the candidates follow by the number of votes will be
display on LCD screen and after some delay it would declare the winner
automatically.

Result

Declare The

Based on the figures above candidate1 (C1) get 18 votes while


candidate2 (C2) only 11 votes. So C1 has wins the poll and the LCD screen
will make congratulation and declare that C1 wins! Conversely the LCD
screen will display C2 wins if the number of votes
votes for C2 is more than C1.
In case of the number of votes for both candidates clash, the LCD screen
will ask for proceed to another voting.
In this project, we still require to make some improvement to
make it more effective for future scope. First, we can
can make an option
initially to choose how much the candidate will be involved. Next, in
security system, we could add a finger print scanning to mark down the
people who have voted to ensure that a same people cannot vote for the
second times. We can also provide
rovide several different languages to voters for
whom English is not the first language. Finally, there are also advantages
when it comes to disabled people,
people, such as blind individuals. Electronic
voting machine can provide headphones to read off instructio
instructions to blind
voters. Additional tools can be incorporated into these voting machines to
help with other disabilities and to aid the elderly as well. Due to time
constraints we have not been able to implement these features in our
project. But it is possible to make it in the future.

Chapter 6: Conclusion
This project show that we can use the microcontroller 8051 to design a
electronic voting machine which is more secured, convenient, and
economic compare with the traditional paper-based voting scheme. We are
successfully build up an electronic voting machine which can be used for
school and college level council elections or any voting purpose event.The
function of the circuit is working according to what are we predicted and
the objectives is achieve. This show that our program code and circuit
design can be implemented to a real life
In this project, we learned some extra code of microcontroller 8051
which we did not learn from the lab session and we are able to use those
code. For an instance, we had used the registers from Bank 1 and the
alternative way to display a message on LCD screen. We learned how to
interface the microcontroller 8051 with PPI 8255, LCD screen, and LED. We
are able to use the ports from PPI 8255 to send an output from
microcontroller 8051 or send an input to microcontroller 8051. We learned
how to solve the problem that we faced during this project.
We hope that our project will not only work on our circuit design, but
also it can work in a real life by do some improvement on it. So that it could
be used for voting purpose at any required place.

Appendix
Assembly program code:
CPU"8051.TBL"
INCL"8051.INC"
MOV SP, #030H
ORG 2000H
PA: EQU 4000H
PB: EQU 4001H
PC: EQU 4002H
PCTR: EQU 4003H
MOV A, #10010000B
MOV DPTR, #PCTR
MOVX @DPTR, A
MOV A, #38H
LCALL COMNWRT
LCALL DELAY
MOV A, #0CH
LCALL COMNWRT
LCALL DELAY
MOV A, #10H
LCALL COMNWRT
LCALL DELAY
MOV A, #01H
LCALL COMNWRT
LCALL DELAY
MOV R0, #0H
MOV R6, #0H
MOV R1, #0H
MOV R2, #0H
MOV R3, #0H
MOV R4, #0H
MOV R5, #0H
MOV R7, #0H
SETB F0
;=========================================================================;
;=========================================================================
START:
LCALL BUTTONPRESS
LCALL FIRSTLINE
LCALL SECONDLINE
CJNE R0, #2, START1
MOV R0, #0
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1

LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
START1:
CJNE R0, #3, START
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL DELAY1
LCALL WINNER
AGAIN:
SJMP AGAIN
;=========================================================================;
SCAN BUTTON
;=========================================================================
BUTTONPRESS:
MOV DPTR, #PA
MOVX A, @DPTR
ANL A, #00001111B
CJNE A, #00000001B, RCHECK1
MOV R0, #1
CLR F0
RET
RCHECK1:

CJNE A, #00000010B, RCHECK2


JB F0, DONTH
INC R1
MOV R0, #2
SETB F0
RET

RCHECK2:

CJNE A, #00000100B, RCHECK3


JB F0, DONTH
INC R2
MOV R0, #2
SETB F0
RET

RCHECK3:

CJNE A, #00001000B, DONTH


MOV R0, #3
RET
DONTH:
RET
;=========================================================================;
DISPLAY MESSAGES ON LCD
;=========================================================================
FIRSTLINE:
LCALL DELAY

MOV A, #80H
LCALL COMNWRT
LCALL DELAY
MOV R4, #0
LOOP1:

MOV A, R4
LCALL COND0
MOVC A, @A+DPTR
INC R4
JZ PROCEED1
LCALL DATAWRT
LCALL DELAY

SJMP LOOP1
PROCEED1: RET
;=========================================================================;
DISPLAY THE TOTAL NUMBER OF VOTES
;=========================================================================
SECONDLINE: MOV DPTR, #PA
MOVX A, @DPTR
ANL A, #00001000B
CJNE A, #00001000B, DONTH1
MOV A, #0C0H
LCALL COMNWRT
LCALL DELAY
MOV A, R1
MOV R7, A
LCALL HEXTOBCD
MOV A, R5
ADD A, #30H
LCALL DATAWRT
LCALL DELAY
MOV A, R6
ADD A, #30H
LCALL DATAWRT
LCALL DELAY
MOV A, #20H
LCALL DATAWRT
LCALL DELAY
MOV A, #20H
LCALL DATAWRT
LCALL DELAY
MOV A, R2
MOV R7, A
LCALL HEXTOBCD
MOV A, R5
ADD A, #30H
LCALL DATAWRT
LCALL DELAY

MOV A, R6
ADD A, #30H
LCALL DATAWRT
LCALL DELAY
RET
DONTH1:
RET
;=========================================================================;
DECLARE WINNER
;=========================================================================
WINNER:
CLR C
MOV A, #01H
LCALL COMNWRT
LCALL DELAY
MOV A, #80H
LCALL COMNWRT
LCALL DELAY
MOV R4, #0
LOOP2:

MOV A, R1
MOV 50H, R2
CJNE A, 50H, LOOP3
LCALL COND6
MOV A, R4
MOVC A, @A+DPTR
INC R4
JZ PROCEED2
LCALL DATAWRT
LCALL DELAY
SJMP LOOP2

LOOP3:

JC LOOP4
MOV A, R4
LCALL COND4
MOVC A, @A+DPTR
INC R4
JZ PROCEED2
LCALL DATAWRT
LCALL DELAY
SJMP LOOP3

LOOP4:

MOV A, R4
LCALL COND5
MOVC A, @A+DPTR
INC R4
JZ PROCEED2
LCALL DATAWRT
LCALL DELAY
SJMP LOOP4

PROCEED2:

MOV R0, 255


MOV A, #18H
LCALL COMNWRT
LCALL DELAY1

LCALL DELAY
DEC R0
MOV A, R0
JNZ PROCEED2
RET
;=========================================================================;
SELECT WHICH MESSAGE TO BE DISPLAY
;=========================================================================
COND0:
CJNE R0, #0, COND1
MOV DPTR, #MSG0
RET
COND1:

CJNE R0, #1, COND2


MOV DPTR, #MSG1
RET

COND2:

CJNE R0, #2, COND3


MOV DPTR, #MSG2
RET

COND3:

MOV DPTR, #MSG3


RET

COND4:

MOV DPTR, #MSG4


RET

COND5:

MOV DPTR, #MSG5


RET

COND6:

MOV DPTR, #MSG6


RET

;=========================================================================;
CONVERT HEX TO BCD
;=========================================================================
HEXTOBCD: CLR C
MOV A, R7
MOV B, #10
DIV AB
MOV R5, A
MOV R6, B
RET

;=========================================================================;
LCD COMMAND
;=========================================================================
COMNWRT: MOV DPTR, #PC
MOVX @DPTR, A
CLR P1.0 ;RS
CLR P1.1 ;RW
SETB P1.2;E
ACALL DELAY
CLR P1.2
RET
DATAWRT:

MOV DPTR, #PC


MOVX @DPTR, A
SETB P1.0
CLR P1.1
SETB P1.2
ACALL DELAY
CLR P1.2
RET

;=========================================================================;
DELAY
;=========================================================================
DELAY:
MOV R3, #225
HERE1:
DJNZ R3, HERE1
RET
DELAY1:
HERE:
HERE2:

SETB PSW.4
MOV R7, #255
MOV R3, #255
DJNZ R3, HERE2
DJNZ R7, HERE
CLR PSW.4
RET

;=========================================================================;
DECLARE MESSAGE TO BE DISPLAY ON LCD
;=========================================================================
ORG 3800H
MSG0: DFB "WELCOME TO VOTE!", 0H
ORG 3830H
MSG1: DFB "PLEASE VOTE... ", 0H
ORG 3850H
MSG2: DFB "THANK YOU... ", 0H

ORG 3870H
MSG3: DFB "C1 C2

", 0H

ORG 3890H
MSG4: DFB "CONGRATULATION!! C1 WINS!!!", 0H
ORG 3910H
MSG5: DFB "CONGRATULATION!! C2 WINS!!!", 0H
ORG 3950H
MSG6: DFB " DRAW!! PROCEED TO THE NEXT VOTING...", 0H
END

REFERENCE
1. http://www.electronics.dit.ie/staff/tscarff/8255PPI/8255.htm
2. http://www.circuitstoday.com/8051-microcontroller
3. http://en.wikipedia.org/wiki/Intel_8255
4.http://www.cdrummond.qc.ca/cegep/informat/professeurs/alain/files/
asc ii.htm
5. Laboratory Manual EEE226 Microprocessor I
6. The 8051 Microcontroller and Embedded Systems
7. Appendix 8051 Instructions, Timing, And Registers

Você também pode gostar