Embedded System Lab Manual
Embedded System Lab Manual
Lab Manual
For
(EC-606)
Name: …………………………………………………….
Semester: 6th
.
The following Regulations and Safety Rules must be observed in all concerned laboratory locations.
1. It is the duty of all concerned parties who use any electrical laboratory to take all reasonable steps to safeguard the HEALTH
and SAFETY of themselves and all other users and visitors.
2. Make sure that all equipment is properly working before using them for laboratory exercises. Any defective equipment must be
reported immediately to the Lab. Instructors or Lab. Technical Staff.
3. Students are allowed to use only the equipment provided in the experiment manual or equipment used for senior project
laboratory.
4. Power supply terminals connected to any circuit are only energized with the presence of the Instructor or Lab. Staff.
5. Students should keep a safe distance from the circuit breakers, electric circuits or any moving parts during the experiment.
6. Avoid any part of your body to be connected to the energized circuit and ground.
7. Switch off the equipment and disconnect the power supplies from the circuit before leaving the laboratory.
8. Observe cleanliness and proper laboratory housekeeping of the equipment and other related accessories.
9. Wear proper clothes and safety gloves or goggles required in working areas that involves fabrications of printed circuit boards,
chemicals process control system, antenna communication equipment and laser facility laboratories.
10. Double check your circuit connections specifically in handling electrical power machines, AC motors and generators before
switching “ON” the power supply.
11. Make sure that the last connection to be made in your circuit is the power supply and first thing to be disconnected is also the
power supply.
12. Equipment should not be removed, transferred to any location without permission from the laboratory staff.
13. Software installation in any computer laboratory is not allowed without the permission from the Laboratory Staff.
14. Computer games are strictly prohibited in the computer laboratory.
15. Students are not allowed to use any equipment without proper orientation and actual hands on equipment operation.
16. Smoking and drinking in the laboratory are not permitted.
3
(EC-606)
OUTCOMES
[
Familiarize with the assembly level and embedded C programming using 8051.
Familiarize with the Keil µVision-3/4 and IAR Embedded Workbench tools.
INTRODUCTION:
Earlier to Microcontrollers, Microprocessors were greatly used for each and every
purpose. Microprocessors were containing ALU, general purpose register, stack pointer,
program counter, clock counter and so many other features which the today’s Microcontroller
also possesses. But the difference between them exists with respect to the number of
instructions, access times, size, reliability, PCB size and so on. Microprocessor contains
large instruction set called as CISC processor whereas Microcontroller contains less
number of instructions and is called as RISC processor. The access time is less in case of
microcontrollers compared to microprocessors and the PCB size reduces in case of
microcontrollers.
There are many versions of microcontrollers 8051, 80528751, AT8951 from Atmel
Corporation and many more. In this manual we will study about the 8051 architecture,
its features, programming and interfacing.
MCS 8051 is an 8-bit single chip microcontroller with many built-in functions and is
the core for all MCS-51 devices.
The main features of the 8051 core are:
Operates with single Power Supply +5V.
8-bit CPU optimized for control applications.
16-bit program counter (PC) and 16-bit data pointer (DPTR).
8-bit program status word (PSW).
8-bit stack pointer (SP).
4K Bytes of On-Chip Program Memory (Internal ROM or EPROM).
128 bytes of On-Chip Data Memory (Internal RAM):
o Four Register Banks, each containing 8 registers (R0 to R7) [Total 32 reg]
o 16-bytes of bit addressable memory.
o 80 bytes of general-purpose data memory (Scratch Pad Area).
Special Function Registers (SFR) to configure/operate microcontroller.
32 bit bi-directional I/O Lines (4 ports P0 to P3).
Two 16-bit timers/counters (T0 and T1).
Full duplex UART (Universal Asynchronous Receiver/Transmitter).
On-Chip oscillator and clock circuitry.
Fig.1. General Block Diagram of 8051 Microcontroller Architecture
6. If Keil Monitor- 51 driver is used click on Settings -> COM Port settings select the
COM Port to which the board is connected and select the baud rate as 19200 or 9600
(recommended). Enable Serial Interrupt option if the user application is not using on-
chip UART, to stop program execution.
7. Build the project; using Project -> Build Project.
application and links. Any errors in the code are indicated by – “Target not
created” in the Build window, along with the error line. Debug the errors. After an error
free, to build go to Debug mode.
8. Now user can enter into Debug mode with Debug- Start / Stop Debug session
Also the (reset, run, halt) icons can be used. Additional icons are
11. Note: To access data RAM area type address as D: 0020h. Similarly to access the DPTR region
(XRAM-present on chip in AT89C51ED2) say 9000h location type in X: 09000H.
Experiment no. 1
Aim : To Write an assembly language program to perform the addition of two
16-bit numbers.
Result: The result of addition of two 16 bit numbers 3388 H and 3345 H is 66CD,Shown in the
output window on the memory location 0x40 and 0x41.
Experiment no. 2
Program:
Note: Write the logic of the program. Try with some other logic.
Experiment no. 3
Program:
Result:
Before Execution: D: 21H = 22H =
Aim To write an assembly language program to generate a square wave using 8051 timer
Theory:
Mode 1 Programming: The following are the characteristics and operations of mode 1: 1. It is a
16-bit timer; therefore, it allows value of 0000 to FFFFH to be loaded into the timer’s register
TL and TH. 2. After TH and TL are loaded with a 16-bit initial value, the timer must be started.
This is done by SETB TR0 for timer 0 and SETB TR1 for timer 1. 3. After the timer is started, it
starts to count up. It counts up until it reaches its limit of FFFFH. When it rolls over from
FFFFH to 0000, it sets high a flag bit called TF (timer flag). Each timer has its own timer flag:
TF0 for timer 0 and TF1 for timer 1. This timer flag can be monitored. When this timer flag is
raised, one option would be to stop the timer with the instructions CLR TR0 or CLR TR1, for
timer 0 and timer 1, respectively. 4. After the timer reaches its limit and rolls over, in order to
repeat the process. TH and TL must be reloaded with the original value, and TF must be
reloaded to 0.
Steps to program in mode 1: To generate a time delay, using timer in mode 1, following are the
steps: 1. Load the TMOD value register indicating which timer (timer 0 or timer 1) is to be used
and which timer mode (0 or 1) is selected. 2. Load registers TL and TH with initial count value.
3. Start the timer. 4. Keep monitoring the timer flag (TF) with the JNB TFx, target instruction to
see if it is raised. Get out of the loop when TF becomes high. 5. Stop the timer. 6. Clear the TF
flag for the next round. 7. Go back to Step 2 to load TH and TL again.
Program:
Delay:
Setb Tr0 ; Start The Timer 0
Again : Jnb Tf0, Again ; Monitor Timer Flag 0 Until It Rolls Over
Clr Tr0 ; Stop Timer 0
Clr Tf0 ; Clear Timer 0 Flag
Ret
RESULT: A Square wave is generated using keil compiler under the spectrum analyzer tab.
Generated square wave as shown in the figure.
Experiment no. 5
Theory:
The microcontroller MCS51 has an inbuilt UART for carrying out serial communication.
The serial communication is done in the asynchronous mode. A serial port, like other PC
ports, is a physical interface to establish data transfer between a computer and external
hardware or device. This transfer, through a serial port, takes place bit by bit.
Bit Addressable: We can assign the values bit by bit. For example, for a single bit, we
can set weather 1 or 0.
Byte Addressable: We cant assign the values bit by bit. We can set only byte by byte.
First, we will see the SFRs.
Registers used for UART
SCON (Serial Control Register) – Bit Addressable
SBUF (Serial Buffer Register) – Byte Addressable
PCON (Power Control Register) – Byte Addressable
SCON (Serial Control Register)
This register is a bit addressable.
SM0 SM1 SM2 REN TB8 RB8 TI RI
Program :
# include<reg51.h>
{ while(*s) {
SBUF=*s++;
while(TI==0);
TI=0;
void main()
unsigned int i;
SCON=0x50;
TMOD=0x20;
TH1=TL1=0xfd;
TR1=1;
while(1) {
send("Embetronicx ");
Result: We have verified the operation of Serial Port by sending a Character on Serial Window.
Experiment no. 6
Theory:
Port 1 occupies a total of 8 pins (pins 1 through 8). It can be used as input or output. In
contrast to port 0, this port does not need any pull-up resistors since it already has pull-up
resistors internally. Upon reset, port 1 is configured as an input port. The following code
will continuously send out to port 1 the alternating values 55H and AAH.
Program:
MOV A,#FF H
BACK: MOV P0,A
ACALL DELAY
CPL A
ACALL DELAY
SJMP BACK
8 P 3.2
0 (INCR) DC
5 P 3.3 Motor
1 (DECR)
Theory:
DC motors are used in many applications like process control and automation in an
industry, robotics, consumer electronics, office automation equipment like printers and
scanners etc. One can consider the use of a DC motor wherever there is need to control the
motion of an object. Speed control of the motor is important in the applications involving
them. For example, in an audio system, the DC motor that drives the cassette should
always run at a fixed speed. Like wise, there are applications where the speed of
the DC motor has to change according to some defined conditions. The DC motor used in
this interface module is a 12V, 4W motor that can be seen in many electronic equipments. The
circuit to control the speed of the motor follows a general concept and can be applied to DC
motors of higher capacity also.
The pulse width modulation technique is used to vary the speed of the DC
motor. The frequency of the pulses is 120Hz. Keeping the frequency constant, the
width of the pulses is used to change the speed. When the pulse width is minimum, the speed
is minimum and when the width is maximum, the speed is maximum (2400rpm). The
ramp and pedestal technique is used to change the pulse width and thereby the speed.
Result: Proteus Simulator Diagram shows the Interfacing of DC Motor with 8051, the
working operation of dc Motor is tested by simulation. Both the Motor is rotate in clockwise
direction.
Experiment no. 8:
Aim: To Write a C program to interface Gas Sensor to detect LPG Leakage using ESP 32.
Requirement: MQ2 Gas Sensor, ESP- 32,Arduino IDE and Connecting Wires.
Block Diagram:
Theory:
A gas leak detection system is a device or set of devices that detect the presence of gas in a
specific area or location. These systems can use various technologies to detect gas leaks, such as
infrared sensors, ultrasonic sensors, or electrochemical sensors. They are commonly used in
industrial settings, such as oil and gas refineries, chemical plants, and natural gas distribution
systems, as well as in residential and commercial buildings. The goal of a gas leak detection
system is to detect gas leaks as quickly as possible in order to prevent fires, explosions, and other
hazards.
An IoT-enabled gas leak detection system using the ESP32 microcontroller would utilize the
capabilities of the ESP32 to connect to the internet and send data from gas sensors to a remote
location for monitoring. The ESP32 is a low-cost, low-power microcontroller with built-in Wi-Fi
and Bluetooth capabilities, making it a suitable choice for IoT projects. The system could be
programmed to send alerts to a control center or to a specific person’s device in the event of a gas
leak, and can also be set up to automatically shut off gas valves or perform other safety actions.
Additionally, the ESP32‘s ability to connect to other devices and sensors could enable the system
to integrate with other safety systems and devices.
The ESP32 is a low-cost, low-power microcontroller with built-in Wi-Fi and Bluetooth
capabilities. It is a popular choice for IoT projects and is commonly used for a variety of
applications such as home automation, wireless control, and sensor data logging.
The ESP32 features a dual-core processor, a rich set of peripherals, and support for a wide range
of protocols. It can be programmed using the Arduino IDE and various other programming
languages such as C, C++, and MicroPython.
Additionally, the ESP32 has a wide range of features including:
A high-performance processor with a clock speed of up to 240 MHz
Support for various types of wireless connectivity such as Wi-Fi, Bluetooth, and
Bluetooth Low Energy (BLE)
The MQ-4 sensor is a type of gas sensor that is commonly used to detect methane, natural gas,
and propane. When used with an ESP32 microcontroller, the MQ-4 sensor can be connected to
the ESP32‘s analog input pins and the ESP32 can be programmed to read the sensor’s output and
determine the concentration of gas in the air. The ESP32 can then send this data over the internet
to a remote location for monitoring and analysis.
The system can be designed to send an alert if the gas concentration exceeds a certain threshold,
and can also be set up to automatically shut off gas valves or perform other safety actions.
Additionally, the ESP32‘s ability to connect to other devices and sensors could enable the system
to integrate with other safety systems and devices.
Program :
void setup() {
Serial.begin(115200);
pinMode(Buzzer, OUTPUT);
pinMode(Gas_digital, INPUT);
}
void loop() {
int gassensorAnalog = analogRead(Gas_analog);
int gassensorDigital = digitalRead(Gas_digital);
Theory:
Stepper motor is brushless DC motor, which can be rotated in small angles, these angles are
called steps. Generally stepper motor use 200 steps to complete 360 degree rotation, means its
rotate 1.8 degree per step. Stepper motor used in many devices which needs precise rotational
movement like robots, antennas, hard drives etc. We can rotate stepper motor to any particular
angle by giving it proper instructions.
Stepper motors are basically two types: Unipolar and Bipolar. Unipolar stepper motor
generally has five or six wire, in which four wires are one end of four stator coils, and other end
of the all four coils is tied together which represents fifth wire, this is called common wire
(common point). Generally there are two common wire, formed by connecting one end of the
two-two coils as shown in below figure. Unipolar stepper motor is very common and popular
because of its ease of use.
In Bipolar stepper motor there is just four wires coming out from two sets of coils, means there
are no common wire.
Stepper motor is made up of a stator and a rotator. Stator represents the four electromagnet coils
which remain stationary around the rotator, and rotator represents permanent magnet which
rotates. Whenever the coils energised by applying the current, the electromagnetic field is created,
resulting the rotation of rotator (permanent magnet). Coils should be energised in a particular
sequence to make the rotator rotate. On the basis of this “sequence” we can divide the working
method of Unipolar stepper motor in three modes: Wave drive mode, full step drive mode and
half step drive mode.
Wave drive mode: In this mode one coil is energised at a time, all four coil are energised one
after another. It produces less torque in compare with Full step drive mode but power
consumption is less. Following is the table for producing this mode using microcontroller, means
we need to give Logic 1 to the coils in the sequential manner.
Steps A B C D
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
Full Drive mode: In this, two coil are energised at the same time producing high torque. Power
consumption is higher. We need to give Logic 1 to two coils at the same time, then to the next
two coils and so on.
Steps A B C D
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1
Half Drive mode: In this mode one and two coils are energised alternatively, means firstly one
coil is energised then two coils are energised then again one coil is energised then again two, and
so on. This is combination of full and wave drive mode, and used to increase the angular rotation
of the motor.
Steps A B C D
1 1 0 0 0
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 0
6 0 0 1 1
7 0 0 0 1
8 1 0 0 1
You need to find out four coil wires and two common wires very carefully otherwise motor will
not rotate. You can find it out by measuring resistance using multimeter, multimeter won’t show
any readings between the wires of two phases. Common wire and the other two wire in the same
phase should show the same resistance, and the two end points of the two coils in the same phase
will show the twice resistance in compared with resistance between common point and one end
point.
Troubleshooting
If your motor is not rotating OR vibrating but not rotating, then you must check the following
checklist:
2. If the circuit and code is ok, then check that the stepper motor gets proper supply voltage
(generally 12v), otherwise it just vibrate but not rotate.
3. If supply is fine, then check the four coil end points which in connected to ULN2003A.
First find the two common end points and connect them to 12v, then connect the
remaining four wires to ULN2003A and try every possible combination until motor get
started. If you wouldn’t connect them in proper order then the motor just vibrate instead
of rotating.
Here is the code for Wave step mode and full wave step mode, you can easily calculate the value
for PORT P2 for the half wave mode.
Code:
#include<reg51.h>
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
void main()
while(1)
msdelay(1);
P2=0x02; //0010
msdelay(1);
P2=0x04; //0100
msdelay(1);
P2=0x08; //1000
msdelay(1);
#include<reg51.h>
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
void main()
while(1)
msdelay(1);
P2 = 0x06; //0110
msdelay(1);
P2 = 0x0C; //1100
msdelay(1);
P2 = 0x09; //1001
msdelay(1);
}
Result: : Proteus Simulator Diagram shows the Interfacing of Stepper Motor with 8051
Microcontroller. Working Operation of Stepper Motor are get verified using different drive
modes.
Experiment no.10
Aim: To Write a C program for Traffic light system using 8051 Micro-Controller
Requirement: Keil development tools for the 8051 Microcontroller, Proteus software
Traffic lights, which may also be known as stoplights, traffic lamps, traffic signals, signal lights,
robots or semaphore, are signaling devices positioned at road intersections, pedestrian crossings
and other locations to control competing flows of traffic.About the colors of Traffic Light Control
Traffic lights alternate the right of way of road users by displaying lights of a standard color (red,
yellow/amber, and green), using a universal color code (and a precise sequence to enable
comprehension by those who are color blind).In the typical sequence of colored lights:
☞Illumination of the green light allows traffic to proceed in the direction denoted,
☞Illumination of the yellow/amber light denoting, if safe to do so, prepare to stop short of the
intersection, and
Usually, the red light contains some orange in its hue, and the green light contains some blue, for
the benefit of people with red-green color blindness, and “green” lights in many areas are in fact
blue lenses on a yellow light (which together appear green).
The Traffic light controller section consists of 12 Nos. point LEDS are arranged by 4Lanes in
8051 Development Board. Each lane has Go (Green), Listen (Yellow) and Stop (Red) LED is
being placed.
Algorithm:
• In this circuit , used three traffic light. signal 1(P2.0 to P2.2) and signal 2
(P2.3 to P2.5) are connected to port 2 and signal 3(P3.0 to P3.2) is connected
to port 3.Traffic light gets turned on as per the sequence provided in the
program.
C Program to Traffic Light using 8051
#include<reg51.h>
//signal 1
sbit tl1r = P2^0; // red
sbit tl1o = P2^1; // orange
sbit tl1g = P2^2; // green
//signal 2
sbit tl2r = P2^3; // red
sbit tl2o = P2^4; // orange
sbit tl2g = P2^5; // green
//signal 3
sbit tl3r = P3^0; // red
sbit tl3o = P3^1; // orange
sbit tl3g = P3^2; // green
while(1)
{
trafficlight();
}
}
void delay(unsigned long int t) // delay routine
{
while(t>0)
{
unsigned long int i;
for(i=1;i<10*1275;i++);
t--;
}
}
void trafficlight(void) // traffic light system program
{
P2= 0x11; // traffic signal control data
P3= 0x04;
/*
tl1r=1; // signal 1
tl1o=0;
tl1g=0;
tl2r=0; // signal 2
tl2o=1;
tl2g=0;
tl3r=0; // signal 3
tl3o=0;
tl3g=1;
*/
delay(100); // delay
P2= 0x0c; // traffic signal control data
P3= 0x02;
/*
tl1r=0; // signal 1
tl1o=0;
tl1g=1;
tl2r=1; // signal 2
tl2o=0;
tl2g=0;
tl3r=0; // signal 3
tl3o=1;
tl3g=0;
*/
delay(100); // delay
P2= 0x22; // traffic signal control data
P3= 0x01;
/*
tl1r=0; // signal 1
tl1o=1;
tl1g=0;
tl2r=0; // signal 2
tl2o=0;
tl2g=1;
tl3r=1; // signal 3
tl3o=0;
tl3g=0;
*/
delay(100); // delay
}
Result: : Proteus Simulator Diagram shows the Interfacing of traffic signal with 8051
.Operation of different Signals are get verified using different time-delays.
Viva Questions