Professional Documents
Culture Documents
On
EMBEDDED SYSTEM AND 8051
MICROCONTROLLER
Submitted
By
MANDEEP CHAUHAN
1214046
2014-2018
(JMIT)
ACKNOWLEGEMENT
From where I have received my training in embedded system that mainly focuses on a 8051
Microcontroller This little work would not have been possible without the kind help,
Mr.ABHISHEK TIWARI , main incharge at ASPL institute. Also highly indebted to JMIT
RADAUR which provided direction and opportunity to obtain training at the institute. I
their support and motivation provided to me. Lastly, I would like to thank the almighty and
MANDEEP CHAUHAN
1214046
JMIT RADAUR
LIST OF FIGURES
2.5 B register 11
3.1 Timer 0 15
3.5 Timer 1 22
6. PROJECT 36
7. CONCLUSION AND BIBLOGRAPHY 41-42
CHAPTER-1
IntroductionTo Embedded System
CPU
GeneralMICR Serial
OCONTROL RAM ROM I/O Timer COM
LERS Port Port
(MCU)-
Purpose
P3.1 TXD 11
P3.2 INT0 12
P3.3 INT1 13
P3.4 T0 14
P3.5 T1 15
P3.6 WR 16
P3.7 RD 17
Figure2.4:Accumulator Register
2.8 B Register:
B register is same as that of accumulator of. It is also an 8 bit register and every bit of this is
accessible. This is also a mathematical register B which is used mostly for multiplication and
division.
Figure2.5:B register
2.9 PSW (Program Status Word) Register
Program status word register is an 8 bit register. It is also referred to as the flag register.
Although the PSW register is 8 bits wide, only 6 bits of it are used by the 8051. The unused
bits are user-definable flags. Four of the flags are called conditional flags, meaning that they
Indicate some conditions that result after an instruction is executed. These four are CY
(carry), AC (auxiliary carry), P (parity) and OV (overflow).
CY PSW.7 Carry Flag
AC PSW.6 Auxiliary Carry Flag
F0 PSW.5 Available to the user for
General Purpose
RS1 PSW.4 Register Bank Selector Bit 1
RS0 PSW.3 Register Bank Selector
Bit 0
OV PSW.2 Overflow Flag
-- PSW.1 User Definable Bit
P PSW.0 Parity Flag.
Bank 1 0 1
Bank 2 1 0
Bank 3 1 1
TIMER 1 TIMER 0
Figure3.2-TMOD register
Bits of this register have the following function:
GATE1: enables and disables Timer 1 by means of a signal brought to the INT1 pin (P3.3):
1: Timer 1 operates only if the INT1 bit is set.
0:Timer 1 operates regardless of the logic state of the INT1 bit.
C/T1: selects pulses to be counted up by the timer/counter 1:
1: Timer counts pulses brought to the T1 pin (P3.5).
0 1:Timer counts pulses from internal oscillator.
T1M1, T1M0: These two bits select the operational mode of the Timer 1.
GATE0: enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2).
1 :Timer 0 operates only if the INT0 bit is set.
T1M1 T1M0 Mode Description
0 0 0 13-bit timer
0 1 1 16-bit timer
1 0 2 8-bit auto reload
1 1 3 Split mode
Table 3.1:Timer 1
0: Timer 0 operates regardless of the logic state of the INT0 bit.
C/T0:selects pulses to be counted up by the timer/counter 0:
1: Timer counts pulses brought to the T0 pin (P3.4).
0: Timer counts pulses from internal oscillator.
Tom1 T0m0 Mode Description
0 0 0 13-Bit Timer
0 1 1 16-Bit Timer
1 0 2 8-Bitauto Reload
1 1 3 Split Mode
Table 3.2:Timer 0
T0M1, T0M0: These two bits select the operational mode of the Timer 0.
Timer 0 in mode 0 (13-bit timer)
This is one of the rarities being kept only for the purpose of compatibility with the previuos
versions of microcontrollers. This mode configures timer 0 as a 13-bit timer which consists of
all 8 bits of TH0 and the lower 5 bits of TL0. As a result, the Timer 0 uses only 13 of 16 bits.
How does it operate? Each coming pulse causes the lower register bits to change their states.
After receiving 32 pulses, this register is loaded and automatically cleared, while the higher
byte (TH0) is incremented by 1. This process is repeated until registers count up 8192 pulses.
After that, both registers are cleared and counting starts from 0.
Timer 0 in mode 1 (16-bit timer)
Mode 1 configures timer 0 as a 16-bit timer comprising all the bits of both registers TH0 and
TL0. That's why this is one of the most commonly used modes. Timer operates in the same
way as in mode 0, with difference that the registers count up to 65 536 as allowable by the 16
bits.
Timer 0 in mode 2 (Auto-Reload Timer)
Mode 2 configures timer 0 as an 8-bit timer. Actually, timer 0 uses only one 8-bit register for
counting and never counts from 0, but from an arbitrary value (0-255) stored in another
(TH0) register.If mode 1 or mode 0 is used, It is necessary to write the number 200 to the
timer registers and constantly check whether an overflow has occured, i.e. whether they
reached the value 255. When it happens, it is necessary to rewrite the number 200 and repeat
the whole procedure. The same procedure is automatically performed by the microcontroller
if set in mode 2. In fact, only the TL0 register operates as a timer, while another (TH0)
register stores the value from which the counting starts. When the TL0 register is loaded,
instead of being cleared, the contents of TH0 will be reloaded to it. Referring to the previous
example, in order to register each 55th pulse, the best solution is to write the number 200 to
the TH0 register and configure the timer to operate in mode 2.
Timer 0 in Mode 3 (Split Timer)
Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit timers. In
other words, the 16-bit timer consisting of two registers TH0 and TL0 is split into two
independent 8-bit timers. This mode is provided for applications requiring an additional 8-bit
timer or counter. The TL0 timer turns into timer 0, while the TH0 timer turns into timer 1. In
addition, all the control bits of 16-bit Timer 1 (consisting of the TH1 and TL1 register), now
control the 8-bit Timer 1. Even though the 16-bit Timer 1 can still be configured to operate in
any of modes (mode 1, 2 or 3), it is no longer possible to disable it as there is no control bit to
do it. Thus, its operation is restricted when timer 0 is in mode 3.
3.1.2 Timer Control (TCON) Register:
TCON register is also one of the registers whose bits are directly in control of timer
operation. Only 4 bits of this register are used for this purpose, while rest of them is used for
interrupt control to be discussed later.
Figure 3.3:Timer1 and Timer0 Operation Modes
TF1: bit is automatically set on the Timer 1 overflow.
TR1: bit enables the Timer 1.
1:Timer 1 is enabled.
Figure 3.5:Timer 1
4.4 Reset
Reset occurs when the RS pin is supplied with a positive pulse in duration of at least 2
machine cycles (24 clock cycles of crystal oscillator). After that, the microcontroller
generates an internal reset signal which clears all SFRs, except SBUF registers, Stack Pointer
and ports (the state of the first two ports is not defined, while FF value is written to the ports
configuring all their pins as inputs). Depending on surrounding and purpose of device, the RS
pin is usually connected to a power-on reset push button or circuit or to both of them. Figure
below illustrates one of the simplestcircuits providing safe power-on reset.
CHAPTER-5
Interfacing
Interfacing
5.1 LED interfacing
Like a normal diode, an LED consists of a chip of semiconducting material impregnated, or
doped, with impurities to create a p-n junction. As in other diodes, current flows easily from
the p-side, or anode, to the n-side, or cathode, but not in the reverse direction. Charge-
carrierselectrons and holes flow into the junction from electrodes with different voltages.
When an electron meets a hole, it falls into a lower energy level, and releases energy in the
form of a photon. The wavelength of the light emitted, and therefore its color, depends on the
band gap energy of the materials forming the p-n junction. In silicon or germanium diodes, the
electrons and holes recombine by a non-radiativetransition which produces no optical
emission, because these are indirect band gap materials. The materials used for an LED have a
direct band gap with energies corresponding to near-infrared, visible or near-ultraviolet light.
LED development began with infrared and red devices made with gallium arsenide. Advances
in materials science have made possible the production of devices with ever-shorter
wavelengths, producing light in a variety ofcolors.Conventional LEDs are made from a
variety of inorganic semiconductor materials, producing the following colors:
Aluminium gallium arsenide (AlGaAs) red and infrared
Aluminium gallium phosphide (AlGaP) green
Aluminium gallium indium phosphide (AlGaInP) high-brightness
orange-red, orange, yellow, and green
Gallium arsenide phosphide (GaAsP) red, orange-red, orange, and yellow
Gallium phosphide (GaP) red, yellow and green
Gallium nitride (GaN) green, pure green (or emerald green), and blue
also white (if it has an AlGaN Quantum Barrier)
/* PROGRAM TO GLOW LED*/
#include<reg51.h>
void delay()
{
int a;
for(a=0;a<=30000;a++);
}
void main()
{
while(1)
{
P2=0x00;
delay();
P2=0xFF;
delay();
}
5.2 Seven segment display interfacing
Seven Segment
The seven-segment LED display has four individual digits, each with a decimal point. Each
of the seven segments (and the decimal point) in a given digit contains an individual LED.
When a suitable voltage is applied to a given segment LED, current flows through and
illuminates that segment LED. By choosing which segments to illuminate, any of the nine
digits can be shown. For example, as shown in the figure below, a 2 can be displayed by
illuminating segments a, b, d, e, and g.seven segment displays come in two varieties -
common anode (CA) and common cathode (CC). In a CA display, the anodes for the seven
segments and the decimal point are joined into a single circuit node. To illuminate a segment
in a CA display, the voltage on a cathode must be at a suitably lower voltage (about .7V) than
the anode. In a CC display, the cathodes are joined together, and the segments are illuminated
by bringing the anode voltage higher than the cathode node (again, by about .7V). The Dig
labboard uses CA displays.
The seven LEDs in each digit are labeled a-g. Since the
Digilab board usesCA displays, the anodes for each of the
four digits are connected in a common node, so that four
separate anode circuit nodes exist (one per digit).Similar
cathode leads from each digit have also been tied together to
form seven common circuit nodes, so that one node exists for
each segment type. These four anode and seven cathode
circuit nodes are available at the J2connector pins labeled A1-A4 and CA-CG. With this
scheme, any segment of any digit can be driven individually. For example, to illuminate
segments and c in the second digit, the b and c cathode nodes would be brought to a suitable
low voltage (by connecting the corresponding circuit node available at the J2 connector to
ground), and anode 2 would be brought to a suitablehigh voltage (by connecting the
corresponding circuit node available at theJ2 connector to Vdd).
/* PROGRAM TO SWITCH ON SEVEN SEGMENT DISPLAY MOVING FROM LSB TO
MSB */
#include<reg51.h>
void delay()
{
int a;
for(a=0;a<=30000;a++);
}
void main()
{
P2=0x3F;
delay();
P2=0x30;
delay();
P2=0x5B;
delay();
P2=0x1F;
delay();
P2=0x66;
delay();
P2=0x6D;
delay();
P2=0x7C;
delay();
P2=0x07;
delay();
P2=0x7F;
delay();
P2=0x3F;
delay();
}
5.3 Stepper motor interfacing
STEPPER MOTOR
EMotion Control, in electronic terms, means to accurately control the movement of an object
based on either speed, distance, load, inertia or a combination of all these factors. There are
numerous types of motion control systems, including; Stepper Motor, Linear Step Motor, DC
Brush, Brushless, Servo, Brushless Servo and more.stepper motor is an electromechanical
device which converts electrical pulses into discrete mechanical movements. Stepper motor is
a form of ac. motor .The shaft or spindle of a stepper motor rotates in discrete step increments
when electrical command pulses are applied to it in the proper sequence. The motors rotation
has several direct relationships to these applied input pulses. The sequence of the applied
pulses is directly related to the direction of motor shafts rotation. The speed of the motor
shafts rotation is directly related to the frequency of the input pulses and the length of rotation
is directly related to the number of input pulses applied. For every input pulse, the motor
shaft turns through a specified number of degrees, called a step. Its working principle is one
step rotation for one input pulse. The range of step size mayvary from 0.72 degree to 90
degree. In position control application, if the number of input pulsessent to the motor is
known, the actual position of the driven job can be obtained.A stepper motor differs from a
conventional motor (CM) as under
Figure 5.1-stepper
motor
a. Input to SM is in
the form of electric pulses whereas input to a CM is invariably from a constant voltage
source.
b. A CM has a free running shaft whereas shaft of SM moves through angular steps.
5.3.1 Step Angle & Steps per Revolution
Movement associated with a single step, depends on the internal construction of the motor,
inParticular the number of teeth on the stator and the rotor. The step angle is the minimum
degree of rotation associated with a single step. Step per revolution is the total number of
steps needed to rotate one complete rotation or 360degrees (e.g., 180 steps * 2 degree = 360)
Since the stepper motor is not ordinary motor and has four separate coils, which have tobe
energized one by one in a stepwise fashion. We term them as coil A, B, C and D. At a
particular instant the coil A should get supply and then after some delay the coil B should get
supply and then coil C and then coil D and so on the cycle continues. The more the delay is
introduced between the energizing of the coils the lesser is the speed of the stepper motor
advice versa.
/* PROGRAM USING STEPPER MOTOR*/
#include<reg51.h>
void delay()
{
int a;
for(a=0;a<=6000;a++);
}
void main()
{
P2=0x00;
delay( );
P2=0xff;
delay();
P2=0x00;
delay( );
P2=0xff;
delay();
P2=0x00;
delay( );
P2=0xff;
delay( );
}
AT89C52 Microcontroller
Software Requirements:
1. Keil Vision IDE
2. Willar Programmer
3. Proteus (for circuit and simulation)
Electronic Code Lock System Circuit Design:
The basic architecture and function of a microcontroller is discussed. With examples, the
need for low power microcontroller is illustrated.
Microcontrollers are of prime importance for electronic control and communication of any
modern appliance. Any household appliance e.g. washing machine, refrigerator, air-
conditioner or office appliances e.g. electronic printer, Photostat copier, fax machine contains
one or more microcontrollers. Because of its bulk usage a marginal saving in power for one
8051 results to enormous saving as a whole.
In any device design, when one feature is optimized another feature degrades. When low
power is achieved the speed or performance may go down. Though this microcontroller
consumes negligible power its other features are comparable to the existing microcontrollers
available in the market.
BIBLOGRAPHY
Sources:
[1] Chris and Dawn Schurs Robotics and Artificial Life Forms,
http://www.schursastrophotography.com
[2] Wallace, David N., Line Following Robot http://www.lifekludger.net/category/weekly-
links/page/2/
[3] DenmarksTechniskeUniversitethttp://www.sweeper.org
[4], [9] Mikes Line Following Robot, Central Illinois Robotics Club,
http://www.circ.mtco.com
[5] http://www.leang.com
[6] http://www.cs.umn.edu
[7], [8] Jackson, Ben, http://www.ben.com
[10] http://www.ece.unm.edu
[11] David Cooks Jet http://www.robotroom.com/jet.html
[12] http://blog.makezine.com
[13] The CBA Line Following Module http://www.budgetbot.com
[14] http://www.james.vroman.com/tecbot1a.htm james@vroman.com
[15] http://www.james.vroman.com/javbot1a.htm