You are on page 1of 43



1.1 Overview :
There are many type of voting process occur in different time and place from
early shape of hand rising to most modern type by using Internet .
Microcontroller is one of the most powerful general purpose device which is used in this
project to realizing the voting machine which have the ability to process data in high
speed , precise result and work together with PC to manage the over all operation .

1.2 Historical Review :

The past few decades have witnessed evolution of Microcontrollers. They have
revitalized a number of products or equipment in almost all fields including
telecommunications, medical, industrial, and consumer products. These embedded
Microcontroller systems now resides at the heart of modern life with a variety of
applications in fields like consumer electronics, automotive systems, domestic, and even
in aerospace products. Embedding a Microcontroller in an electronics instrument or
product requires a specialized design skill which requires a synergy of hardware and
software skills. [ 1 ]
In our day-to-day life we come across a number of embedded products. When we
switch on the washing machine or send an SMS on a cell phone one cannot prevent
without thinking the mechanism and the co-working of hardware and software in the
background. The market for such smart embedded products is occupying newer and
newer applications seemingly impossible few years back.

A Microcontroller (or MCU) is a computer-on-a-chip used to control electronic
devices. It is a type of microprocessor emphasizing self-sufficiency and cost-
effectiveness, in contrast to a general-purpose microprocessor (the kind used in a PC). A
typical Microcontroller contains all the memory and interfaces needed for a simple
application, whereas a general purpose microprocessor requires additional chips to
provide these functions . [ 1 ]

A highly integrated chip that contains all the components comprising a controller.
Typically this includes a CPU, RAM, some form of ROM, I/O ports, and timers. Unlike
a general-purpose computer, which also includes all of these components, a
Microcontroller is designed for a very specific task – to control a particular system. As a
result, the parts can be simplified and reduced, which cuts down on production costs .
The definitions given by various sources describe Microcontroller as an integrated
circuit (IC) with processor as well as peripherals on chip. But the crux of the matter is
the widespread uses of Microcontrollers in electronic systems. They are hidden inside a
surprising number of products such as microwave oven, TV, VCR, digital camera, cell
phone, Camcorders, cars, printers, keyboards, to name a few. The last three decades and
especially the past few years have witnessed the tremendous growth in the top-of-the-
line processors used for personal computing and digital signal processor (DSP)

Today, the use of Microcontrollers in embedded systems outnumbers the use of

processors in both the PC and the workstation market. It is estimated that over 50% of
the vast majority of the computer chips sold are Microcontrollers. The main reasons
behind their huge success are powerful yet cleverly chosen customizable electronics,
ease in programming, and low cost. These days Microcontrollers find increasing
application even in areas where they could not be used previously. With the decreasing
costs and footprints, it is now possible to have small-sized and cost-effective

Microcontroller units (MCUs) for new applications. The Microcontrollers today are
small enough to penetrate into the traditional market for 4-bit applications like TV
remote controls, toys, and games. For the simplest of all control applications they can
offer high value smart switch functionality for applications that previously used
electromechanical devices. [ 1 ]

1.3 Aim of the project :

The aim of the project is to design and implement an electronic voting machine
that has several features over present voting operation .

1.4 Report Layout :

The report of this project consists of five chapter some of them for theory other
for particular works as shown below

Chapter 1 : Introduction
Chapter 2 : Microcontrollers and RS-232 Data interface
Chapter 3 : System design and hardware implementation
Chapter 4 : Software implementation
Chapter 5 : Conclusion and future works

Microcontrollers And RS-232 Data interface
2.1 Microcontrollers Overview
The 8051 family of micro controllers is based on an architecture which is highly
optimized for embedded control systems. It is used in a wide variety of applications
from military equipment to automobiles to the keyboard on your PC .
family of Microcontrollers is available in a wide array of variations from manufacturers
such as Intel, Philips, Atmel and Siemens. These manufacturers have added numerous
features and peripherals to the 8051 such as I²C interfaces, analog to digital converters,
watchdog timers, and pulse width modulated outputs.
Variations of the 8051 with clock speeds up to 40MHz and voltage requirements down
to 1.5 volts are available. This wide range of parts based on one core makes the 8051
family an excellent choice as the base architecture for a company's entire line of
products since it can perform many functions and developers will only have to learn this
one platform. [ 4 ]
Features of AT89C51 which is used in our project
• Compatible with MCS-51TM Products
• 4K Bytes of In-System Re-programmable Flash Memory
• Endurance: 1,000 Write/Erase Cycles
• Fully Static Operation: 0 Hz to 24 MHz
• Three-level Program Memory Lock
• 128 x 8-bit Internal RAM
• 32 Programmable I/O Lines
• Two 16-bit Timer/Counters
• Six Interrupt Sources
• Programmable Serial Channel
• Low-power Idle and Power-down Modes [ 11 ]

A particularly useful feature of the 8051 core is the inclusion of a boolean processing
engine which allows bit-level boolean logic operations to be carried out directly and
efficiently on internal registers and RAM. This feature helped cement the 8051's
popularity in industrial control applications. Another valued feature is that it has four
separate register sets, which can be used to greatly reduce interrupt latency compared to
the more common method of storing interrupt context on a stack.
The 8051 UARTs make it simple to use the chip as a serial communications interface.
External pins can be configured to connect to internal shift registers in a variety of ways,
and the internal timers can also be used, allowing serial communications in a number of
modes, both synchronous and asynchronous. [ 1 ]

Figure 2.1 8051 layout

2.2 Microcontroller Applications
The Microcontroller applications are mainly categorized into the following types
(see Figure 2.2):
• Audio
• Automotive
• Communication/wired
• Computers and peripherals
• Consumer
• Industrial
• Imaging and video
• Medical
• Military/aerospace
• Mobile/wireless
• Motor control
• Security
• General Purpose
• Miscellaneous
Automobile industry is the main driving force in propelling the growth of
Microcontrollers. It is estimated that the Microcontrollers constitute 33% of the
semiconductors used in a vehicle . Requirements of the automobile sector has forced the
Microcontroller manufacturers to come out with the new bus protocols such as control
area network (CAN) and local interconnect network (LIN). The 8- and 16-bit
Microcontrollers are used for low-end applications and lower-cost vehicles while the
32-bit Microcontrollers are used for high-end application and high-end vehicles. It is
estimated that currently 30% – 40% Microcontrollers are used in low-end vehicles and
about 70% Microcontrollers are used in high-end vehicles.

These requirements are continuously increasing and it is highly likely that the count of
Microcontrollers in vehicles will further increase in the future . [ 1 ]

Figure 2.2 – application tree

2.3 Pin definitions and functions
The capability to interface external memory has an impact on pin organization. In
general, there are two types of Microcontrollers. First, those Microcontrollers which
have on-chip Program Memory and are not capable to use external memory and second,
Microcontrollers, such as the 8051, which can interface external memory. Of course,
some of them lack internal Program Memory and must fetch instructions from external
memory. In the second case, a large majority of the Microcontroller pins are occupied
for memory interface. As indicated in Figure 2.3 , Port 0 and Port 2 link the
Microcontroller with the external memory.

In addition, the parallel ports, the serial port, the interrupt system and the timer/counters
need pins to interact with the environment. Figure 2.3 shows a pin configuration of the
8051 Microcontroller in a 40-pin dual in-line package. Port 0 can be used either as a
general purpose port or to access external memory. When external memory is used, Port
0 forms the low order byte of the external memory address (A0 - A7). Next, the byte
being written or read is transferred through Port 0.

External pull-ups resister resister are required when Port 0 loaded . Port 1 is a general
purpose port with internal pull-ups resister. and does not possess any other special
function. Port 2 can be used either as a general purpose port or to emit the high-order
address (A8- A16) and also with internal pull-ups resister. Port 3 is an 8-bit bi-
directional I/O port with internal pull-ups resister.[ 8 ]

Figure 2.3 pin configuration

2.4 Memory Organization

The 8051 architecture provides the user with three physically distinct memory
spaces which can be seen in Figure 2.4 Each memory space consists of contiguous
addresses from 0 to the maximum size, in bytes, of the memory space. Address overlaps
are resolved by utilizing instructions which refer specifically to a given address space.
The three memory spaces function as described below. [ 8 ]

Figure 2.4 Memory Organization

2.4.1 The Code Space

The first memory space is the CODE segment in which the executable program
resides. This segment can be up to 64K (since it is addressed by 16 address lines) . The
processor treats this segment as read only and will generate signals appropriate to access
a memory device such as an EPROM. However, this does not mean that the CODE
segment must be implemented using an EPROM. Many embedded systems these days
are using EEPROM which allows the memory to be overwritten either by the 8051 itself
or by an external device. This makes upgrades to the product easy to do since new
software can be downloaded into the EEPROM rather than having to disassemble it and
install a new EPROM.
Code memory is accessed based on the chip line EA. If the line is low, control goes to
external memory. If the line is high, initial control goes to internal memory. The next
line of code after the top of internal memory is external memory. This transition is
regardless of EA setting. The next address will be in sequence. In other words,
the low external memory is inaccessible. [ 8 ]

In addition to executable code, it is common practice with the 8051 to store fixed lookup
tables in the CODE segment. To facilitate this, the 8051 provides instructions which
allow rapid access to tables via the data pointer (DPTR) or the program counter with an
offset into the table optionally provided by the accumulator. This means that oftentimes,
a table's base address can be loaded in DPTR and the element of the table to access can
be held in the accumulator. The addition is performed by the 8051 during the execution
of the instruction which can save many cycles depending on the situation.
2.4.2 The Data Space
The second memory space is the 128 bytes of internal RAM on the 8051, or the
first 128 bytes of internal RAM on the 8052. This segment is typically referred to as the
DATA segment. The RAM locations in this segment are accessed in one or two cycles
depending on the instruction. This access time is much quicker than access to the
XDATA segment because memory is addressed directly rather than via a memory
pointer such as DPTR which must first be initialized. Therefore, frequently used
variables and temporary scratch variables are usually assigned to the DATA segment.
Such allocation must be done with care, however, due to the limited amount of memory
in this segment. Variables stored in the DATA segment can also be accessed indirectly
via R0 or R1. The register being used as the memory pointer must contain the address of
the byte to be retrieved or altered. These instructions can take one or two processor
cycles depending on the source/destination data byte.
The DATA segment contains two smaller segments of interest. The first subsegment
consists of the four sets of register banks which compose the first 32 bytes of RAM. The
8051 can use any of these four groups of eight bytes as its default register bank. The
selection of register banks is changeable at any time via the RS1 and the RS0 bits in the
Processor Status Word (PSW). These two bits combine into a number from 0 to 3 (with
RS1 being the most significant bit) which indicates the register bank to be used. Register
bank switching allows not only for quick parameter passing, but also opens the door for
simplifying task switching on the 8051.

The second sub-segment in the DATA space is a bit addressable segment in which each
bit can be individually accessed. This segment is referred to as the BDATA segment. The
bit addressable segment consists of 16 bytes (128 bits) above the four register banks in
memory. The 8051 contains several single bit instructions which are often very useful in
control applications and aid in replacing external combinatorial logic with software in
the 8051 thus reducing parts count on the target system. It should be noted that these 16
bytes can also be accessed on a "byte-wide" basis just like any other byte in the DATA
space. [ 8 ]
2.4.3 Special Function Registers [ 7 ]

Table 2.4 Special Function Registers

2.5 Timing
The control unit of a microprocessor or Microcontroller is responsible for the
proper handling of the stream of instructions. Each instruction includes one or more
steps (cycles). At the same time, an instruction can be viewed as a deeper level program
which performs a series of specific actions. Executing this program, termed
microprogram or microcode, the control unit emerges as a processor within the CPU.
There can be no doubt, every processor needs memory to read the instructions.
Consequently, the control unit must contain a ROM. Alternatively, the control unit can
be designed as a sequential machine. Practically, the users might not be interested in the
internal architecture of the Microcontroller. However, they should be aware of the timing
parameters of the microcomputer and the essential design rules. The topics of this
section are the following matters:

• Basic timing: the interaction between the Microcontroller's CPU and memory.

• The Microcontroller's instructions parameters: execution time and number of bytes.

Figure 2.5 shows the basic timing diagram. A machine cycle includes 12 oscillator
periods. The cycle is divided into 6 states - S1 through S6. Each state consists of 2
phases - P1 and P2. As an example of one-byte, one-cycle instruction we use INC A
(Increment accumulator A). A fetch/execute cycle from external Program Memory
includes the following steps:

The opcode is read through Port 0 (Cycle 1, State 1)

Figure 2.5 basic timing diagram
The low address byte (A0 - A7) is latched into the external register buffer on the high-to-
low transition of ALE pulse. The high address byte (A8 - A15) is emitted through Port
There is a fetch at Cycle 1, State 4, but it is a one-byte instruction and the byte read is
ignored. The Program Counter is not incremented .
The low address byte (A0 - A7) of the next opcode is prepared .[ 8 ]

2.6 Serial port

The 8051 Microcontroller, like almost all other computers, processes data in
parallel. At the same time, the communication between computers is often done by serial
links. Inevitably, a serial bus would be slower than a parallel bus, but it is cost-effective
and very popular for small embedded systems and personal computers. The rate of
transmission is called the bit rate. The bit rate is frequently termed baud rate. Apart from
the fact that bit rate and baud rate are not always equal, they are used synonymously in
this text.
The Microcontroller subsystem which converts the parallel data into a serial bit stream

and vice versa is called a serial port. The serial port is alternatively labeled Universal
Asynchronous Receiver Transmitter (UART). The serial port of the 8051 is a full duplex
port and therefore it can transmit and receive simultaneously. The receive register is
buffered and it is possible to go on reception of a second byte before a previously
received byte has been read. The receive and transmit registers are both named SBUF.
The serial port is controlled by a Serial port CONtrol register (SCON). Moreover, the
register SCON acts as a status register including a Transmit Interrupt flag (TI) and a
Receive Interrupt flag (RI). Figure 2.6 shows the register SCON and its relation to the
incoming and outgoing frames.
A set interrupt flag TI indicates that the transmit buffer is empty and can be loaded
again. The interrupt flag TI is set by hardware at the end of the 8th bit period in mode 0
or at the beginning of the stop bit in the other modes when the serial port transmits. The
flag TI must be cleared by software.
A set receive interrupt flag RI alarms that the receive buffer is full and should be read.
The interrupt flag RI is set by hardware at the end of the 8th bit period in mode 0 or
through the stop bit period in the other modes, when the serial port receives. Likewise,
the flag RI must be cleared by software.
As you might expect, mode 0 is one of four possible modes of operation that can be
selected by bits SM0 and SM1from register SCON. Unlike what you might expect, the
bit SM0 is the most significant bit (MSB) when the mode is coded. A bit REN from
register SCON enables serial reception for all modes. It can be set by software to enable
or cleared to disable the reception.[ 8 ]
2.6.1 Mode 0
This synchronous mode is used to interface shift registers. In mode 0 the serial bit
stream goes either in or out through the line R×D (P3.0). The shift clock is generated on
pin T×D (P3.1). Eight bits are either transmitted or received. The least significant bit
(LSB) is transferred first.

The baud rate is

Transmission is initiated by loading the register SBUF. To start the reception, the
following condition must be satisfied

The logic equation implies that the reception is allowed by setting the bit REN and by
clearing the receive interrupt flag RI. The flag REN is cleared in the beginning. The flag
RI is reset after each received byte. Mode 0 is commonly used for fast data transfer in
conjunction with parallel-to-serial and serial-to-parallel registers.[ 8 ]

2.6.2 Mode 1
Mode 1 is the standard full-duplex mode. A data word includes a start bit (low), 8
data bits and a stop bit (high). The LSB is transferred first. In mode 1, 2 and 3 the bit
stream is transmitted through the pin T×D and received through the pin R×D. The baud
rate can be programmed by Timer/Counter 1. Transmission is initiated by a move to the
register SBUF. Reception is initiated when the line R×D is switched from high to low. If
the first bit after the transition is high, the receive circuit will be reset and go back to
wait for another high-to-low transition.

then the following actions will be performed:

• The data received in an input shift register is moved into register SBUF.

• The stop bit from the frame is loaded into the flip-flop RB8 of the register SCON.

• The receive interrupt flag RI is set.

If the described conditions are not satisfied the received frame will be lost. [ 8 ]

2.6.3 Mode 2
This mode facilitates multiprocessor communications. The frame includes a start
bit (low), 8 data bits, an additional bit (D8) and a stop bit (high). The LSB is transferred

The register PCON occupies the place between Timer/Counter 1 and the serial port .

Figure 2.6 attempts to illustrate modes 2 and 3. The transmission is initiated again by a
move to register SBUF. The additional bit D8 takes its value from register SCON, bit
TB8. The transmit interrupt flag TI is set at the beginning of the stop bit (shift register

As usual, the reception will be under way if the input R×D is changed from high to low.

the serial port will perform the following actions:

• The data (D0-D7) from the input shift register is moved into register SBUF.

• The received additional bit D8 is stored into flip-flop RB8 of the register SCON.

• The interrupt flag RI is set.

Otherwise the received frame is lost. [ 8 ]

Figure 2.6 The 8051 serial port control register SCON, mode 2 and 3
2.6.4 Mode 3
The baud rate in mode 3 is variable and sets up exactly the same as in mode 1.
This allows 9-bit data transfer.

Table 2.2 covers all possible combinations between the serial port and Timer/Counter 1
modes. In general, mode 0 and 2 have a fixed baud rate depending on oscillator
frequency. Mode 1 and 3 possess a programmable baud rate option based on
Timer/Counter 1. If that's the case, the baud rate can be controlled by writing a certain
code to register TH1. In this way either oscillator frequency fOSC or external signal
with frequency fT1 applied to input T1 is divided to form the desired baud rate. If the
serial port in mode 1 and 3 is combined with Timer/Counter 1 in counter mode, the
ceiling of the input frequency is 1/24 fOSC.

Table 2.2 Baud rate selection

Table 2.3 illustrates several widespread baud rates and examples how they can be

Table 2.3 Baud rate examples.

2.7 RS-232
RS-232 is designed to handle communications between two devices with a
distance limit of around 80 to 130 ft, depending on the bit rate and cable type.

RS-232 uses unbalanced, or single-ended, lines. Each signal in the interface has one
dedicated line whose voltage is referenced to a common ground.

2.7.1 Signal
In popular use, RS-232 refers to a serial interface that complies with much of the
standard TIA-232Interface between Data Terminal Equipment. The name RS-232 dates
to an earlier edition of the standard.

The standard’s current publisher is the Telecommunications Industry Association (TIA).

Previous versions were a product of the Electronics Industries Association (EIA)

The standard designates 25 lines in the interface, but RS-232 ports rarely support more
than the nine signals in Table 2.9. The additional signals are intended for use with
synchronous modems, secondary transmission channels, and selecting a transmission
speed on a dual-rate modem. Some applications

require only three lines (or even two, if the link is one way).

Much of the RS-232 terminology reflects its origin as a standard for communications
between a computer terminal and an external modem. A “dumb” terminal contains a
keyboard, a display, a communications port for accessing a remote computer, and little
else. An RS-232 link connects the terminal to a modem, which in turn accesses the
phone lines that connect to the remote computer. PCs with modems and network
interfaces have made this type of terminal connection nearly obsolete.

These days, an RS-232 port is more likely to connect a PC to an embedded system or to

connect two embedded systems. Much of the original RS-232 terminology thus doesn’t
apply to modern applications, but the hardware interface remains useful. [ 2 ]

Table 2.4 RS-232 pin

2.7.2 DTE & DCE
The RS-232 standard calls the terminal end of the link the data terminal
equipment, or DTE. The modem end of the link is the data circuit-terminating
equipment, or DCE. The signals and their functions are named from the perspective of
the DTE. For example, TX (transmit data) is an output on a DTE and an input on a DCE,
while RX (receive data) is an input on a DTE and an output on a DCE. The RS-232 ports
on PCs are almost always DTEs. It doesn’t matter which device in a link is the DTE and
which is the DCE, but every connection between two computers must either have one of
each or must emulate the absent interface (typically DCE) with an adapter called a null

2.7.3 Voltage
RS-232 logic levels are defined as positive and negative voltages rather than the
positive-only voltages of TTL and CMOS logic . At an RS-232 data output (TX), logic 0
is defined as equal to or more positive than +5V, and logic 1 is defined as equal to or
more negative than -5V. In other words, the data uses negative logic, where the more
positive voltage is logic 0 and the more negative voltage is logic 1. the status and control
signals use the same voltages, but with positive logic. A positive voltage indicates a
logic 1 and a function that is On, asserted, or True, and a negative voltage indicates a
logic 0 and a function that is Off, not asserted, or False.

An RS-232 interface chip typically inverts the signals and converts between TTL/CMOS
voltages and RS-232 voltages. On a UART’s output pin, a logic-1 data bit or an Off
control signal is a logic high, which results in a negative voltage at the RS-232 output. A
logic-0 data bit or asserted control signal is a logic low at the UART and results in a
positive voltage at the RS-232 output. Because an RS-232 receiver can be at the end of a
long cable, by the time the signal reaches the receiver, the voltage may have attenuated
or have noise riding on it. To allow for degraded signals, the receiver accepts smaller
voltages as valid. A positive voltage of 3V or greater is a logic 0 at RX or asserted at a

control input. A negative voltage of 3V or greater (more negative) is a logic 1 at RX

or Off at a control input. The logic level of an input between -3V and +3V is undefined.
The noise margin, or voltage margin, is the difference between the output and input
voltages. RS-232’s large voltage swings result in a much wider noise margin than 5V
TTL or CMOS logic. For example, an RS-232 output of +5V can attenuate or have noise
spikes as large as 2V at the receiver and will still be a valid logic 0. Many RS-232
outputs have wider voltage swings that result in even wider noise margins. The
maximum allowed voltage swing is ±15V, though receivers must accept voltages as high
as ±25V without damage. On the data lines, Space is logic 0 (positive voltage), and
Mark is logic 1 (negative voltage). [ 2 ]

System Design And Hardware Implementation
This chapter divide in to eight part for illustrate the circuit design and the the
function of each unit in the project .


3.1 system block digram overview

The Microcontroller is connected to key pad to take user input and process the
data to and arrange the operation . If it correct given a notification to the user and
display the result on the seven segment display . After complete the election , data send
to the computer to manage the overall operation for all users data .

Figure 3.1
overview digram of the project

3.2 Keypad
The circuit below describe the keypad and how it work .

the keypad contain 10 switches [0 – 9] each one of them connect to the ground from a
terminal . The second terminal connect to the Microcontroller ,which is put logic 1

[ 5 volt ] on that port and check periodically if one or more pin go to logic 0[grounded]

if more than one key press at the same time , MCU does not take it as correct input .

minimal time between successive press key is 0.5 second .

this done by simple counter in Microcontroller .

Figure 3.2 keypad

3.3 crystal oscillator

Figure 3.3 crystal oscillator

Capacitors = 30pf

can take it between [20-40] pf

crystal oscillator is 11.0592 Mhz

this is special crystal type which is used for serial communication

this give a minimal error rate



such if
1200 baud rate is need and xtal is 12Mhz TH1 will be 229.95833.

but if 1200 baud rate is need and xtal is 11.0592 Mhz TH1 will be 232 .

there will be an error when convert it to hexadecimal number .

3.4 output display

Figure 3.4 hexadecimal display

Hexadecimal display IC have four data latch input and decoder .

D ' input ' is the most significant bit

A ' input ' is the least significant bit

ic is til311

3.5 RS-232 adapter

Figure 3.5 RS-232 db-9

In our project used usb-RS-32 converter .

RS-232 cables can vary in length, number of wires, and shielding.

Early versions of the RS-232 standard recommended limiting cable length to 50 ft, and
this is still a good general guideline. For data rates of 20 kbps or less .

3.6 Voltage converter
As MCU work on voltage of +5 and 0 volt and RS-232 need voltage between
+13 and -13 volt therefor need a converters between these voltage . Max232 can do this



Figure 3.6 max232

Logic 0 to +5 ~ +15

Logic 1 to -5 ~ -15

3.7 Power supply
The circuit below describe how to convert from 220 V AC to 5 V DC

Figure 3.7 power supply

Transformer convert from 220 V AC to 5 V AC

Wave rectification

Smoothing capacitor eliminate the ripple that comes from the rectifier

regulation regulate the output power it give a constant 5 volt

3.8 Circuit Description
The system consist of :

1. Microcontroller
2. keypad (for user data input)
3. 2 hexadecimal display (show user data)
4. 2 LED (lower LED indicate most significant hexadecimal number read, and upper
LED indicate least significant hexadecimal number read)
5. power supply
6. USB-RS-32 converter cable (to transfer data to the computer)
as shown in the Figure

Figure 3.8 practical work

Software Implementation
In this chapter we devoted on software implementation of the project and it can be
divided in to two section one for Microcontroller programming and the second for
interfacing program which is written in matlab language .

4.1 Microcontroller main program

MCU can be programed in many language such c , c++ , java ,baisc and other
language and by using compiler convert that code to assemble language which is the
main programing language for it .

In our case the program was written in assembly to reduce the memory space , operation
time and more efficient works .

4.1.1 Program flowchart

As shown in the Figure below it illustrate the flow chart of the main program .

as the power on for MCU it's first initialize it's ports , serial port . After that it will show
the letters “ CC “ which mean Constituent .

Then it's check for user input which is the user name . After he/she input the the data if it
correct it will appear on the displayer , then appear “ AA “ which mean Attribute , so it
also wait user to enter it but this time it will give him a twice trial .

If he enter invalid Attribute for the tow try it will back to user name stage .

After enter it right it's appear “ EE “ which mean Election , wait user enter a numbers
and then send it to master device through RS-232 .

Figure 4.1 MCU program flowchart

4.1.2 Setting the baud rate
Baud rate is a bit rate used for serial communication in term of bit/sec for MCU
can can work in varying baud rate start from 150 to 76800 for ' atmel ' MCU

note : Baud rate limitations depend on MCU vendor and it's application .

to setup the MCU on a specific baud rate back to section 3.3 which has to equation help
to give the precisely baud rate

for example it choose 1200

mov TMOD,#20H ;Timer 1 Mode 2
anl PCON,#7FH ;SMOD = 0, K=1
mov TH1,#0e8H ;1200 BAUD @11.0592 MHz
MOV tl1,#00h
mov SCON,#50H ;Set SM1 & REN
setb TR1 ;Start timer
setb TI

4.1.3 Subroutine program for keypad

MCU always check the keypad for any new data periodically , to preform an data
input to keypad the data should be in form of 8 bit ' two BCD number ' so if data will be
number 7 ''0111 in binary '' as an example , the data input should be as 07

''00000111'' to take it .

The main idea is to convert port input to data stored in the accumulator and then shift it
to accept the second number to form 8 bit number .

Note : Subroutine program below show who to check any new data on keypad , if the
switch does not release , shift the data and two or more switch closed at the same time .
mov p1,#0ffh ;set port 1 and 3 as input

mov p3,#0fch
acall keydown ;keydown looks foe any key(s) down
jz scan ;if a-00 then no key(s) down loop
acall convert ;convert return flag set if not valid
jbc 20,scan ;or a set to 00 to 09 for keys 0-9
rl a
rl a
rl a
rl a
mov r4,a ;store the value of a
acall softtime ;wait a time to release the key
mov p1,#0ffh
mov p3,#0fch
mov p0,#0fh
acall keydown ;see if key is still down
jz scan1 ;second number
acall convert ;see if key is still valid and matches
jbc 20,scan1 ;the original key found
add a,r4 ;have total number 8 bit
mov r4,a ;copy a to r4 register
mov p0, #00h
ret ;ret to the main program

Note : This subroutine show who to convert the data to BCD number and give it to the
main keypad program

Note : Simply it check the whole keypad pin to defined pattern for each number if
invalid pattern occur it will inform the main keypad program .

MOV R0,p1 ;get state of p1 key to r0
mov a,p3 ;get state of p3 keys to a
orl a,#0cfh ;make bits 0,1and 4-7ones
anl a,r0 ;check for another keys down

cpl a ;a=ff if all key release
ret ;if a. ff then at least one key pressed
convert: clr 20 ;assume that key bit is valid
clr a ;a contain first possible key (00)
mov r1,p1 ;get p1 key pattert in r1
mov r3,p3 ;get p3 key pattern in r3
orl 03,#0cfh ;make r3 bits 0,1 and 4-7 ones
cjne r1,#0feh,one ;search r1 for legal pattern
sjmp check3 ;check p3 for no key down
inc a ;a = 01
cjne r1,#0fdh,two ;search for valid pattern
sjmp check3 ;check p3 for no key down
inc a ; a = 02
cjne r1,#0fbh,three ;search for legal pattern
sjmp check3 ;check p3 for no key down
inc a ; a= 03
cjne r1,#0f7h,four ;search for legal pattern
sjmp check3 ;check p3 for no key down
four: inc a ;a = 04
cjne r1,#0efh,five ;search for legal pattern
sjmp check3 ;check p3 for no key down
five: inc a ; a = 05
cjne r1,#0dfh,six ;search for legal pattern
sjmp check3 ;check p3 for no key down
inc a ; a = 06
CJNE R1,#0bfh,seven ;search for legal pattern
sjmp check3 ;check p3 for no key down
inc a ; a = 07
cjne r1,#7fh,eight ;search for legal pattern
sjmp check3 ;check p3 for no key down
inc a ; a = 08
cjne r3,#0efh,nine ;now look for a key in r3

jnb p3.5,bad ;check that key 9 is up
sjmp good ;go to the keyboard main program
inc a ; a = 09
cjne r3,#0dfh,bad ;redundant check
jnb p3.4,bad ;if r1 has key low r3 must all high
jnb p3.5,bad ;if r1 has key low r3 must all high
sjmp good
setb 20 ;signal an invalid key pattern
mov p1,#0ffh
mov p3,#0ffh
ret ;return to main keyboard program

4.1.4 Subroutine program for time delay

If we back to section 2.5 we found that each instruction take time to preform and
it,s depend on crystal oscillator value , under this idea the delay program work . this
program give a delay of 0.5 second
MOV 05,#03h
time: MOV 07,#245
mov 06h,#0ffh
djnz 06h,inter ; software timer
djnz 07,decrement
DJNZ 05,time

4.1.5 Subroutine program for serial communication

Serial combinations can be be done by initialized the serial port first as shown in
section 4.1.2 then put the data on Serial Buffer Register (SBUR) and wait if the last data
does not send .
JNB TI,serial ;xmit busy so wait.
clr TI ;clr for next xmit
mov SBUF,r2 ;mov byte to serial
jnb ti,tii
mov SBUF,r4 ;mov byte to serial
mov p0,#0ffh

4.2 Interfacing Program flowchart With Matlab
We use matlab programming language to make a program for interfacing the slave
device with the PC through serial port

Figure 4.2 interfacing program flowchart

The main idea of the program is to prepare serial port on specific option 'baud rate ,
stopbit , parity .. '

Then make a matrix with user id and an empty matrix for user election .

wait data to check if user make election before ignore his election else save user id and
his election and the program will wait until all user complete election .

conclusion and future works
In this chapter , a conclusion with some abbreviations of how to upgrade the project

5.1 Conclusion
Microcontroller has several feature over PC in industrial equipment from price , size ,
effectiveness and operation .

The EVM electronic voting machine has many option to be implemented , in any
version it's need a change in algorithm , communication mean , keypad size , output
displays .

Programming the MCU need to be learn carefully from simple program contain several
line to huge program contain several hundred of line .

5.2 Future works
Electronic voting machine can be developed by improved it's communication
channel by replacing RS-32 cable by wireless link between the master unit and the
slave's units and change the master unit to embedded system to increase the security of
the over all operation which in our case the PC .

Other thing as using LCD instead of 7-segment to change “ user and election “ numbers
type to characters type , the keypad is associated with this option to be develop .

It can be used Programmable Interface Controller (PIC) Microcontroller instead of 8051

Microcontrollers for system development due to their low cost, wide availability, large
user base, extensive collection of application notes, availability of low cost or free
development tools, and serial programming (and re-programming with flash memory)


[ 1 ] JIVAN S. PARAB , Exploring c for Microcontroller , 2007

[ 2 ] Jan Axelson , Serial Port Complete , 2007

[ 3 ] Marcus O. Durham , System Design and the 8051 2E , 2004

[ 4 ] Hassan Parchizadeh , 8051 Microcontrollers An Applications-Based Introduction ,


[ 5 ] Dogan Ibrahim , Microcontroller Projects in C for the 8051 , 2000

[ 6 ] The final word on 8051

[ 7 ] Atmel , Atmel 8051 Microcontrollers Hardware Manual

[ 8 ] Karakehayov , Embedded Systems Design With 8051 Microcontrollers , 1999

[ 9 ] Mackenzie , The 8051 Microcontroller 3rd Edition , 1995

[ 10 ] kenneth j. Ayala , The 8051 Microcontroller Architecture, Programming and

Applications , 1991

[ 11 ] AT89C51 Data sheet