Embedded Lab Manual
Embedded Lab Manual
A Microcontroller consists of a powerful CPU tightly coupled with memory (RAM, ROM or
EPROM), various I/O features such as Serial port(s), Parallel port(s), Timer/Counter(s),
Interrupt Controller, Data Acquisition Interfaces - Analog to Digital Converter(ADC), Digital
to Analog Converter(DAC), everything integrated onto a single Silicon chip.
It does not mean that any microcontroller should have all the above said features on chip.
Depending on the need and area of application for which it is designed, the on chip features
present in it may or may not include all the individual sections said above.
If a system is developed with a microprocessor, the designer has to go for external memory
such as RAM, ROM or EPROM and peripherals and hence the size of the PCB (Printed
Circuit Board) will be large enough to hold all the required peripherals. But, the
microcontroller has got all these peripheral facilities on a single chip. So, development of a
similar system with a microcontroller reduces PCB size and cost of the design.
Intel has introduced a family of Microcontrollers called the MCS-51. This family comprises
the 8031, 8051, 8052, 8751 and 8752 Microcontrollers. Our trainer kit supports all these
microcontrollers. 8051, an 8-bit Single chip Microcontroller has got a powerful CPU
optimised for control applications, 64K Program Memory address space, 64K Data Memory
address space, 4K bytes of on-chip ROM (Read Only Memory), 128 bytes of on-chip RAM
(Read/Write Memory), Four 8-bit bidirectional Parallel ports, one full-duplex (it can transmit
and receive simultaneously) Serial port, two 16-bit timer/counters and an extensive interrupt
structure. 8031 is the ROM less version of 8051 whereas 8751 is the EPROM version of
8051. This is the main difference between 8031, 8051 and 8751. Since we have not used the
1
On-chip ROM or EPROM in Micro-51, Micro-51 EB and Micropower-i based 8031/51 Piggy
board, any of these three Microcontrollers can be used. For individual line and control
applications, 8051 is best suited as it incorporates a special set of instruction which are
capable of bit addressing the onchip I/O features of 8051.
APPLICATIONS OF MICROCONTROLLERS
2
THE 8051 MICROCONTROLLER ARCHITECTURE
The 8051 have 4K of code memory implemented as on-chip Read Only Memory (ROM). The
8051 have 128 bytes of internal Random Access Memory (RAM). The 8051 has two
timer/counters, a serial port, 4 general purpose parallel input/output ports, and interrupt
control logic with five sources of interrupts. Besides internal RAM, the 8051 have various
Special Function Registers (SFR), which are the control and data registers for on-chip
facilities. The SFRs also include the accumulator, the B register, and the Program Status
Word (PSW), which contains the CPU flags. Programming the various internal hardware
facilities of the 8051 is achieved by placing the appropriate control words into the
corresponding SFRs. The 8031 are similar to the 8051, except it lacks the on-chip ROM.
3
VARIOUS 8051 MICROCONTROLLERS
The 8051 is available in different memory types, such as UV-EPROM, flash, and NV-RAM,
all of which have different part numbers. The UV-EPROM version of the 8051 is the 8751.
Many companies including Philips, Atmel, Analog Devices & Cygnal manufactures the flash
ROM version. The Atmel flash 8051 is called AT89C51 & the Analog Devices version is
ADuC812. The NV-RAM version of the 8051 made by Dallas semiconductor is called
DS5000. There is also the OTP (One time programmable) version of the 8051 made by
various manufacturers. All these versions of 8051 (MCS-51 series) are called as ‘8051
Derivatives’. MCS 51 Series of Microcontrollers are
Although 8051 family members (e.g. 8751, 89C51) come in different packages, such as DIP
(dual in-line package), QFP (quad flat package), and LLC (Leadless chip carrier), they all
have 40 pins that are dedicated for various function such as I/O, RD, WR, address, data and
interrupts. It must be noted that some companies provide a less pin version of the 8051 with a
reduced number of I/O ports for less demanding applications & user flexibility. ATMEL
892051 is the 20 pin 8051 derivative IC with less digital I/O lines & reduced flash memory
compared to its 40 pin AT89C51 series. However, since the vast majority of developers use
the 40-pin DIP package chip. And now RISC versions of 8051 ICs are also available with
ATMEL & they called it as AVR microcontrollers & available size from 8-pin package.
Examining the following figure, note that of the 40 pins a total of 32 pins are set aside for the
four ports P0, P1, P2 and P3, where each ports takes 8 pins. The rest of the pins are
designated as Vcc, GND, XTAL1, XTAL2, RST, EA, ALE, and PSEN. Of these 8 pins, all
members of the 8051 and 8031 families use six of them. In other words, they must be
connected in order for the system to work, regardless of whether the microcontroller is of the
4
8051 or 8031 family. The other two pins PSEN- and ALE are used mainly in 8031 based
systems.
1–8: Port 1: Each of these pins can be used as either input or output according to your needs.
Also, pins 1 and 2 (P1.0 and P1.1) have special functions associated with Timer 2.
9: Reset Signal: High logical state on this input halts the MCU and clears all the registers.
Bringing this pin back to logical state zero starts the program a new as if the power had just
been turned on. In another words, positive voltage impulse on this pin resets the MCU.
Depending on the device's purpose and environs, this pin is usually connected to the push-
button, reset-upon-start circuit or a brown out reset circuit.
10-17: Port 3:as with Port 1, each of these pins can be used as universal input or output.
However, each pin of Port 3 has an alternative function:
Pin 10: RXD - serial input for asynchronous communication or serial output for synchronous
communication.
5
Pin 11: TXD - serial output for asynchronous communication or clock output for synchronous
communication
18-19: X2 and X1: Input and output of internal oscillator. Quartz crystal controlling the
frequency commonly connects to these pins. Capacitances within the oscillator mechanism
optimal voltage
21- 28: Port 2: if external memory is not present, pins of Port 2 act as universal input/output.
If external memory is present, this is the location of the higher address byte, i.e. addresses A8
– A15. It is important to note that in cases when not all the 8 bits are used for addressing the
memory (i.e. memory is smaller than 64kB), the rest of the unused bits are not available as
input/output.
29: PSEN: MCU activates this bit (brings to low state) upon each reading of byte instruction)
from program memory. If external ROM is used for storing the program, PSEN- is directly
connected to its control pins.
30: ALE: before each reading of the external memory, MCU sends the lower byte of the
address register (addresses A0 – A7) to port P0 and activates the output ALE. External Chip
(eg: 74HC373), memorizes the state of port P0 upon receiving a signal from ALE pin, and
uses it as part of the address for memory chip. During the second part of the MCU cycle,
signal on ALE is off, and port P0 is used as Data Bus. In this way, by adding only one
integrated circuit, data from port can be multiplexed and the port simultaneously used for
transferring both addresses and data.
31: EA: Bringing this pin to the logical state zero designates the ports P2 and P3 for
transferring addresses regardless of the presence of the internal memory. This means that
6
even if there is a program loaded in the MCU it will not be executed, but the one from the
external ROM will be used instead. Conversely, bringing the pin to the high logical state
causes the controller to use both memories, first the internal, and then the external (if
present).
32-39: Port 0: Similar to Port 2, pins of Port 0 can be used as universal input/output, if
external memory is not used. If external memory is used, P0 behaves as address output (A0 –
A7) when ALE pin is at high logical level, or as data output (Data Bus) when ALE pin is at
low logical level.
7
Experiment No 1 Date:
Aim:
To perform addition of two 8 bit data using immediate addressing mode and
store the result in memory.
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
8
Program:
MOV A, #15H
ADD A, #10H
MOVX @DPTR,A
9
Flowchart:
10
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
Thus the program to add two 8 bit numbers using 8051 microcontroller was
written and executed successfully.
11
1B. SUBTRACTION OF TWO 8 BIT NUMBERS USING 8051 MICROCONTROLLER
Aim:
To perform subtraction of two 8 bit data using immediate addressing mode and
store the result in memory.
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
12
Program:
CLR C
MOV A,#DATA1
SUBB A,#DATA2
MOV DPTR,#4500
MOVX @DPTR,A
13
Flowchart:
14
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
Thus the program to subtract two 8 bit numbers using 8051 microcontroller
was written and executed successfully.
15
1C. MULTIPLICATION OF TWO 8 BIT NUMBERS USING 8051 MICROCONTROLLER
Aim:
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
4. Multiply A with B.
5. Initialize the memory location and store the lower order byte in memory.
16
Program:
MOV A, #DATA1
MOV B, #DATA2
MUL AB
MOVX @DPTR, A
INC DPTR
MOV A,B
MOVX @DPTR,A
17
Flowchart:
18
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
Thus the program to multiply two 8 bit numbers using 8051 microcontroller
was written and executed successfully.
19
1D. DIVISION OF TWO 8 BIT NUMBERS USING 8051 MICROCONTROLLER
Aim:
To perform division of two 8 bit data using immediate addressing mode and
store the result in memory.
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
4. Divide A by B.
20
Program:
MOV A, #DATA1
MOV B, #DATA2
DIV AB
MOVX @DPTR, A
INC DPTR
MOV A,B
MOVX @DPTR,A
21
Flowchart:
22
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
Thus the program to divide two 8 bit numbers using 8051 microcontroller was
written and executed successfully.
23
Experiment No 2 Date:
Aim:
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
2.Load the array in the consecutive memory location and initialize the memory pointer
5.Load the other register with the value of the memory pointer.
7.Check for carry, if exist, increment the carry register by 1, otherwise continue.
24
Program:
MOVX A, @DPTR
MOV R0, A
MOV B, #00
MOV R1, B
ADD: CLR C
INC DPTR
MOVX A, @DPTR
ADD A, B
MOV B, A
JNC NC
INC R1
NC: DJ NZ R0,ADD
MOV A, R1
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
25
Flowchart:
26
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
27
Experiment No 3 Date:
Aim:
To obtain the one's and two's complement of an 8-bit number using 8051
Microcontroller.
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
4.Initialize the memory location and store the content of accumulator in it.
28
Program:
MOV A, #DATA
CPL A
MOVX @DPTR, A
INC A
INC DPTR
MOVX @DPTR,A
29
Flowchart:
30
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
Thus an assembly language program to obtain the one's and two's complement
of an 8-bit number was written and output was verified successfully using 8051
Microcontroller.
31
Experiment No 4 Date:
Aim:
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
4. Compare the first number with internal memory location. If it is greater, move it to internal
memory location.
5. Further comparison is with this number and this comparison is done till the end of the
array.
6. Now the biggest number in internal memory location is stored in memory as the result.
32
Program:
MOV A,40H
MOVX @DPTR, A
LOOP1: JC LOOP3
MOV 40H, A
SJMP LOOP3
33
Flowchart:
34
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
Thus an assembly language program to find the largest element in an array was
written and was successfully executed using 8051 microcontroller.
35
Experiment No 5 Date:
Aim:
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
4. Compare the first number with internal memory location. If it is lesser, move it to internal
memory location.
5. Further comparison is with this number and this comparison is done till the end of the
array.
6. Now the biggest number in internal memory location is stored in memory as the result.
36
Program:
MOV DPTR,#4200
MOV 40H,#FF
MOV R5,#0A
MOV A,40H
MOVX @DPTR, A
MOV 40H,A
SJMP LOOP3
37
Flowchart:
38
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
39
Experiment No 6 Date:
Aim:
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
2. First consider the first two numbers of the array. See if this pair of numbers is out of
order.
5. Perform this step for count times, count being one less than array length.
40
Program:
MOV R3,#4
MOV R4,#4
MOV DPTR,#4500
MOVX A, @DPTR
MOV B, A
MOVX A, @DPTR
MOV R0, A
CLR C
SUBB A, B
JNC CHKNXT
PUSH DPH
MOV DPL,R5
MOV DPH, R6
MOV A, R0
MOVX @DPTR, A
POP DPH
POP DPL
MOV A, B
41
MOVX @DPTR, A
MOV B, R0
DEC R4
MOV A, R4
MOV R3, A
INC R4
MOV DPL, R5
MOV DPH, R6
INC DPTR
42
Flowchart:
43
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
44
Experiment No 7 Date:
Aim:
Apparatus Required:
1)8051 Microcontroller
2)Keyboard
Algorithm:
2. First consider the first two numbers of the array. See if this pair of numbers is out of
order.
5. Perform this step for count times, count being one less than array length.
45
Program:
MOV R3, #4
MOV R4, #4
MOVX A, @DPTR
MOV B, A
MOVX A, @DPTR
MOV R0, A
CLR C
SUBB A, B
JC CHKNXT
PUSH DPH
MOV DPL, R5
MOV DPH, R6
MOV A, R0
MOVX @DPTR, A
POP DPH
POP DPL
MOV A, B
46
MOVX @DPTR, A
MOV B, R0
DEC R4
MOV A, R4
MOV R3, A
INC R4
MOV DPL, R5
MOV DPH, R6
INC DPTR
47
Flowchart:
48
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
49
Introduction about Arduino UNO
Types of Microcontrollers
Microcontrollers are divided into various categories based on memory, bits and
instruction sets.Based on Bit, three microcontrollers are there,
• CISC − Contains a large set of computer instructions that range from very
simple to very complex.
50
• RISC − Is designed to perform a smaller number of types of computer
instructions.
• Is an environment mainly used to write code and upload computer code to the
physical device.Arduino IDE uses a simplified version of C++
1) Processor-16Mhz
2) Memory-2 Kb SRAM and 32Kb Flash Memory
3) Digital I/O-14
4) Analog I/O-6
2)ATMEGA 32U4 Microcontroller(ARDUINO LEONARDO)
1) Processor-16Mhz
3)Digital I/O-20
4)Analog I/O-12
3)ATMEGA 2560 Microcontroller(ARDUINO MEGA)
1)Processor-16Mhz
3)Digital I/O-54
4)Analog I/O-16 Input and 0 Output
4)AT91sam3X8E Microcontroller(ARDUINO DUE)
1)Processor-84 Mhz
3)Digital I/O-54
4)Analog I/O-16 Input and 2 Output
51
Arduino Board Details
1-Power USB
Arduino board can be powered by using the USB cable from your computer.
Arduino boards can be powered directly from the AC mains power supply by
connecting it to the Barrel Jack.
3-Voltage Regulator
The function of the voltage regulator is to control the voltage given to the
Arduino board and stabilize the DC voltages used by the processor and other
elements.There are two types of voltage regulators
52
A fixed voltage regulator produces a fixed DC output voltage, which is either
positive or negative.An adjustable voltage regulator produces a DC output
voltage, which can be adjusted to any other value of certain voltage range.
Hence, adjustable voltage regulator is also called as a variable voltage
regulator.
4-Crystal Oscillator
5,17-Arduino Reset
You can reset our Arduino board, (i.e., start our program from the beginning)
in two ways.
2) Second, you can connect an external reset button to the Arduino pin labelled
RESET (5)
6,7,8,9-3.3v,5v,GND,Vin
Most of the components used with Arduino board works fine with 3.3 volt and
5 volt.
GND (8)(Ground) − There are several GND pins on the Arduino, any of which
can be used to ground your circuit.
Vin (9) − This pin also can be used to power the Arduino board from an
external power source, like AC mains power supply.
53
10-Analog Pins
The Arduino UNO board has six analog input pins A0 through A5. These pins
can read the signal from an analog sensor and convert it into a digital value that
can be read by the microprocessor.
11-Main Microcontroller
12-ICSP Pin
1)MOSI(Master Out Slave In)-Supply output data from slave to the input of
the master
2)MISO(Master In Slave out)- Supply output data from master to the input of
the slave
4)RESET
5)VCC
6)GND
54
This LED should light up when you plug your Arduino into a power source to
indicate that your board is powered up correctly. If this light does not turn on,
then there is something wrong with the connection.
Appear in two places on the Arduino UNO board. First, at the digital pins 0 and
1, to indicate the pins responsible for serial communication.
Second, the TX and RX led (13). The TX led flashes with different speed
while sending the serial data. RX flashes during the receiving process.
15-Digital I/O
The Arduino UNO board has 14 digital I/O pins (of which 6 provide PWM
(Pulse Width Modulation) output. The pins labeled “~” can be used to generate
PWM.These pins can be configured to work as input digital pins to read logic
values(0 or 1) or as digital output pins to drive different modules like
LED’s,Relay etc.
16-AREF
Used to set an external reference voltage (between 0 and 5 Volts) as the upper
limit for the analog input pins.
55
Tutorial on Arduino IDE Software
The Arduino IDE is the interface where you will write the program that tell the board
what to do. You can find the latest version of this software on the link:
https://www.arduino.cc/en/software
To install the software, you will need to click on the link that corresponds with your
computer’s operating system. Once the software has been installed on your computer,
go ahead, and open it up. This is the Arduino IDE and is the place where all the
programming will happen.
56
1. Menu Bar: Gives you access to the tools needed for creating and saving
Arduino sketches.
2. Verify Button: Compiles your code and checks for errors in spelling or
syntax.
3. Upload Button: Sends the code to the board that’s connected such as
Arduino
UNO in this case. Lights on the board will blink rapidly when uploading.
5. Sketch Name: When the sketch is saved, the name of the sketch is displayed
here.
6. Open Existing Sketch: Allows you to open a saved sketch or one from the
stored examples.
7. Save Sketch: This saves the sketch you currently have open.
8. Serial Monitor: When the board is connected, this will display the serial
57
9. Code Area: This area is where you compose the code of the sketch that tells
10.Message Area: This area tells you about the status on saving, code
compiling,
11.Text Console: Shows the details of an error messages, size of the program
12.Board and Serial Port: Tells you what board is being used and what serial
At this point you are ready to connect your Arduino to your computer. Plug one end of
the USB cable to the Arduino Uno and then the other end of the USB to your
computer’s USB port. Once the board is connected, you will need to go to Tools then
Board then finally select Arduino Uno.
Next, you have to tell the Arduino which port you are using on your computer. To
select the port, go to Tools then Port then select the port that says Arduino.
58
Introduction about Tinkercad
3- Simulator: They offer a good interface for designing and simulating projects.
59
On the top right corner, SIGN IN option is there. Click it. You can SIGN IN with your
klu mail ID.
Click on Circuits to switch from 3D Designs to “Circuits” mode, and then click on
Create new Circuit.
On the right side of the screen, the components are available. These components
include basics electronic components, Microcontrollers and their Interfacing Sensors
and Devices. Drag and drop the components of interest to the Main Window.
After the Connections are made, click the Code Option on the top menu bar. This is to
be done if you are having a Microcontroller in your circuit.
60
After completion of the above step, Click the Start Simulation option available beside
it. If there are no errors in the circuit and / or Program, the output can be visible on the
screen. If the output is on the Serial Monitor of Arduino, you need to click the “Serial
Monitor” option available below the Code option.
61
Experiment No 8 Date:
Aim:
To build a circuit using Arduino UNO through which a traffic light is turned ON and
OFF automatically.
Apparatus Required:
2.Arduino UNO
3.Resistors
4.Jumping Wires
Program:
void setup()
{
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}
void loop()
{
for (int i = 0 ; i < 10 ; i +=1)
{
digitalWrite(11,HIGH);
delay(100);
digitalWrite(11,LOW);
delay(100);
}
digitalWrite(11,HIGH);
62
delay(5000);
digitalWrite(11,LOW);
delay(1000);
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(13,HIGH);
delay(5000);
digitalWrite(13,LOW);
delay(1000);
Circuit Diagram:
63
Connections:
64
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
Thus, with the help of knowledge of traffic light control, circuits have been
constructed and implemented successfully.
65
Experiment No 9 Date:
Aim:
To build a circuit that use the temperature sensor to detect the temperature value
continuously using Arduino and Tinkercad Software Tool.
Apparatus Required:
1.Arduino UNO
2)Temperature Sensor(TMP36)
3)Jumping Wires
Program:
#define analogPin A0
void setup()
{
Serial.begin(9600);
analogReference(EXTERNAL);
}
void loop() {
Serial.print("Temperature: ");
Serial.print(tempInC);
Serial.print("\xB0");
Serial.print("C");
Serial.print("\n");
66
delay(2000);
}
Circuit Diagram:
Connections:
5. The red wire is connected from 5V power from Arduino to TMP36’s power(Vs+).
6. The black wire is connected from TMP36’s Vout to Arduino’s A0(Analog) pin.
7. Green wire is connected from the ground(GND) of Arduino to the ground of the
TMP36 sensor.
8. The yellow wire is connected from the 3.3V of Arduino to the reference
voltage(AREF) pin in Arduino.
9. After the connections are made, click the Start Simulation button.
67
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
68
Experiment No 10 Date:
Aim:
To build a circuit that use the ultrasonic sensor to detect the distance between
sensor and object continuously using Arduino and Tinkercad Software Tool.
Apparatus Required:
1)Arduino UNO
2)Ultrasonic Sensor
3)Jumper Wires
Program:
#define echoPin \
#define trigPin \
long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
Serial.println("Distance measurement using Arduino Uno.");
delay(500);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite( trigPin,HIGH);
delayMicroseconds(10);
69
digitalWrite(trigPin,LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration * 0.0344 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(100);
}
Circuit Diagram:
70
Connections:
71
Assessment for Experiment
Program (10)
Output (20)
Viva (10)
Total (50)
Result:
72