1. INTRODUCTION TO EMBEDDED SYSTEMS An embedded system is a special-purpose system in which the computer is completely encapsulated by the device it controls. Unlike a general-purpose computer, such as a personal computer, an embedded system performs pre-defined tasks, usually with very specific requirements. Since the system is dedicated to a specific task, design engineers can optimize it, reducing the size and cost of the product. Embedded systems are often mass-produced, so the cost savings may be multiplied by millions of items. Physically, embedded systems range from portable devices such as digital watches and MP3 players , to large stationary installations like traffic lights , factory controllers . Complexity varies from low, with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure. Embedded systems contain processing cores that are either microcontrollers or digital signal processors (DSP). The key characteristic, however, is being dedicated to handle a particular task. Since the embedded system is dedicated to specific tasks, design engineers can optimize it to reduce the size and cost of the product and increase the reliability and performance. Some embedded systems are mass-produced, benefiting from economies of scale . Robotics and automation are a part of embedded systems itself. Robot development and automation needs study of embedded systems. Examples of Embedded System:- I. automatic teller machines (ATMs) [1]
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1. INTRODUCTION TO EMBEDDED SYSTEMS
An embedded system is a special-purpose system in which the computer is completely encapsulated
by the device it controls. Unlike a general-purpose computer, such as a personal computer, an
embedded system performs pre-defined tasks, usually with very specific requirements. Since the
system is dedicated to a specific task, design engineers can optimize it, reducing the size and cost of
the product. Embedded systems are often mass-produced, so the cost savings may be multiplied by
millions of items.
Physically, embedded systems range from portable devices such as digital watches and MP3 players,
to large stationary installations like traffic lights, factory controllers. Complexity varies from low,
with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted
inside a large chassis or enclosure.
Embedded systems contain processing cores that are either microcontrollers or digital signal
processors (DSP). The key characteristic, however, is being dedicated to handle a particular task.
Since the embedded system is dedicated to specific tasks, design engineers can optimize it to reduce
the size and cost of the product and increase the reliability and performance. Some embedded systems
are mass-produced, benefiting from economies of scale.
Robotics and automation are a part of embedded systems itself. Robot development and automation
needs study of embedded systems.
Examples of Embedded System:-
I. automatic teller machines (ATMs)
II. avionics, such as inertial guidance systems, flight control hardware/software and other
integrated systems in aircraft and missiles
III. cellular telephones and telephone switches
IV. computer equipment such as routers and printers
V. engine controllers and antilock brake controllers for automobiles
VI. home automation products, like thermostats, air conditioners, sprinklers, and security
monitoring systems
VII. handheld calculators
VIII. household appliances, including microwave ovens, washing machines, television sets
Pins 1-8 (Port 1) - Each of these pins can be configured as an input or an output.
Pin 9 (Reset) - A logic one on this pin disables the microcontroller and clears the contents of most
registers. In other words, the positive voltage on this pin resets the microcontroller. By applying logic
zero to this pin, the program starts execution from the beginning.
Pins 10- 17 (Port 3) -Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions:
Pin 10 (RXD) - Serial asynchronous communication input or Serial synchronous communication
output.
Pin 11(TXD) - Serial asynchronous communication output or Serial synchronous communication
clock output.
Pin 12 (INT 0) - Interrupt 0 input.
[16]
Pin 13(INT 1) - Interrupt 1 input.
Pin 14(T0) - Counter 0 clock input.
Pin 15(T1) - Counter 1 clock input.
Pin 16(WR) -Write to external (additional) RAM.
Pin 17 (RD) -Read from external RAM.
Pin 18 and 19(X1, X2) - Internal oscillator input and output. A quartz crystal which specifies
operating frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can
also be used for frequency stability. Later versions of microcontrollers operate at a frequency of 0 Hz
up to over 50 Hz.
Pin 20 (GND) - Ground.
Pin 21-28 (Port 2) - If there is no intention to use external memory then these port pins are configured
as general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-
A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which means
that not all eight port bits are used for its addressing, the rest of them are not available as
inputs/outputs.
Pin 29 (PSEN) - If external ROM is used for storing program then a logic zero (0) appears on it every
time the microcontroller reads a byte from memory.
Pin 30 (ALE) - Prior to reading from external memory, the microcontroller puts the lower address
byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the
external register memorizes the state of P0 and uses it as a memory chip address. Immediately after
that, the ALU pin is returned its previous logic state and P0 is now used as a Data Bus. As seen, port
data multiplexing is performed by means of only one additional (and cheap) integrated circuit. In other
words, this port is used for both data and address transmission.
Pin 31 (EA) - By applying logic zero to this pin, P2 and P3 are used for data and address transmission
with no regard to whether there is internal memory or not. It means that even there is a program
written to the microcontroller, it will not be executed. Instead, the program written to external ROM
will be executed. By applying logic one to the EA pin, the microcontroller will use both memories,
first internal then external (if exists).
Pin 32-39 (Port 0) - Similar to P2, if external memory is not used, these pins can be used as general
inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven
high (1) or as data output (Data Bus) when the ALE pin is driven low (0).
Pin 40 (Vcc) - +5V power supply.
[17]
4.5 MICROCONTROLLER 8051 ARCHITECTURE
It is 8-bit microcontroller, means MC 8051 can Read, Write and Process 8 bit data. This is mostly
used microcontroller in the robotics, home appliances likemp3 player, washing machines, electronic
iron and industries. Mostly used blocks in the architecture of 8051 are as follows:
Address bus-For a device (memory or I/O) to be recognized by the CPU, it must be assigned an
address. The address assigned to a given device must be unique. The CPU puts the address on the
address bus, and the decoding circuitry finds the device.
Data bus-The CPU either gets data from the device or sends data to it.
Control bus-Provides read or write signals to the device to indicate if the CPU is asking for
information or sending it information.
[18]
4.6 Memory and Registers
The 8051 microcontroller has a total of 256 bytes of RAM in which 128 is visible or useraccessible
and extra 128 is for special function registers. The user accessible RAM is used for temporary data
storage. The user accessible RAM is from the address range 00 to 7Fh.From the user accessible RAM,
32 bytes of RAM is used for registers and rest for Stack operations. The 32 Bytes of RAM is divided
into four register Banks i.e. Bank0, Bank 1, Bank 2, Bank3. Each of these banks have 8 Registers i.e.
R0 to R7 each.
RAM locations from 0 to 7 are set aside for bank 0 of R0 – R7 where R0 is RAM location 0, Rl is
RAM location 1, and R2 is location 2, and so on, until memory location 7, which belongs to R7 of
bank 0. The second bank of registers R0 – R7 starts at RAM location 08 and goes to location 0FH.
The third bank of R0 – R7 starts at memory location 10H and goes to location 17H. Finally, RAM
locations 18H to 1FH are set aside for the fourth bank of R0 – R7.
Generally for normal operations, Register bank Bank0 is set by default. But we can switch to other
banks by using PSW Commands.
SFRs (Special Function Register) - These Registers are in extra 128 bytes of the memory. This part
of memory is not user accessible and these registers are used for special purposes. These
[19]
registers range from 80h to FFh. There are a total of only 21 SFRs in this range and all other addresses
from 80h to FFh are invalid and there use can cause errors and not valuable results.
Some of the SFRs are TCON, SBUF, ACC, B, SCON, TMOD SP, P0, PSW, TL0, and TL1. These all
the registers have some specific function that has to be performed after they are programmed.
Byte Addressable SFR with byte address
SP – Stack printer – 81H
DPTR – Data pointer 2 bytes
DPL – Low byte – 82H
DPH – High byte – 83H
TMOD – Timer mode control – 89H
TH0 – Timer 0 Higher order bytes – 8CH
TL0 – Timer 0 Low order bytes – 8AH
TH1 – Timer 1 High bytes = 80H
TL1 – Timer 1 Low order byte = 86H
SBUF – Serial data buffer = 99H
PCON – Power control – 87H.
DPTR - Data Pointer in 8051
16 bit register; it is divided into two parts DPH and DPL.
DPH for Higher order 8 bits, DPL for lower order 8 bits.
DPTR, DPH, DPL these all are SFRs in 8051.
4.7 Timers and Counters:
[20]
The 8051 has two timers T0 and T1, which may be configured and used individually. The 8052 has an
additional Timer T2.All these counters count up on negative going edges at their inputs. These can be
used as event counters (where they count the number of negative transitions on a pin connected to
some external source), or as Timers, where they count up once every twelfth clock cycle. A special
use of timers is for generating baud rates for the serial port. The usage of these timers is somewhat
different from common general purpose timer/counters such as the 8253 and 8254. This difference
stems partly from the fact that we cannot afford to have a large numbers of pins dedicated to the
functioning of these timer counters. Thus, just two multifunction pins are used as external inputs in
8051. Gating is accomplished by control bits in the special function registers, and using the external
interrupt pins as gate inputs. There are no output pins associated with the timers. The processor can
be interrupted by the timers and as a part of the interrupt service routine, the processor can performing
IO function through its ports. When used as baud rate generators, the output
goes directly to the serial port hardware within the microcomputer.
8051 timers always count up. Each counter has a 16 bit count register in the SFR area. The low and
high bytes can be accessed as separate bytes. When their
count rolls over from the maximum count to 0000, they set the corresponding
timer flag (TF1 or TF0) in TCON. The 8051 can be set up so that an interrupt occurs whenever TF1
or TF0 is set. when 8051 branches to the interrupt vector, it automatically clears the TF
flag.
Timer means which can give the delay of particular time between some events. For example on or
off the lights after every 2 sec. This delay can be provided through some assembly program but in
microcontroller two hardware pins are available for delay generation. These hardware pins can be
also used for counting
some external events. How much times a number is repeated in the given table is calculated by the
counter.
• In MC8051, two timer pins are available T0 and T1, by these timers we can
give the delay of particular time if we use these in timer mode.
• We can count external pulses at these pins if we use these pins in counter
mode.
• 16 bits timers are available. Means we can generate delay between 0000H
to FFFFH.
[21]
• Two special function registers are available.
• In the same way for T1.
• TMOD, TCON registers are used for controlling timer operation.
Basic registers of the timer
Timer 0 and Timer 1 are 16 bits wide
each 16-bit timer is accessed as two separate registers of low byte and high byte.
Timer 0 registers
low byte register is called TL0 (Timer 0 low byte) and the high byte register is referred to as TH0
(Timer 0 high byte)
can be accessed like any other register, such as A, B, R0, R1, R2, etc.
"MOV TL0, #4 FH" moves the value 4FH into TL0
"MOV R5, TH0" saves TH0 (high byte of Timer 0) in R5
Timer 1 registers
also 16 bits
split into two bytes TL1 (Timer 1 low byte) and TH1 (Timer 1 high byte)
accessible in the same way as the registers of Timer 0.
TMOD (timer mode) register
timers 0 and 1 use TMOD register to set operation modes (only learn Mode 1 and 2)
8-bit register
lower 4 bits are for Timer 0
upper 4 bits are for Timer 1
[22]
lower 2 bits are used to set the timer mode
(only learn Mode 1 and 2)
upper 2 bits to specify the operation
(only learn timer operation)
Clock source for timer
timer needs a clock pulse to tick
if C/T = 0, the crystal frequency attached to the 8051 is the source of the clock for the timer
frequency for the timer is always 1/12th the frequency of the crystal attached to the 8051
XTAL = 11.0592 MHz allows the 8051 system to communicate with the PC with no errors
In our case, the timer frequency is 1MHz since our crystal frequency is 12MHz
Using Windows calculator to find TH, TL
Windows scientific calculator can be use to find the TH, TL values
Lets say we would like to find the TH, TL values for a time delay that uses 35,000 clocks of 1.085ms
open scientific calculator and select decimal
enter 35,000
[23]
select hex - converts 35,000 to hex 88B8H
select +/- to give -35000 decimal (7748H)
the lowest two digits (48) of this hex value are for TL and the next two (77) are for TH
C/T bit in TMOD register
used as a timer, the 8051's crystal is used as the source of the frequency
used as a counter, pulse outside the 8051 increments the TH, TL registers
counter mode, TMOD and TH, TL registers are the same as for the timer
timer modes are the same as well
C/T bit in TMOD register
C/T bit in the TMOD register decides the source of the clock for the timer
C/T = 0, timer gets pulses from crystal
C/T = 1, the timer used as counter and gets pulses from outside the 8051
C/T = 1, the counter counts up as pulses are fed from pins 14 and 15
pins are called T0 (Timer 0 input) and T1 (Timer 1 input)
these two pins belong to port 3
Timer 0, when C/T = 1, pin P3.4 provides the clock pulse and the counter counts up for each clock
pulse coming from that pin
Timer 1, when C/T = 1 each clock pulse coming in from pin P3.5 makes the counter count up
TCON register
[24]
TR0 and TR1 flags turn on or off the timers
bits are part of a register called TCON (timer control)
upper four bits are used to store the TF and TR bits of both Timer 0 and Timer 1
lower four bits are set aside for controlling the interrupt bits
"SETB TRl" and "CLR TRl“
"SETB TCON. 6" and "CLR TCON. 6“
Timer Func tions
When used as timers, the 8051 timers count up every 12th clock cycle. This is
selected by clearing the corresponding C/T flags in the TMOD special function
register, placed at the address 89H.
Timer modes
[25]
Table 9–2 Equivalent Instructions for the Timer Control Register (TCON)
The timers may operate in one of four modes:
Mode 0 In this mode, the timers act as 13 bit counters. This mode is largely meant for providing
compatibility with an older microcontroller from Intel(8048). This mode is practically never used in
fresh designs. Except for the counter size, this mode is identical to mode 1.
Mode 1 In this mode, the timers are 16 bits in size. This is a commonly used mode. It is common
to configured the timer to cause an interrupt when it overflows. The interrupt routine then reloads the
timer.
Mode 2 This mode provides an 8 bit counter with auto-reload. It uses the high byte of the count
register to store the count value and the low byte as the actual counter. The counter is automatically
re-loaded from TH when it overflows. Thus, there is no software overhead for re-loading the
registers. This is convenient for generating baud rates etc. The timing resolution is much lower in
this mode (only 8 bits). Therefore crystal frequencies have to be carefully chosen to generate
accurate baud rates. Crystals of 11.059MHz are often used rather than 12 MHz for this reason.
Mode 3 In this mode Timers T0 and T1 behave quite divergently. T0 acts as two independent 8 bit
counters. Count register TL0 uses the resources (such as the RUN flag, overflows flag) in TCON,
TMOD etc. meant for T0. Similarly,TH0 uses the resources meant for T1. Thus, TR1 will enable
running the 8 bit counter made up of TH0. TF1 will be set whenever TH0 overflows.T1 now has no
control bits at all! It can only be used for services which require no control, no gating and no
interrupts. Thus, T1 can be used for Baud rate generation, while we still have two timers available
(both with 8 bit resolution).
Serial Port
• There are two pins available for serial communication TXD and RXD.
• Normally TXD is used for transmitting serial data which is in SBUF register,
RXD is used for receiving the serial data.
• SCON register is used for controlling the operation.
• There are four modes of serial communication which has been discussed in
next chapter.
OSSCILLATORS
[26]
It is used for providing the clock to MC8051 which decides the speed orbaud rate of MC.
We use crystal which frequency vary from 4MHz to 30 MHz, normally we
use 11.0592 MHz frequency.
INTERRUPTS
Interrupts are defined as requests because they can be refused (masked) if
they are not used, that is when an interrupt is acknowledged. A special set
of events or routines are followed to handle the interrupts. These special
routines are known as interrupt handler or interrupt service routines (ISR).
These are located at a special location in memory.
INT0 and INT1 are the pins for external interrupts.
[27]
ARCHUTECTURE OF 8051:-
ALU Arithmetic Logical Unit: This unit is used for the arithmetic calculations.
Accumulator: This register is used for arithmetic operations. This is also bit addressable and 8 bit
register.
B-Register: This register is used in only two instructions MUL AB and DIV AB. This is also
bit addressable and 8 bit register.
PC-Program Counter
• Points to the address of next instruction to be executed from ROM
• It is 16 bit register means the 8051 can access program address from
0000H to FFFFH. A total of 64KB of code. 16 bit register means.
[28]
STACKS IN 8051:-
[29]
5.PROGRAMMING AND INTERFACING:-5.1 INPUT DEVICES INTERFACING
5.1.1 SWITCH
Fig-2.1-Various Types Of Switches
Fig. 1 Switches are used to open/close a circuit
Fig. 2 S1 is a "single pole on/off" switch in the off position
Fig. 3 This is a "2 pole on/off" switch which completely isolates the lamp from the supply in the off
position. This may be important if it is a high voltage supply. The dotted line indicates that S1a and
S1b are part of the same switch "ganged" together and operate simultaneously.
Fig. 4 This is a "single pole changeover" switch. Either lamp 1 or lamp 2 is on.
Fig. 5this is a "2 pole changeover" switch. The unlit lamp is completely isolated from the supply.
Again S1a and S1b are part of the same switch
Fig. 6this is a "single pole 5 way" switch. It can select 1 of 5 circuits. You can have 2p 5w, 3p 4w
etc
Fig. 8 This is a "changeover" slide switch. When operated a-b opens and b-c closes
[30]
1 INTERFACING WITH AT89S52-
In 8051 PORT 1, PORT 2 & PORT 3 have internal 10k Pull-up resistors whereas this Pull-up resistor
is absent in PORT 0. Hence PORT 1, 2 & 3 can be directly used to interface a switch whereas we have
to use an external 10k pull-up resistor for PORT 0 to be used for switch interfacing or for any other
input. Figure 2.2 shows switch interfacing for PORT 1, 2 & 3. Figure 2.3 shows switch interfacing to
PORT 0.
Fig 2.2 - Switch Interfacing For Port 1, 2 & 3
For any pin to be used as an INPUT PIN a HIGH (1) should be written to the pin if you don’t do this
the pin will always be read as LOW.In the above figure when the switch is not pressed the 10k resistor
provides the current needed for LOGIC 1 closure of switch provides LOGIC 0 to the controller
PIN.Let's write a small program where whenever a switch is pressed a LED is turned ON. Consider
that switch is connected to P2.0 & an LED connected to P2.1.
Program of switch interfacing-
Main()
{
P2_0==1;
SETB P2_1==0;
While(1)
{
If(P2_0==0)
{
P2_1==1;
}
Else
{
P2_1==0;
}
}
[31]
OUTPUT DEVICES INTERFACING
5.2.1 LED INTERFACING
C CODE FOR BLINKING LEDS CONNECTED ON PORT2:
#include<at89s8252.h>
void delay(unsigned int i);
void main(void)
{While(1){P2=0x00;Delay(0xffff);P2=0x00;Delay(0xff);}}void delay(unsigned int i){while(i!=0){i--;}}
Fig:-3.1-Hardware Interfacing Of Led With At89s52
[32]
3.1.2 C CODE FOR RUNNING LED CONNECTED ON PORT2:
#include<at89s8252.h>
void delay(unsigned int i);
void main (){P0=0x00;while (1){delay(0xffff);P2_0=1;delay(0xffff);P2_0=0;P2_1=1;delay(0xffff);P2_1=0;P2_2=1;delay(0xffff);P2_2=0;P2_3=1;delay(0xffff);P2_3=0;P2_4=1;delay(0xffff);P2_4=0;P2_5=1;delay(0xffff);P2_5=0;P2_6=1;delay(0xffff);P2_6=0;P2_7=1;delay(0xffff);P2_7=0;P2_0=1}}void delay(unsigned int i){while (i!=0){
i--;
}
}
5.2.2 LCD(JHD162A) INTERFACING:
[33]
On most displays, the pins are numbered on the LCD’s printed circuit board, but if not, it is quit easy
to locate pin1. Since the pin is connected to ground, it often has a thicker PCB track connected to it,
and it is generally connected to the metal work at some point.
Fig:-3.2-Jhd162a LCD(16x2)
Three command control inputs. When this line is low, data bytes transferred to the display are treated
as commands, and data bytes read from the display indicate its status. By setting the RS line high,
character data can be transferred to and from the module.
Pin 5 is (R/W) line. This line is pulled low in order to write commands or character data to the
module, or pulled high to read character data or status information from its registers.
Pin 6 is Enable (E) line. This input is used to initiate the actual transfer of commands or character data
between the module and the data lines. When writing to the display, data is transferred only on the
high to low transition of this signal. However, when reading from the display, data will become
available shortly after the low to high transition and remain available until the signal falls low again
C CODE FOR LCD DISPLAY//Program to study basics of LCD#include"AT89S8252.h"//macro directives of LCD#define LCD P1#define RS P3_3#define EN P3_4//prototyping various functions of LCDvoid delay(unsigned int d);void lcd_cmd(unsigned char c);void lcd_init(void);void cursor_position(unsigned char p);void display(unsigned char h);//program to display character 'A'void main(){
lcd_init();cursor_position(0);
[34]
display('A');}
//defining delay functionvoid delay(unsigned int d){
while(d!=0)d--;
}//subprogram to send various commands to LCDvoid lcd_cmd(unsigned char c){
delay(300);LCD=c;RS=0;EN=1;EN=0;
}//subprogram too initialize LCDvoid lcd_init(void){
lcd_cmd(0x01);lcd_cmd(0x38);lcd_cmd(0x0C);
}
//subprogram to set cursor positionvoid cursor_position(unsigned char p){
lcd_cmd(0x80+p);}
//subprogram to display data on LCDvoid display(unsigned char h){
delay(300);LCD=h;RS=1;EN=1;EN=0;
}
C CODE FOR STRING DISPLAY ON LCD:
void main()
[35]
{
while(1)
{
unsigned char name[]={"hello&"};
unsigned char group[]={"Group 3&"};
lcd_init();
cursor_position(0);
string_display(name);
cursor_position(40); //to display string on second row of LCD
string_display(group);
}
}
//function to display string
void string_display(unsigned char *s)
{
while(*s!='&')
{
display(*s);
delay(0xffff);
s++;
}
}
5.2.3 SEVEN SEGMENT DISPLAY
The 7 segment display is used as a numerical indicator on many types of test equipment.
[36]
Fig:-3.4-Basic Diagram Of A Seven Segment Display
It is an assembly of light emitting diodes which can be powered individually. They most commonly
emit red light. They are arranged and labeled as shown in the figure 3.4.
Powering all the segments will display the number 8. Powering a,b,c d and g will display the number
3. Numbers 0 to 9 can be displayed. The d.p represents a decimal point. The one shown is a common
anode display since all anodes are joined together and go to the positive supply. The cathodes are
connected individually to zero volts. Resistors must be placed in series with each diode to limit the
current through each diode to a safe value.
Early wrist watches used this type of display but they used so much current that the display was
normally switched off. To see the time you had to push a button. Common cathode displays where all
the cathodes are joined are also available. Liquid crystal displays do a similar job and consume much
less power. Alphanumeric displays are available which can show letters as well as numbers
C CODE TO INTERFACE SEVEN SEGMENT WITH AT89S52 AND DISPLAY NUMBERS 0
TO 99
#include"at89s8252.h"
void delay(unsigned int d);
void bcd(unsigned int x);
void main()
{
unsigned char i;
while(1)
{
for(i=0;i<100;i++)
{
bcd(i);
}
[37]
}
}
void delay(unsigned int d)
{
while(d!=0)
{
d--;
}
}
5.2.4 RELAY INTERFACING
The electromagnetic relay consists of a multi-turn coil, wound on an iron core, to form an
electromagnet. When the coil is energised, by passing current through it, the core becomes
temporarily magnetised.
Fig:-3.5-Basic Relay Circuit
The magnetized core attracts the iron armature. The armature is pivoted which causes it to operate one
or more sets of contacts. When the coil is de-energized the armature and contacts are released. The
coil can be energized from a low power source such as a transistor while the contacts can switch high
powers such as the mains supply. The relay can also be situated remotely from the control source.
Relays can generate a very high voltage across the coil when switched off.
This can damage other components in the circuit. To prevent this a diode is connected across the coil.
The cathode of the diode is connected to the most positive end of the coil.
[38]
Fig:-3.6-Basic Relay Leads
The spring sets (contacts) can be a mixture of normally open , normally closed and change over.The
actual contact points on the springsets are available for high current and low current operation. Relays
are devices which allow low power circuits to switch a relatively high Current/Voltage ON/OFF. For a
relay to operate a suitable pull-in & holding current should be passed through its coil. Generally relay
coils are designed to operate from a particular voltage often its 5V or 12V.
The function of relay driver circuit is to provide the necessary current (typically 25 to 70ma) to
energize the relay coil.
Fig:-3.7- Basic Relay Interfacing With At89s8252
Figure 3.7 shows the basic relay driver circuit. As you can see an NPN transistor BC547 is being used
to control the relay. The transistor is driven into saturation (turned ON) when a LOGIC 1 is written on
the PORT PIN thus turning ON the relay. The relay is turned OFF by writing LOGIC 0 on the port
pin.
[39]
5.2.5 MOTORS INTERFACING
4.1 L293D DUAL H-BRIDGE MOTOR DRIVER
L293D is a dual H-Bridge motor driver, So with one IC we can interface two DC motors which can be
controlled in both clockwise and counter clockwise direction and if you have motor with fix direction
of motion the you can make use of all the four I/Os to connect up to four DC motors. L293D has
output current of 600mA and peak output current of 1.2A per channel. Moreover for protection of
circuit from back EMF output diodes are included within the IC. The output supply (VCC2) has a
wide range from 4.5V to 36V, which has made L293D a best choice for DC motor driver.
.
Fig 4.1- Interfacing A Dc Motor Using L293d
As you can see in the circuit, three pins are needed for interfacing a DC motor (A, B, Enable). If you
want the o/p to be enabled completely then you can connect Enable to VCC and only 2 pins needed
from controller to make the motor work.
As per the truth mentioned in the image above its fairly simple to program the microcontroller. Its also
clear from the truth table of BJT circuit and L293D the programming will be same for both of them,
just keeping in mind the allowed combinations of A and B. We will discuss about programming in C
as well as assembly for running motor with the help of a microcontroller
The ADC0804 family is CMOS 8-Bit, successive-approximation A/D converters which use a modified
potentiometer ladder and are designed to operate with the 8080A control bus via three-state outputs.
These converters appear to the processor as memory locations or I/O ports, and hence no interfacing
logic is required. The differential analog voltage input has good common mode- rejection and permits
offsetting the analog zero-input voltage value. In addition, the voltage reference input can be adjusted
to allow encoding any smaller analog voltage span to the full 8 bits of resolution.
5.1.1 Features
• 80C48 and 80C80/85 Bus Compatible - No Interfacing Logic Required
• Conversion Time < 100us
• Easy Interface to Most Microprocessors
• Differential Analog Voltage Inputs
• TTL Compatible Inputs and Outputs
• On-Chip Clock Generator
• 0V to 5V Analog Voltage Input Range (Single + 5V Supply)
• No Zero-Adjust Required
5.1.2 ADC-0804 PIN DIAGRAM
Fig.-5.1-adc-0804 pin diagram
Hardware interfacing of ADC-0804
[42]
R 21 0 K
C 61 0 u F 1 6 V
V C C
C 1 31 0 4
EOC
SOC
V C C
C 1 41 u f / 1 6 v
R 62 2 0 E
U 4A D C 0 8 0 4
+ I N6
-I N7
AG
ND
8V R E F / 2
9
GN
D10
D B 71 1 D B 61 2 D B 51 3 D B 41 4 D B 31 5 D B 21 6 D B 11 7 D B 01 8
C L K R1 9
VC
C/V
RE
F20
C L K I N4
I N TR5
C S1
R D2
W R3
V C C
R 51 0 K
R 1 71 0 K
C 71 5 0 p F
U 2 1TL 4 3 1
23
1
C 81 u f / 1 6 v
C 9C A P
R SE N
L C D
C O N 1 6 _ 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
V C CR S E N R 5 5
5 6 E
Temprature monitoring system
U 2 2 L M 3 5 / S O
G N D3
V C C1
2
O U TP U T
R 5 31 k
V C C
U 2
A T8 9 S 8 2 5 2
R S T9
XTA L 21 8 XTA L 11 9
GN
D20
P S E N2 9 A L E / P R O G3 0
EA
/VP
P31
VC
C40
P 1 . 0 / T21
P 1 . 1 / T2 -E X2
P 1 . 23
P 1 . 34
P 1 . 4 / S S5
P 1 . 5 / M O S I6
P 1 . 6 / M I S O7
P 1 . 7 / S C K8
P 2 . 0 / A 82 1
P 2 . 1 / A 92 2
P 2 . 2 / A 1 02 3
P 2 . 3 / A 1 12 4
P 2 . 4 / A 1 22 5
P 2 . 5 / A 1 32 6
P 2 . 6 / A 1 42 7
P 2 . 7 / A 1 52 8
P 3 . 0 / R XD1 0
P 3 . 1 / TXD1 1
P 3 . 2 / I N T0 1 2
P 3 . 3 / I N T11 3
P 3 . 4 / T01 4
P 3 . 5 / T11 5
P 3 . 6 / W R1 6
P 3 . 7 / R D1 7
P 0 . 0 / A D 03 9 P 0 . 1 / A D 13 8 P 0 . 2 / A D 23 7 P 0 . 3 / A D 33 6 P 0 . 4 / A D 43 5 P 0 . 5 / A D 53 4 P 0 . 6 / A D 63 3 P 0 . 7 / A D 73 2
C 43 3 p F
C 53 3 p F
Y 2
C R Y S TA L
12
3
4
V C CV C C
Fig.-5.2- hardware interfacing of adc-0804 for temperature monitoring
When interfacing is being done then gets lowered then only it allows the controller to read the
4 REN 9ChReceiver Enable. This bit must be set in order to receive
characters.
3 TB8 9Bh Transmit bit 8. The 9th bit to transmit in mode 2 and 3.
2 RB8 9Ah Receive bit 8. The 9th bit received in mode 2 and 3.
1 TI 99h Transmit Flag. Set when a byte has been completely transmitted.
0 RI 98h Receive Flag. Set when a byte has been completely received.
SERIAL TRANSMISSION INTERFACING
SPT RXD
SPT TXD
U 5
A T8 9 S 8 2 5 2
R S T9
XTA L 21 8 XTA L 11 9
GN
D20
P S E N2 9
A L E / P R O G3 0
EA
/VP
P31
VC
C40
P 1 . 0 / T21
P 1 . 1 / T2 -E X2
P 1 . 23
P 1 . 34
P 1 . 4 / S S5
P 1 . 5 / M O S I6
P 1 . 6 / M I S O7
P 1 . 7 / S C K8
P 2 . 0 / A 82 1
P 2 . 1 / A 92 2
P 2 . 2 / A 1 02 3
P 2 . 3 / A 1 12 4
P 2 . 4 / A 1 22 5
P 2 . 5 / A 1 32 6
P 2 . 6 / A 1 42 7
P 2 . 7 / A 1 52 8
P 3 . 0 / R XD1 0P 3 . 1 / TXD1 1
P 3 . 2 / I N T01 2
P 3 . 3 / I N T11 3
P 3 . 4 / T01 4
P 3 . 5 / T11 5
P 3 . 6 / W R1 6P 3 . 7 / R D1 7
P 0 . 0 / A D 03 9
P 0 . 1 / A D 13 8
P 0 . 2 / A D 23 7
P 0 . 3 / A D 33 6
P 0 . 4 / A D 43 5
P 0 . 5 / A D 53 4
P 0 . 6 / A D 63 3
P 0 . 7 / A D 73 2
C 1 63 3 p F
C 1 73 3 p F
Y 4
C R Y S TA L
123
4
V C CV C C
R 41 0 K
C 1 81 0 u F 1 6 V
V C C
C 1 91 0 4
C 2 01 0 U F / 1 6 V
C 2 11 0 U F / 1 6 V
V C C
V C C
C 2 21 0 U F / 1 6 V
C 2 31 0 4
C 2 4 1 0 U F / 1 6 V
U 6
M A X2 3 2
C 1 +1
C 1 -3
C 2 +4
C 2 -5
VC
C16
GN
D15
V +2
V -6
R 1 O U T1 2
R 2 O U T9
T1 I N1 1
T2 I N1 0
R 1 I N1 3
R 2 I N8
T1 O U T1 4
T2 O U T7
J 7
S E R I A L P O R T O F P C
123
Fig.7.1-Max232 Interfacing With At89s52 For Serial Transmission
C- CODE FOR SERIAL TRANSMISSION(FROM MICROCONTROLLER TO PC)
#include<at89s8252.h>
void Init_SPT(void);
void transmit_serial(unsigned char a);
void delay(unsigned int i);
void main(void)
{
Init_SPT();
while(1)
{
delay(0XFFFF);
transmit_serial('N');
delay(0XFFFF);
transmit_serial('E');
delay(0XFFFF);
transmit_serial('T');
delay(0XFFFF);
transmit_serial('M');
delay(0XFFFF);
transmit_serial('A');
delay(0XFFFF);
[46]
transmit_serial('X');
delay(0XFFFF);
}
}
void Init_SPT(void)
{
TMOD=0x20;
TH1=0xfd;
TR1=1;
SCON=0x40;
}
void transmit_serial(unsigned char a)
{
SBUF=a;
delay(500);
TI=0;
}
void delay(unsigned int i)
{
while(i!=0)
{
i--;
}
}
ELECTRONIC VOTING MACHINE USING 8051
MICROCONTROLLER
[47]
List of Contents
Abstract 50
1. Background 51
2. Microcontroller 56
2.1 Introduction 56
2.2 History 56
2.3 Definition of a Microcontroller 58
2.4 Microcontrollers vs Microprocessors 58
2.5 Memory Unit 58
2.6 Central Processing Unit 59
2.7 Bus 59
2.8 Input Output Unit 59
2.9 Serial Communication 60
2.10 Timer Unit 60
2.11 Watch Dog 61
2.12 Analog to Digital Converter 61
3. Introduction to 16X2 LCD Display 63
3.1 Pin description 63
3.2 DDRAM - Display Data RAM 64
3.3 BF - Busy Flag 64
3.4 Instruction Register (IR) and Data Register (DR) 64
3.5 Commands and Instruction set 64
3.6 Sending Commands to LCD 64
4. Project Description 65
4.1 Block diagram 65
4.2 General working 65
4.3 C language code 68
5. Project Methodology 72
5.1 Components 72
5.2 Software used 72
5.3 Equipments used 72
[48]
6. Result and Conclusion 73
7. Applications 73
8. Future Scope 73
9. References and Bibliography 74
ABSTRACT
India is world’s largest democracy. It is perceived to be charismatic one as it
accommodates cultural, regional, economical, social disparities and still is able to stand on its own.
Fundamental right to vote or simply voting in elections forms the basis of Indian democracy.
[49]
In India all earlier elections be it state elections or centre elections a voter used to cast his/her
vote to his/her favorite candidate by putting the stamp against his/her name and then folding the
ballot paper as per a prescribed method before putting it in the Ballot box. This is a long, time-
consuming process and very much prone to errors. This situation continued till election scene was
completely changed by electronic voting machine. No more ballot paper, ballot boxes, stamping,
etc. all this condensed into a simple box called ballot unit of the electronic voting machine.
EVM is capable of saving considerable printing stationery and transport of large volumes of electoral
material. It is easy to transport, store, and maintain. It completely rules out the chance of invalid
votes. Its use results in reduction of 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. It is also eco friendly. Our EVM consists of one microcontroller
AT89S52. The unit consists of one LCD, 6 push buttons, couple of switches, an LED and a buzzer,
etc. The port 0 of microcontroller is used for interfacing the led, port 2 is used for control
switches, port 3 is used for Interfacing push buttons for voting.
BACKGROUND
Democracy and Voting
Democracy has come to be accepted as the most preferred form of political system all over the
world. However, the success of a democratic structure is to be judged by the successes that can be
[50]
solely attributed to this system. There are various challenges before democracy. These are
foundational challenges, challenge of expansion and deepening of democracy. All of these are
dependent on how the democracy is perceived by people who form the government, participate in
formation of government and are benefited by it. As we all know that India is world’s largest
democracy. It is perceived to be charismatic one as it accommodates cultural, regional, econo mical,
social disparities and still is able
to stand on its own. India follows a federal form of government. It means that governance power is
not residing with one authority, but is distributed at various levels. In India power is distributed
between states and central authority.
What forms the basis of such vast and complex system of governance?
One needs not to be an Einstein to guess the answer. It is fundamental right to vote or
simply voting in elections.
Indian constitution provide every adult above the age of 18 years irrespective of his/her
religion, region, caste, creed, color, economic status, education and sex the essential right
to vote and elect her/his candidate to represent her/him.
Hence voting can be termed as backbone of not just democracy in India but all around the
world. Voting can be done in various ways. In early Roman Empire voting used to be
done by raising hands in favor or against. In board rooms voting is done in similar way,
some write their vote down, some choose to speak, some choose to cast vote using latest
technology.
Voting Techniques
In India all earlier elections be it state elections or centre elections a voter used to cast
his/her vote to his/her favorite candidate by putting the stamp against his/her name and
then folding the ballot paper as per a prescribed method before putting it in the Ballot
box. This is a long, time-consuming process and very much prone to errors.
This method wanted voters to be skilled voters to know how to put a stamp, and
methodical folding of ballot paper. Millions of paper would be printed and heavy ballot
boxes would be loaded and unloaded to and from ballot office to polling station. All this
continued till election scene was completely changed by electronic voting machine. No
more ballot paper, ballot boxes, stamping, etc. all this condensed into a simple box called
ballot unit of the electronic voting machine.
The marking system of voting was introduced in 1962 to make it possible for a
substantial number of illiterate voters to indicate easily their preferences in choosing their
representatives. Over the years, there was a pronounced increase in the volume of work:
crores of ballot papers had to be printed and lakhs of ballot boxes had to be prepared,
transported, and kept in storage; and a great amount of time was taken up by the conduct
[51]
of elections. To overcome these difficulties, the Election Commission of India (ECI)
thought of electronic gadgets. The Electronics Corporation of India Ltd. (ECIL),
Hyderabad, and Bharat Electronics Ltd. (BEL), Bangalore, developed the electronic
voting machine in 1981.
The Electronic Voting Machine
The complete EVM consists mainly of two units - (a) Control Unit and (b) Balloting Unit
with cable for connecting it with Control unit. A Balloting Unit caters upto 16 candidates.
Four Balloting Units linked together catering in all to 64 candidates can be used with one
control unit. The control unit is kept with the Presiding Officer and the Balloting Unit is
used by the voter for polling.
The Balloting Unit of EVM is a small Box-like device, on top of which each candidate
and his/her election symbol is listed like a big ballot paper. Against each candidate's
name, a red LED and a blue button is provided. The voter polls his vote by pressing the
blue button against the name of his desired candidate.
How the Vote is cast with this EVM?
The entire process is very easy to understand:
• Like in earlier system, your name is called and you are asked to sign or put your
thumb impression in a register.
• After your identification is done by Election Officer, an ink mark is put on your
finger, same as earlier.
• Then the Election Officer gives you a slip that bears the Voter register number
where you signed or put your thumb impression.
• 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.
• 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. On the Balloting Unit of EVM, you press the button placed in front
of your favorite candidate and release.
Compare and Contrast: Paper Voting and EVM
We have so far discussed three different voting systems. These systems are being used or
considered obsolete because of certain positive and negative points. These are
summarized as follows:
[52]
Device type
Ballot paper : Papers and boxes
EVM : Embedded system with Assembly code
Visual Output
Ballot paper : Stamp on paper
EVM : Single LED against each candidate's name
Operating System/ Software
Ballot paper : No operating system
EVM : None, the Assembly code to register number of votes is all it has
Hence it is simple automation of voting, no complexities.
Records/ Audits
Ballot paper : Manual counting to be done by officials, lengthy, time consuming
Process. Inaccurate due to human errors.
EVM : The Voting unit doesn't store anything, the control unit records the number of votes cast for
each candidate against his serial number.
No record to link person-to-vote.
Control and Operation
Ballot paper: Manual operation
EVM : Automatic operation. The control Unit accumulates the votes, it is a device with flash
storage and seven segment LED displays. The ballot unit has a button to issue a ballot for a voter.
Security Issues
Ballot paper : No security provided by the system, neither during polling nor during voting.
EVM : During polling, a facility is provided to seal the machine in case of booth
capturing. No further voting can be done afterwards.
Ballot Issue
Ballot paper : Ballot paper is issued by Electoral officer on which voter could cast his vote.
EVM : Ballot is issued by Electoral officer by pressing a button on the control Unit.
It allows the voter to press any button on the ballot unit to cast his vote.
Storage of Votes
Ballot paper : In ballot boxes assigned for the purpose of storing votes, highly insecure method
of storage.
EVM : In Internal Non removable memory of the Control Units. No transfer over
network. Security increases with this feature. Moreover these results cant be accessed by authorized
[53]
personnel
only at commissioned offices..
Cost of the System
Ballot paper : High cost of paper printing in millions and low speed of the whole process.
EVM : About 12000 INR (300$) for one EVM.
Power Supply
Ballot paper : No power supply required.
EVM : 6V alkaline batteries or electricity.
Capacity
Ballot paper : As much a ballot box can hold.
EVM : 3840 Votes .
Existing System
But this electronic voting machine has its disadvantages too. These areas of deficiency
are not much of a concern to a layman, but for an intelligent voter this must be eliminated
for a secure election. The few technical disadvantages are given as:
• Microprocessor based design, which requires a no. of supporting components like
memory, peripheral interface, etc.
• No security against illegal viewing of results, as presiding officer can view the
results without any difficulty.
• Less user friendly due to two seven segment displays
• Existing system costs high.
Proposed System
All these faults motivated us to make this new enhanced EVM. The faults which are
eliminated are summarized as follows:
• Microcontroller replaced microprocessor, which made the EVM closer to real
time operation making it faster, more reliable and unique.
• More user friendly and interactive LCD display
• Proposed system costs less.
• As soon as the button is pressed, the LED indicator lights off and a whistle sound
comes from the machine. This signifies that your vote has been casted rightly.
Now you can come out.
• In case of LED not not being turned off, press the button firmly again. If finding it
difficult, consult the Presiding Officer.
[54]
• Your vote is complete safe and secret and there is no room for error as well. You
can rest assured that your vote is not going to be invalid in any case.
• The Voting Machine is attached to the 'Control Unit'. When the user presses the
button, his vote is registered in the control unit and the number of votes for the
respective candidates is calculated automatically.
Booth Capture
A remarkable advantage is that rigging is not possible with the EVMs. In the ballot paper
system, the intruders can mark hundreds of ballots and put them into the ballot box in a
matter of a few minutes. This is not possible in voting machines as the machine is
designed to cast only one vote and for the next vote to be casted the presiding officer
should make it ready by pressing the related button. Thus the presiding officer can have a
complete control of voting and avoid any kind of malpractices
The EVMs have following advantages:
• 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.
[55]
2. MICROCONTROLLERS
2.1 Introduction
Circumstances that we find ourselves in today in the field of microcontrollers had their
beginnings in the development of technology of integrated circuits. This development has
made it possible to store hundreds of thousands of transistors into one chip. That was a
prerequisite for production of microprocessors, and the first computers were made by
adding external peripherals such as memory, input-output lines, timers and other. Further
increasing of the volume of the package resulted in creation of integrated circuits. These
integrated circuits contained both processor and peripherals. That is how the first chip
containing a microcomputer, or what would later be known as a microcontroller came
about.
2.2 History
It was year 1969, and a team of Japanese engineers from the BUSICOM Company
arrived to United States with a request that a few integrated circuits for calculators be
made using their projects. The proposition was set to INTEL, and Marcian Hoff was
responsible for the project. Since he was the one who has had experience in working with
a computer (PC) PDP8, it occurred to him to suggest a fundamentally different solution
instead of the suggested construction. This solution presumed that the function of the
integrated circuit is determined by a program stored in it. That meant that configuration
would be simpler, but that it would require far more memory than the project that was
proposed by Japanese engineers would require. After a while, though Japanese engineers
tried finding an easier solution, Marcian's idea won, and the first microprocessor was
born. In transforming an idea into a ready made product, Frederico Faggin was a major
help to INTEL. He transferred to INTEL, and in only 9 months had succeeded in making
a product from its first conception. INTEL obtained the rights to sell this integral block in
1971. First, they bought the license from the BUSICOM Company who had no idea what
treasure they had. During that year, there appeared on the market a microprocessor called
4004. That was the first 4-bit microprocessor with the speed of 6 000 operations per second.
Not long after that, American company CTC requested from INTEL and Texas
Instruments to make an 8-bit microprocessor for use in terminals. Even though CTC gave
up this idea in the end, Intel and Texas Instruments kept working on the microprocessor
and in April of 1972, first 8-bit microprocessor appeared on the market under a name
8008.
[56]
2.3 Definition of a Microcontroller
Microcontroller, as the name suggests, are small controllers. They are like single chip
computers that are often embedded into other systems to function as
processing/controlling unit. For example, the remote control you are using probably has
microcontrollers inside that do decoding and other controlling functions. They are also
used in automobiles, washing machines, microwave ovens, toys ... etc, where automation
is needed.
The key features of microcontrollers include:
• High Integration of Functionality
• Microcontrollers sometimes are called single-chip computers because they have
on-chip memory and I/O circuitry and other circuitries that enable them to
function as small standalone computers without other supporting circuitry.
• Field Programmability, Flexibility
• Microcontrollers often use EEPROM or EPROM as their storage device to allow
field programmability so they are flexible to use. Once the program is tested to be
correct then large quantities of microcontrollers can be programmed to be used in
embedded systems.
• Easy to Use
[57]
2.4 Microcontrollers versus Microprocessors
Microcontroller differs from a microprocessor in many ways. First and the most
important is its functionality. In order for a microprocessor to be used, other components
such as memory, or components for receiving and sending data must be added to it. In
short that means that microprocessor is the very heart of the computer. On the other hand,
microcontroller is designed to be all of that in one. No other external components are
needed for its application because all necessary peripherals are already built into it. Thus,
we save the time and space needed to construct devices.
2.5 Memory unit
Memory is part of the microcontroller whose function is to store data.
The easiest way to explain it is to describe it as one big closet with lots of drawers. If we
suppose that we marked the drawers in such a way that they cannot be confused, any of
their contents will then be easily accessible. It is enough to know the designation of the
drawer and so its contents will be known to us for sure.
Typically, the amount of ROM type memory will vary between around 512 bytes and
4096 bytes, although some 16 bit microcontrollers such as the Hitachi H8/3048 can have
as much as 128 Kbytes of ROM type memory. ROM type memory, as has already been mentioned,
is used to store the program code. ROM memory can be ROM (as in One Time Programmable
memory), EPROM, or EEPROM. The amount of RAM memory is usually somewhat smaller,
typically ranging between 25 bytes to 4 Kbytes. RAM is used for data storage and stack
management tasks. It is also used for register stacks (as in the microchip PIC range of
microcontrollers). [58]
2.6 Central Processing Unit
Let add 3 more memory locations to a specific block that will have a built in capability to
multiply, divide, subtract, and move its contents from one memory location onto another.
The part we just added in is called "central processing unit" (CPU). Its memory locations
are called registers.
2.7 Bus
That "way" is called "bus". Physically, it represents a group of 8, 16, or more wires.
There are two types of buses: address and data bus. The first one consists of as many
lines as the amount of memory we wish to address and the other one is as wide as data, in
our case 8 bits or the connection line. First one serves to transmit address from CPU
memory, and the second to connect all blocks inside the microcontroller.
Figure2.4: Showing connection between memory and central unit using buses
2.8 Input-output unit
Those locations we've just added are called "ports". There are several types of ports:
input, output or bidirectional ports. When working with ports, first of all it is necessary to
choose which port we need to work with, and then to send data to, or take it from the
port.
2.9 Serial communication
[59]
Beside stated above we've added to the already existing unit the possibility of
communication with an outside world. However, this way of communicating has its
drawbacks. One of the basic drawbacks is the number of lines which need to be used in
order to transfer data. What if it is being transferred to a distance of several kilometers?
The number of lines times’ number of kilometers doesn't promise the economy of the
project. It leaves us having to reduce the number of lines in such a way that we don't
lessen its functionality. Suppose we are working with three lines only, and that one line is
used for sending data, other for receiving, and the third one is used as a reference line for
both the input and the output side. In order for this to work, we need to set the rules of
exchange of data. These rules are called protocol. Protocol is therefore defined in
advance so there wouldn't be any misunderstanding between the sides that are
communicating with each other. For example, if one man is speaking in French, and the
other in English, it is highly unlikely that they will quickly and effectively understand
each other. Let's suppose we have the following protocol. The logical unit "1" is set up on
the transmitting line until transfer begins.
Figure2.6: Serial unit sending data through three lines only
2.10 Timer unit
Since we have the serial communication explained, we can receive, send and process
data. However, in order to utilize it in industry we need a few additionally blocks. One of those
is the timer block which is significant to us because it can give us information about time,
duration, protocol etc. The basic unit of the timer is a free-run counter which is in fact a
register whose numeric value increments by one in even intervals, so that by taking its
value during periods T1 and T2 and on the basis of their difference we can determine
how much time has elapsed. This is a very important part of the microcontroller whose
understanding requires most of ourtime.
2.12 Analog to Digital Converter
[60]
As the peripheral signals usually are substantially different from the ones that
microcontroller can understand (zero and one), they have to be converted into a pattern
which can be comprehended by a microcontroller. This task is performed by a block for
analog to digital conversion or by an ADC. This block is responsible for converting an
information about some analog value to a binary number and for follow it through to a
CPU block so that CPU block can further process it.
Figure2.9: Block for converting an analog input to digital output
Finally, the microcontroller is now completed, and all we need to do now is to assemble it
into an electronic component where it will access inner blocks through the outside pins.
The picture below shows what a microcontroller looks like inside.
Figure2.10: Physical configuration of the interior of a microcontroller
Thin lines which lead from the center towards the sides of the microcontroller represent
wires connecting inner blocks with the pins on the housing of the microcontroller so
called bonding lines. Chart on the following page represents the center section of a
microcontroller.
[61]
Figure2.11: Microcontroller outline with basic elements and internal connections
2.13 AT89S52 microcontroller:
The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K
bytes of in-system programmable Flash memory. The device is manufactured using
Atmel’s high-density nonvolatile memory technology and is compatible with the indus-
try-standard 80C51 instruction set and pinout. The on-chip Flash allows the program
memory to be reprogrammed in-system or by a conventional nonvolatile memory pro-
grammer. By combining a versatile 8-bit CPU with in-system programmable Flash on a
monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides a
highly-flexible and cost-effective solution to many embedded control applications.
[62]
3. INTRODUCTION TO 16X2 LCD DISPLAY
LCD stands for Liquid Crystal Display. The most commonly used LCDs found in the
market today are 1 Line, 2 Line or 4 Line LCDs which have only 1 controller and support
at most of 80 characters.
3.1 Pin Description
Most LCDs with two controllers has 16 Pins. Pin description is shown in the table
below.
Pin No. Name Description
Pin no. 1 D7 Data bus line 7 (MSB)
Pin no. 2 D6 Data bus line 6
Pin no. 3 D5 Data bus line 5
Pin no. 4 D4 Data bus line 4
Pin no. 5 D3 Data bus line 3
Pin no. 6 D2 Data bus line 2
Pin no. 7 D1 Data bus line 1
Pin no. 8 D0 Data bus line 0 (LSB)
Pin no. 9 EN1 Enable signal for row 0 and 1 (1stcontroller)
Pin no. 12 VEE Contrast adjust
Pin no. 13 VSS Power supply (GND)
Pin no. 14 VCC Power supply (+5V)
Pin no. 15 EN2 Enable signal for row 2 and 3 (2ndcontroller)
Pin no. 16 NC Not Connected
Table No.3.1: Pin description of the LCD
[63]
3.2 DDRAM - Display Data RAM
Display data RAM (DDRAM) stores display data represented in 8-bit character codes. Its
extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM
(DDRAM) that is not used for display can be used as general data RAM. So whatever
you send on the DDRAM is actually displayed on the LCD.
3.3 BF - Busy Flag
Busy Flag is a status indicator flag for LCD. When we send a command or data to the
LCD for processing, this flag is set (i.e. BF =1) and as soon as the instruction is executed
successfully this flag is cleared (BF = 0). This is helpful in producing and exact amount
of delay. For the LCD processing. To read Busy Flag, the condition RS = 0 and R/W = 1
must be met and The MSB of the LCD data bus (D7) act as busy flag. When BF = 1
means LCD is busy and will not accept next command or data and BF = 0 means LCD is
ready for the next command or data to process.
3.4 Instruction Register (IR) and Data Register (DR)
There are two 8-bit registers controller Instruction and Data register. Instruction register
corresponds to the register where you send commands to LCD e.g. LCD shift command,
LCD clear, LCD address etc. and Data register is used for storing data which is to be
displayed on LCD. When send the enable signal of the LCD is asserted, the data on the
pins is latched in to the data register and data is then moved automatically to the
DDRAM and hence is displayed on the LCD.
3.5 Commands and Instruction set
Only the instruction register (IR) and the data register (DR) of the LCD can be controlled
by the MCU. Before starting the internal operation of the LCD, control information is
temporarily stored into these registers to allow interfacing with various MCUs, which
operate at different speeds, or various peripheral control devices. The internal operation
of the LCD is determined by signals sent from the MCU.
3.6 Sending Commands to LCD
To send commands we simply need to select the command register. Everything is same
as we have done in the initialization routine. But we will summarize the common steps
and put them in a single subroutine.
Following are the steps:
Move data to LCD port
Select command register
select write operation
[64]
send enable signal
PROJECT DESCRIPTION:-
BLOCK DIAGRAM
GENERAL WORKING:-1. Initially when the switch is closed, allows the evm to take the vote. the vote is taken only when push button is pressed and led D1 is switched ON.
[65]
2. A push button is assigned to each party. When the push button of the desired party is
pressed, the led is switched off which indicates that the vote is cast and the buzzer gives a
beep.
[66]
Again the push button is pressed so that the evm is ready to take the next vote which
isindicated through the led D1.The same process is repeated until all the voters cast theirvotes.
3. To view the results of each respective party, the switch must be opened
4. To know the result of the party, the push button of the respective party must be pressed so that the
number of votes cast for the party is displayed on the lcd screen.
[67]
This process is repeated to know the results of each party.