Professional Documents
Culture Documents
Engineering Technology
(An Autonomous Institution)
19ECI401
MICROPROCESSOR AND
MICROCONTROLLERS
Submitted by
Name : karthikeyan M
Reg. No : 19EPCI014
SRI KRISHNA COLLEGE OF ENGINEERING AND TECHNOLOGY
COIMBATORE-641 008
BONAFIDE CERTIFICATE
To provide quality education in the fundamentals as well as the current trends in the field of
the department to facilitate R&D and consulting activities and to disseminate knowledge by
PEO- II Identify, analyze and formulate problems to offer appropriate design solutions that
are technically superior, economically feasible, environmentally compatible and
Socially acceptable.
PEO- III Achieve progress in professional and research career through communication
Skills, team work and knowledge up-gradation through continuous education.
PROGRAMME OUTCOMES
PO- a Apply the knowledge of the physical sciences, mathematics, computing, Electronics
and Communication Engineering fundamentals for modeling and solving complex
engineering problems.
PO- c Design and evaluate complex systems for specific purpose in Electronics and
Communication Engineering, with due considerations for economic, environmental,
social, political, ethical, health and safety considerations
PO- e Apply appropriate techniques, skills, and modern tools for the design and analysis
of engineering systems.
PO- f Attain broad education to provide engineering solution by taking environment and
sustainability into consideration
PO- g Understand the contemporary technical, professional issues and provide engineering
solution for societal problems
PO- h Develop consciousness of professional, ethical, legal, security, social issues and
Responsibilities
PO- i Function effectively as individuals and in teams which may involve people from
diverse background to accomplish a common goal
PO- j Communicate effectively both in written and oral form to address activities with
engineering community and society
PO- l Apply engineering and management fundamentals to manage the projects in time
with due consideration for finance
TABLE OF CONTENTS
Ex .No Date Exp.Name Page no Marks Staff Sign
1. 09/01/2021 8086 ARITHMETIC 9
OPERATIONS
2. 23/01/2021 8051 17
ARITHMETIC
OPERATORS
3. 28/01/2021 LARGEST 36
AND SMALLEST
IN AN ARRAY
4. 12/02/2021 Interfacing 8051 with 42
ADC
5. 27/02/2021 Interfacing 8051 with 47
Stepper motor
6. 06/03/2021 PROGRAMMABLE 56
PERIPHERAL
INTERFACE TO 8051
MICROCONTROLLER
7. 13/03/2021 INTERFACING LED 60
USING ARM WITH
KEIL C
8. 20/03/2021 DATA 64
TRANSCEIVER IN
ARM USING UART
9. 27/03/2021 PROGRAMMING 67
USING ARDUNIO –
LED FADING
10. 27/03/2021 TRAFFIC LIGHT 71
CONTROLLER
USING ARDUNIO
11. 27/03/2021 INTERFACING 75
GAS SENSOR
WITH ARDUINO
Experiment No. 01
Title of Experiment 8086 ARITHMETIC OPERATIONS
Date of Experiment 09/01/2021
EXPERIMENT OBJECTIVE:
To perform addition,subtraction,multiplication,division of two 16-
bit data and store the result in memory using 8086 microprocessor
OUPUT(8Bit_Addition):
OUTPUT(8Bit_Subtraction):
OUTPUT(Addition+Subtraction 8Bit):
OUTPUT(8Bit_Multiplication):
OUTPUT(8Bit_Division):
OUTPUT(16Bit_Addition):
OUTPUT(16Bit_Subtraction):
OUTPUT(Largest Number):
OUTPUT(Smallest Number):
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
KUNIAMUTHUR, COIMBATORE 641008
Experiment No. 4
Title of Experiment Interfacing 8051 with ADC
EXPERIMENT OBJECTIVE:
To Interface 8051 with ADC.
Steps for converting the analogue input and reading the output from ADC0804.
1. Make CS=0 and send a low to high pulse to WR pin to start the conversion.
2. Now keep checking the INTR pin. INTR will be 1 if conversion is not finished and INTR
will be 0 if conversion is finished.
3. If conversion is not finished (INTR=1) , poll until it is finished.
4. If conversion is finished (INTR=0), go to the next step.
5. Make CS=0 and send a high to low pulse to RD pin to read the data from the ADC.
THEORY:
i.)Interfacing ADC to 8051
ADC (Analog to digital converter) forms a very essential part in many embedded projects and this
article is about interfacing an ADC to 8051 embedded controller. ADC 0804 is the ADC used here
and before going through the interfacing procedure, we must neatly understand how the ADC
0804 works.
ORG 00H
MOV P1,#81h // initiates P1 as the input port
MAIN: CLR P3.7 // makes CS=0
SETB P3.6 // makes RD high
CLR P3.5 // makes WR low
SETB P3.5 // low to high pulse to WR for starting conversion
WAIT: JB P3.4,WAIT // polls until INTR=0
CLR P3.7 // ensures CS=0
CLR P3.6 // high to low pulse to RD for reading the data from ADC
MOV A,P1 // moves the digital data to accumulator
CPL A // complements the digital data (*see the notes)
MOV P0,A // outputs the data to P0 for the LEDs
SJMP MAIN // jumps back to the MAIN program
END
Program:
Proteus design:
RESULT:
Thus assemble language program to Interface 8051 with ADC was executed in proteus
software.
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
KUNIAMUTHUR, COIMBATORE 641008
Experiment No. 5
Title of Experiment Interfacing 8051 with Stepper motor
EXPERIMENT OBJECTIVE:
To Interface 8051 with Stepper motor.
● A motor, in general, is a device that converts electrical energy into mechanical en-
ergy.
● As the name suggests, a stepper motor is a device that does the same task as above
but, in steps.
● It is a brushless, synchronous electric motor that can divide a complete rotation into
a number of steps. Stepper motors generally have a permanent magnet shaft (rotor),
and it is surrounded by a stator.
● The best feature of this type of motor is that the motor’s angular position can be ac-
curately controlled without any feedback mechanism, as long as the motor is not
oversized. (From a designer’s point of view the sizing of the motor is essential, if
the stepper motor is undersized then it will not be able to withstand load and if it is
oversized then it becomes too expensive for its purpose.).
● Therefore, it works in a simple accurate open-loop system, where the output is dir-
ectly dependent on the input.
● A stepper motor rotates at small angles to complete 360 degrees rotation, these
small angles are called steps, hence the name Stepper Motor. Typically, a stepper
motor consists of 200 steps.
The sequence in which the coils are excited to form the poles causes the rotor to attract one pair of
stator pole and repel the other causing motion in the shaft and the load connected to it. The
sequence on which the coils are energized is discussed in detail in the next section of this article.
We are using Port 2 of 8051 microcontroller to generate high and low pulses and using a current
amplifier IC i.e. ULN2003a to amplify the current to drive the stepper motor using the pulse of the
microcontroller. On the basis of the way the coils are energized, a Unipolar Stepper motor can be
classified into three categories:
In this mode only one coil is energized at a time, all the four coils are energized one after the other
in a sequence. In terms of power consumption, this mode is a power saver, but the torque
produced is less compared to the full drive mode. In the following table, A-B-C-D refers to the
stator coils, that are to be energized sequentially in the manner and ‘1’s and ‘0’s refers to ‘HIGH‘
and ‘LOW’ states.
Steps A B C D HEX
1 1 0 0 0 0x08
2 0 1 0 0 0x04
3 0 0 1 0 0x02
4 0 0 0 1 0x01
ULN2003A driver:
A Stepper motor consumes a current of 0.1 – 1 A during step rotation with the load. An AT89c51
produces a maximum current of 0.045A through the ports. Therefore, the pulses sent from Port 2
are not sufficient to run a stepper motor. Hence, we cannot directly interface stepper motors with
microcontrollers like AT89C51 microcontroller.
There are two solutions to this problem:
8051- Timer
8051 has two timers Timer0 (T0) and Timer1 (T1), both are 16-bit wide. Since 8051 has 8-bit
architecture, each of these is accessed by two separate 8-bit registers as shown in the figure below.
These registers are used to load timer count.
TMOD is an 8-bit register used for selecting timer or counter and mode of timers. Lower 4-bits are
used for control operation of timer 0 or counter0, and remaining 4-bits are used for control
operation of timer1 or counter1.This register is present in SFR register, the address for SFR
register is 89th.
TCON is an 8-bit control register and contains a timer and interrupt flags.
Programming steps for delay function
1. Load Tmod register value i.e. TMOD = 0x01 for Timer0 mode1 (16-bit timer mode).
2. Load calculated THx value i.e. here TH0 = 0xFC.
3. Load calculated TLx value i.e. here TL0 = 0x74.
4. Start the timer by setting a TRx bit. i.e. here TR0 = 1.
5. Poll TFx flag till it does not get set.
6. Stop the timer by clearing TRx bit. i.e. here TR0 = 0.
7. Clear timer flag TFx bit i.e. here TF0 = 0.
8. Repeat from step 1 to 7 for the delay again.
In order to generate a delay of 1ms, the calculations using above steps are as follows.
org 00H
LOOP:Mov TMOD,#01h
Mov P2,#08h
ACALL DELAY
Mov P2,#04H
ACALL DELAY
Mov P2,#02H
ACALL DELAY
Mov P2,#01H
ACALL DELAY
SJMP LOOP
DELAY:
MOV r0,#200
Mov TL0,#18H
SETB TR0
Wait:JNB TF0,wait
Clr TR0
Clr TF0
DJNZ R0,Back
Ret
end
PROGRAM:
PROTEAUS DESING:
RESULT:
Thus assemble language program to Interface 8051 with Stepper motor was simulated in Keil and
Experiment No. 06
Title of Experiment PROGRAMMABLE PERIPHERAL INTERFACE TO 8051 MICROCONTROLLER
EXPERIMENT OBJECTIVE:
SOFTWARE REQUIRED:
PROGRAMMABLE PERIPHERAL INTERFACE TO 8051 MICROCONTROLLER
Aim:
To interface an LED through 8255 Programmable Peripheral Interface with 8051 through assembly language
Theory:
The number of I/O pins of Intel 8051 microcontroller is limited to 32 only. In some special design cases these many
I/O pins might not be sufficient for the system designer. For applications that require the pulses from many pins of
the 8051, it is always recommended to use 8255 PPI to avoid data loss and damage to the microcontroller.
The 8255 is a widely used, programmable, parallel I/O device. It can be programmed to transfer data under various
conditions, from simple I/O to interrupt I/O.
Features
• Three 8‐bit IO ports PA, PB, PC
• PA can be set for Modes 0, 1, 2. PB for 0, 1 and PC for mode 0 and for BSR. Modes 1 and 2 are interrupt driven.
• PC has two 4‐bit ports: PC upper (PCU) and PC lower (PCL), each can be set independently for Input or Output.
Each PC bit can be set/reset individually in BSR mode.
• PA and PCU are Group A (GA) and PB and PCL are Group B (GB)
• Address/data bus must be externally demultiplexed.
8255 can be operated in two modes BSR (Bit Set Reset) mode or
i. I/O mode
ii. BSR mode Bit set/reset, applicable to PC only. One bit is S/R at a time.
Algorithm:
Program:
mov dptr,#8003h
mov a,#80h
movx @dptr,a
mov dptr, #8000h
mov a, #01h
loop1: movx @dptr,a
acall delay
delay: mov tmod, #10h
loop2: mov th1,#08h
mov tl1,#0fdh
setb tr1
loop3:jnb tf1,loop3
clr tf1
clr tr1
cpl a
sjmp loop1
ret
end
Sample Output:
U1
19 39
XTAL1 P0.0/AD0
38
P0.1/AD1
37
P0.2/AD2
18 36
XTAL2 P0.3/AD3
35
P0.4/AD4
34
P0.5/AD5
33
P0.6/AD6
9 32
RST P0.7/AD7 U2 8255A
21 34 4
80C51 P2.0/A8
22 33
D0 PA0
3
P2.1/A9 D1 PA1
P2.2/A10
23 32
D2 PA2
2 D1
29 24 31 1 LED-BLUE
PSEN P2.3/A11 D3 PA3
30 25 30 40
ALE P2.4/A12 D4 PA4
31 26 29 39
EA P2.5/A13 D5 PA5
27 28 38
P2.6/A14 D6 PA6
28 27 37
P2.7/A15 D7 PA7
1 10 5 18
P1.0 P3.0/RXD RD PB0
2 11 36 19
P1.1 P3.1/TXD WR PB1
3 12 9 20
P1.2 P3.2/INT0 A0 PB2
4 13 8 21
P1.3 P3.3/INT1 A1 PB3
5 14 35 22
P1.4 P3.4/T0 RESET PB4
6 15 23
P1.5 P3.5/T1 PB5
7 16 6 24
P1.6 P3.6/WR CS PB6
8 17 25
P1.7 P3.7/RD PB7
80C51 14
PC0
15
PC1
16
PC2
17
PC3
13
PC4
12
PC5
11
PC6
10
PC7
8255A
Result:
Thus the LED is connected through interfacing a 8255 PPI with 8051 and rotated through
assembly language programming.
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
KUNIAMUTHUR, COIMBATORE 641008
Experiment No. 07
Title of Experiment INTERFACING LED USING ARM WITH KEIL C
Date of Experiment 13/03/2021
THEORY
NXP’s ARM7 (LPC2148), ARM Primer Kit is proposed to smooth the progress of developing
and debugging of various designs encompassing of High speed 32-bit Microcontrollers.
INTERFACING LED
Fig. shows how to interface the LED to microcontroller. As you can see the Anode is
connected through a resistor to GND & the Cathode is connected to the Microcontroller pin. So
when the Port Pin is HIGH the LED is OFF & when the Port Pin is LOW the LED is turned ON.
ALGORITHMS
PROGRAM:
Experiment No. 08
Title of Experiment DATA TRANSCEIVER IN ARM USING UART
Date of Experiment 20/03/2021
AIM:
To transmit and receive a single character data using UART module in ARM
SOFTWARE REQUIRED
i. ARM Evaluation kit
ii. Keil software
THEORY:
The simplest way to communicate between a computer and a microcontroller is through UART
i.e. Universal Asynchronous Receiver Transmitter. It is a type of Serial Communication Protocol
and it uses only two wires for transferring the data. UART Protocol uses only two wires (or pins
in a device like microcontroller) to transmit the data. In that, one is for transmitting the data and
the pin is called TX pin in the device. The other pin is used to receive the data and is called RX
pin.
Both the UART modules are identical, except the UART1 block has an additional full modem
interface. This includes all the pins for RS232 compatibility like flow control pins (CTS, RTS)
etc. Both the UART blocks have 16 byte Receive and Transmit FIFO structures to hold the
transmit and receive data. In order to control the data access and assembly, the UART blocks have
two registers each. For the transmitter operation, the TX has two special registers called Transmit
Holding Register (THR) and Transmit Shift Register (TSR). In order to transmit the data, it is first
sent to THR and then moved to TSR. For the receiver operation, the RX has two special registers
called Receiver Buffer Register (RBR) and Receive Shift Register (RSR). When the data is
received, it is first stored in the RSR and then moved to RBR.
PROGRAM:
#include <lpc214x.h>
int main()
{
PINSEL0 |= 0x05;
U0LCR = 0x83; // line control
U0DLL = 97; //
U0LCR = 0x3; // not
while(1)
{
while(!(U0LSR&0x20));
U0THR='A';
}
}
RESULT:
The transmiting and receiving the single character data using UART module in ARM has
successfully completed.
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
Experiment No. 09
Title of Experiment PROGRAMMING USING ARDUNIO –
LED FADING
EXPERIMENT OBJECTIVE:
EQUIPMENTS REQUIRED:
SOFTWARE REQUIRED
PROGRAMMING USING ARDUNIO – LED FADING
AIM:
To write a program using Ardunio and with the use of analog output (Pulse Width Modulation
(PWM)) to fade an LED.
HARDWARE REQUIRED
1) Arduino or Genuino board
2) LED
3) 220 ohm resistor
4) hook-up wires
5) breadboard
CIRCUIT
PWM is a technique for getting an analog-like behavior from a digital output by switching it off and on very
fast and with different ratio between on and off time. An LED connected to digital output pin 9 through a 220 ohm
resistor.
CODE
intledPin = 9; // LED connected to digital pin 9
void setup() {
// nothing happens in setup
}
void loop() {
// fade in from min to max in increments of 5 points:
for (intfadeValue = 0 ; fadeValue<= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
int brightness = 0;
void setup()
{
pinMode(9, OUTPUT);
}
void loop()
{
for (brightness = 0; brightness <= 255; brightness += 5) {
analogWrite(9, brightness);
delay(30); // Wait for 30 millisecond(s)
}
for (brightness = 255; brightness >= 0; brightness -= 5) {
analogWrite(9, brightness);
delay(30); // Wait for 30 millisecond(s)
}
}
RESULT
Experiment No. 10
Title of Experiment TRAFFIC LIGHT CONTROLLER USING AR-
DUNIO
EXPERIMENT OBJECTIVE:
SOFTWARE REQUIRED:
TRAFFIC LIGHT CONTROLLER USING ARDUNIO
AIM
To write a program using Ardunio to control the traffic light.
APPARATUS REQUIRED:
CIRCUIT
That was easy. Now for the difficult part -– the actual logic of a traffic light. Create a sepa-
rate function for changing the lights (you’ll see why later).
When you first begin programming, the code itself is very rudimentary – it’s figuring out the minute logic
details that presents the biggest problem. The key to being a good programmer is to be able to look at any process, and
break it down into its fundamental steps.
CODE
void setup(){
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
void loop(){
changeLights();
delay(15000);
}
voidchangeLights(){
// green off, yellow on for 3 seconds
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(3000);
void setup()
{
pinMode(13, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(6000);
digitalWrite(13, LOW);
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
delay(3000);
digitalWrite(2, LOW);
}
RESULT:
The TRAFFIC LIGHT CONTROLLER USING ARDUNIO has been stuied and
executed successfully
SRI KRISHNA COLLEGE OF ENGINEERING AND
TECHNOLOGY
(AN AUTONOMOUS INSTITUTION)
Experiment No. 11
Title of Experiment INTERFACING GAS SENSOR WITH AR-
DUINO
Date of Experiment 27/03/2021
EXPERIMENT OBJECTIVE:
SOFTWARE REQUIRES:
INTERFACING GAS SENSOR WITH ARDUINO
AIM
To write a program to Interfacing Gas sensor with Arduino .
APPARATUS REQUIRED:
THEORY:
Gas sensor is one which comes handy in applications where we have to detect the variation in the concentration of
toxic gases in order to maintain the system safe and avoid/caution any unexpected threats. There are various gas
sensors to detect gases like oxygen, Carbon Dioxide, Nitrogen, methane etc. They can also be commonly found in
devices that are used to detect the leakage of the harmful gases, monitor the air quality in industries and offices etc.
A gas sensor is a device which detects the presence or concentration of gases in the atmosphere. Based on the
concentration of the gas the sensor produces a corresponding potential difference by changing the resistance of the
material inside the sensor, which can be measured as output voltage. Based on this voltage value the type and
concentration of the gas can be estimated.
SCHEMATIC:
CODE
/*
### Detector de gás ###
# Verde = Seguro #
# Amarelo = Alerta #
# Laranja = Perigo #
# Vermelho = Área Contaminada #
*/
void loop(){
int valor = analogRead(PINO_SGAS);
valor = map(valor, 300, 750, 0, 100);
digitalWrite(LED_VERDE, HIGH);
digitalWrite(LED_AMARELO, valor >= 30 ? HIGH : LOW);
digitalWrite(LED_VERMELHO1, valor >= 50 ? HIGH : LOW);
digitalWrite(LED_VERMELHO2, valor >= 80 ? HIGH : LOW);
delay(250);
}
RESULT:
The INTERFACING GAS SENSOR WITH ARDUINO has been studied and
executed successfully.