SlideShare a Scribd company logo
1 of 65
Download to read offline
UNIT V
INTERFACING MICROCONTROLLER
Programming 8051 Timers - Serial Port
Programming - Interrupts Programming – LCD
& Keyboard Interfacing - ADC, DAC & Sensor
Interfacing - External Memory Interface-
Stepper Motor and Waveform generation -
Comparison of Microprocessor,
Microcontroller, PIC and ARM processors
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
1
PROGRAMMING8051 TIMERS
Mode 1 Programming
• It allows values of 0000 H to FFFF H to be loaded into
the timer’s registers TL and TH.
• After TH and TL are loaded with a 16 - bit initial value,
the timer must be started.
• This is done by “SET B TR0” for Timer 0 and “SET B
TR1” for Timer 1.
• After the timer is started, it starts to count up. It
counts up until it reaches its limit of FFFF H. When it
rolls over from FFFF H to 0000H, it sets high a flag bit
called TF (Timer Flag).
• 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.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
2
• After the timer reaches its limit and rolls over to
repeat the process the registers TH and TL must
be reloaded with the original value and TF must
be reset to 0.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
3
Programming in mode 1 to generate a
time delay:
• 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.
• Load registers TL and TH with initial count values.
• Start the Timer.
• Keep monitoring the timer flag (TF). When TF
becomes high get out of the loop.
• Stop the timer.
• Clear the TF flag for the next round.
• Go back to step 2 to load TL and TH again.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
4
Program
• Write an ALP to generate a square wave of 50% duty cycle on the P2.2 bit.
Timer 0 is used to generate the time delay. Crystal frequency = 11.0592 MHz.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
5
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
6
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
7
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
8
Mode 2 Programming
• Mode 2 allows only values of 00 H to FF H to be
loaded into the timer’s register TH.
• After TH is loaded with the 8 bit value, the 8051
gives a copy of it to TL. Then the timer must be
started. This is done by “SET B TR0” for Timer 0 and
“SET B TR 1” for Timer 1.
• After the timer is started, it started it starts to count
up by incrementing the TL register. It counts up until
it reaches its limit of FFH. When it rolls over from
FFH to 00H, it sets high the timer flag (TF) TF0 is
raised for Timer 0 and TF 1 is raised for Timer 1.
• When the TL register rolls from FF H to 00 H and TF is
set to 1, TL is reloaded automatically with the
original value kept by the TH register. To repeat the
process clear TF (anti - reloading).
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
9
Programming in Mode 2 to generate a time delay:
• Load the TMOD value register indicating which timer (Timer 0
or 1) is to be used and select the timer mode 2.
• Load the TH registers with the initial count value.
• Start the timer.
• Keep monitoring the timer flag (TF) with “JNB TFx” instruction.
When TF becomes high get out of the loop.
• Clear the TF flag
• Go back to step 4, since Mode 2 is auto - reload.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
10
• Program :
• Write an ALP to generate 2KHz square waveform on pin 1.3 use Timer 1,
Auto reload mode. Assume crystal frequency is 12MHz.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
11
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
12
INTERRUPT PROGRAMMING
• An interrupt is an internal or external event that interrupts
the microcontroller to inform it that a device needs its
service.
• Every interrupt has a program associated with it called the
interrupt service routine (ISR). The 8051 has 6 interrupts:
• Reset
• Timer interrupts : Timer 0 interrupt
• Timer 1 interrupt
• External hardware interrupts : INT 0, INT 1
• Serial communication interrupt
• The 8051 can be programmed to enable or disable an
interrupt and the interrupt priority can be altered. Register
IE is responsible for enabling and disabling the interrupts.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
13
Programming Timer Interrupts:
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
14
Programming External Hardware Interrupts
• The 8051 has two external hardware interrupts
INT 0 and INT 1. Upon activation of these
interrupts through Port pins P3.2 and P3.3, the
8051 gets interrupted in whatever it is doing and
jumps to the interrupt vector table to perform
the interrupt service routine (ISR).
• There are two types of activation for the external
hardware interrupts: Level triggered and Edge
triggered.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
15
KEYBOARD INTERFACING
• A matrix keyboard having a 4 x 4 matrix of rows and
columns.
• The rows are connected to an output port and the columns
are connected to an input port.
• When a key is pressed, a row and a column make a contact,
otherwise there is no connection between rows and
columns.
• If all the rows are grounded and a key is pressed, one of
the columns will have 0 since the key pressed provides the
path to ground.
• If no key has been pressed, reading the input port will yield
1s for all columns since they are connected to Vcc.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
16
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
17
• To make sure that the preceeding key has been
released, 0s are output to all rows at once and
the columns are read and checked repeatedly
until all the columns are high.
• When all columns are found to be high, the
program waits for a short amount of time before
it goes to the next stage of waiting for a key to be
pressed.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
18
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
19
LCD INTERFACING
• The various types of LCD displays are, 16x2, 20x1,
20x2, 20x4, 40x2 and 40x4 LCDs.
• 16x2 LCD means that it having two lines, 16
characters per line. Figure shows LCD interfacing
with 8051.
• The 8 bit data pins (D0–D7) are used to send
information tot he LCD or read the contents of
the LCD’s internal registers.
• The data lines are connected to Port 1. Register
Select (RS), Read/Write ( R/W ) and Enable (EN)
plans are connected to Port 3.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
20
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
21
• There are two important registers are available
inside the LCD.
• They are (i) instruction command register, (ii)
data registr.
• The RS pin is used to select the register. If RS=0,
the instruction command code register is
selected, allowing the user to send a command.
• If RS=1, the data register is selected, allowing the
user to send data to be displayed on the LCD.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
22
• R/W pin is used to write information to the LCD or
read information from it.
• EN (enable) pin is used to latch information
presented to its data pins.
• When data is supplied to data pins, a high-to-low
pulse must be applied to EN pin in order for the
LCD to latch in the data present at the data pins.
This pulse must be a minimum of 450 ns.
• When busy flas (D7)=1, the LCD is busy and will
not accept any new informations.
• When busy flas (D7) = 0, the LCD is ready to
receive new information.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
23
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
24
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
25
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
26
ADC interfacing
• ADCs are used to convert the analog signals to
digital numbers so that the microcontroller can
read them.
• ADC [like ADC 0804 IC] works with +5 volts and
has a resolution of 8 bits.
• Conversion time is defined as the time taken to
convert the analog input to digital (binary)
number.
• The conversion time varies depending upon the
clock signals; it cannot be faster than 110 μs .
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
27
• Analog input is given to the pins Vin (+) and Vin (-).
• Vin (-) is connected to ground.
• Digital output pins are D0 - D7. D7 is the MSB and
D0 is the LSB.
• There are two pins for ground, analog ground
and digital ground. Analog ground is connected to
the ground of the analog Vin and digital ground is
connected to the ground of the VCC pin.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
28
The following steps are followed for data
conversion :
• Make chip select ( CS ) = 0 and send a low - to -
high pulse to pin WR to start the conversion.
• Keep monitoring the INTR pin. If INTR is low, the
conversion is finished and go to the next step. If
INTR is high, keep polling until it goes low.
• After the INTR has become low, we make CS = 0
and send a high- to-low pulse to the RD pin to get
the data out. The timing for this process is shown
in Fig.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
29
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
30
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
31
DAC INTERFACING
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
32
SENSOR INTERFACING
Sensor :
• Sensor converts the physical Pressure,
Temperature or other variable to a proportional
voltage or current.
Types of Sensors :
• Light Sensor
• Temperature Sensor
• Pressure Sensor
• Force Sensor
• Flow Sensor
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
33
Temperature Sensor
• There are many types of temperature sensors.
Now we discuss about Semiconductor
Temperature Sensor (LM 35).
• The LM35 series sensors are precision integrated
circuit temperature sensor whose output voltage
is proportional to the Celsius (centigrade)
temperature.
• It outputs 10 mV for each degree of centigrade
temperature. If the output is connected to a
negative reference voltage VS, the sensor will give
a meaningful output for a temperature range of –
550C to +1500C.
• The output voltage can be amplified or filtered
for a particular application.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
34
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
35
Sensor interfacing with 8051
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
36
• The temperature sensor output (Vout) is given to signal
conditioner. Signal conditioning is used for current-to-
voltage conversion or a signal amplification.
• The amplified signal is now given to analog-to-digital
converter (ADC 0848). Since the ADC0848 has 8 bit
resolution with a maximum of 256 (28) steps and the
LM35 produces 10mV for every degree of temperature
change, we can condition Vin of the ADC 0848 to
produce a Vout of 256 x 10 = 2560 mV for full-scale
output.
• Therefore, in order to produce the full-scale Vout of
2560 mV (2.56 V) for the ADC 0848, we need to set
Vref = 2.56 V.
• This makes Vout of ADC 0848 corresponding directly to
the temperaure as monitored by the LM35. Figure 5.18
shows the interfacing of a temperature sensor with
8051 microcontroller.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
37
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
38
STEPPER MOTOR INTERFACING
• A stepper motor is a widely used device that translates electrical
pulses into mechanical movement.
• In applications such as disk drives, dot matrix printers and robotics
the stepper motor is used for position control.
• Every stepper motor has a permanent magnet rotor surrounded by
four stator windings, that are paired with a center-tapped common.
• The center tap allows a change of current direction in each of two
coils when a winding is grounded, thereby resulting in a polarity
change of the stator. The stepper motor shaft runs in a fixed
repeatable increment which allows one to move it to a precise
position.
• This repeatable fixed movement is possible as a result of basic
magnetic theory where poles of the same polarity repel and
opposite poles attract.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
39
• The direction of the rotation is dictated by the
stator poles.
• The stator poles are determined by the current
sent through the wire coils.
• As the direction of the current is changed, the
polarity is also changed causing the reverse
motion of the rotor As the sequence of power is
applied to each stator winding, the rotor will
rotate.
• There are several used sequences where each has
a different degree of precision.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
40
• The driver must be able to handle the current and
voltage involved.
• Furthermore, because the load is inductive, the
drivers must be protected against the inductive
voltage surge which occurs when a transistor
switch tries to open up and discontinue the
current flow through a winding of the stepper.
• The drivers include clamping diodes to deactivate
this problem. Now when one of the drivers turns
off, its diode permits the current which was
flowing through the motor winding to continue,
dying away at a rate determined by the L/R ratio
of the motor winding.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
41
Normal 4 step sequence
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
42
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
43
EXTERNAL MEMORY INTERFACING
• When the data is located in the code space of 8051,
MOVC instruction is used to get the data, where ‘C’
stands for code.
• When the data memory space must be implemented
externally, MOVX instruction is used, where ‘X’ stands
for external.
External ROM Interfacing
•External ROM is accessed whenever the EA(external access)
pin is connected to ground or when the PC contains an address
higher than the last address in the internal 4K bytes ROM
(0FFFH).
•8051 designs can thus use internal and external ROM
automatically; the 8031, having no internal ROM, must have
EA grounded.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
44
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
45
External data RAM interfacing
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
46
Interrupt Programming
• An interrupt is an internal or external event that
interrupts the microcontroller to inform it that a
device needs its service. Every interrupt has a
program associated with it called the interrupt
service routine (ISR). The 8051 has 6 interrupts:
Reset
Timer interrupts : Timer 0 interrupt
Timer 1 interrupt
External hardware interrupts : INT 0 INT 1
Serial communication interrupt
• The 8051 can be programmed to enable or
disable an interrupt and the interrupt priority can
be altered. Register IE is responsible for enabling
and disabling the interrupts.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
47
Programming Timer Interrupts
• The timer flag (TF) is raised when the timer rolls over. In polling TF,
we have to wait until the TF is raised.
• In problem with polling method is that the microcontroller is tied
down while waiting for TF to be raised and cannot do anything else.
• Using interrupts solves this problem and avoids trying down the
microcontroller.
• If the timer interrupt in the IE register is enabled, whenever the
timer rolls over, TF is raised and the microcontroller is interrupted in
whatever it is doing and jumps to the interrupt vector table to
service the ISR.
• In this way the microcontroller can do other things until it is notified
that the timer has rolled over.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
48
Program
Write an ALP that continuously gets 8-bit data from port 0 and sends it to port 1 while
simultaneously creating a square wave of 200 ms period on pin 2.3. Use Timer 0 to create the
square wave.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
49
Programming External Hardware Interrupts
Program
Write a program in which the INT 1 pin is connected to a switch that
is normally high (+Vcc). Whenever it goes low, it should turn on an
LED. The LED is connected to Port 2.4 and is normally off. When it is
turned on it should stay on for a fraction of a second. As long as the
switch is pressed low, the LED should stay on.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
50
Program :
Write 8051 ALP to display the characters ‘MICRO’ in the
first row, third position of 2 lines x 20 characters LCD.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
51
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
52
Program :
Using ADC and 8051, digitize an input waveform for every
50 micro seconds until 1000 samples have been stored in
external RAM location at 2000H. Assume crystal frequency
= 12MHz.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
53
Sine wave generation
Program :
• Write 8051 ALP to generate sine wave using DAC with 125 samples.
Assume output voltage is 5V.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
54
Program:
Write 8051 ALP to generate the square wave on Port 1.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
55
• Program:
Write 8051 ALP to generate the triangular wave on Port 1.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
56
Program:
• Write 8051 ALP to generate the staircase wave with three levels of voltage V1 , V2
and V3.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
57
Program:
• Write 8051 ALP to generate the ramp wave increasing from 00H to
FFH.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
58
• Problem – Write a program in 8086 microprocessor to multiply two
8-bit numbers, where numbers are stored from offset 500 and store
the result into offset 600.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
59
• Problem – Write a program to multiply two 16-bit
numbers where starting address is 2000 and the
numbers are at 3000 and 3002 memory address and
store result into 3004 and 3006 memory address.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
60
• Problem – Write an assembly language program in 8086
microprocessor to find average of n eight bit numbers
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
61
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
62
• Write 8086 Assembly language program to find the largest
number in a given array, which is starts from memory offset
501. The size of the series is stored at memory offset 500.
Store the largest number at memory offset 600.
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
63
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
64
5/25/2021
Kongunadu College of Engineering and
Technology(Autonomous)
65

More Related Content

What's hot

Interfacing technique with 8085- ADC[0808]
Interfacing technique with 8085- ADC[0808]Interfacing technique with 8085- ADC[0808]
Interfacing technique with 8085- ADC[0808]Guhan k
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051ssuser3a47cb
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controllerabhikalmegh
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction SetDr. Pankaj Zope
 
8086 in minimum mode
8086 in minimum mode8086 in minimum mode
8086 in minimum modeSridari Iyer
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
Digital to Analog Converter by LDCE students
Digital to Analog Converter by LDCE studentsDigital to Analog Converter by LDCE students
Digital to Analog Converter by LDCE studentsMitul Lakhani
 
8 interrupt 8051
8 interrupt 80518 interrupt 8051
8 interrupt 8051daniemol
 
Memory & I/O interfacing
Memory & I/O  interfacingMemory & I/O  interfacing
Memory & I/O interfacingdeval patel
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller pptRahul Kumar
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerGaurav Verma
 
Counters & time delay
Counters & time delayCounters & time delay
Counters & time delayHemant Chetwani
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers ViVek Patel
 
INTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSORINTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSORSagar Kuntumal
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086Mahalakshmiv11
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051SARITHA REDDY
 

What's hot (20)

Interfacing technique with 8085- ADC[0808]
Interfacing technique with 8085- ADC[0808]Interfacing technique with 8085- ADC[0808]
Interfacing technique with 8085- ADC[0808]
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
 
8086 in minimum mode
8086 in minimum mode8086 in minimum mode
8086 in minimum mode
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Digital to Analog Converter by LDCE students
Digital to Analog Converter by LDCE studentsDigital to Analog Converter by LDCE students
Digital to Analog Converter by LDCE students
 
8 interrupt 8051
8 interrupt 80518 interrupt 8051
8 interrupt 8051
 
Adc interfacing
Adc interfacingAdc interfacing
Adc interfacing
 
Multiplexers & Demultiplexers
Multiplexers & DemultiplexersMultiplexers & Demultiplexers
Multiplexers & Demultiplexers
 
Memory & I/O interfacing
Memory & I/O  interfacingMemory & I/O  interfacing
Memory & I/O interfacing
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller ppt
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
Counters & time delay
Counters & time delayCounters & time delay
Counters & time delay
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers
 
INTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSORINTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSOR
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
 

Similar to Programming 8051 Timers, Interrupts, LCD & Keyboard Interfacing

UNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptxUNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptxGowrishankar C
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfSPonmalar1
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interfaceAbhishek Choksi
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and RoboticsNIT Raipur
 
Calculator design with lcd using fpga
Calculator design with lcd using fpgaCalculator design with lcd using fpga
Calculator design with lcd using fpgaHossam Hassan
 
Electronic voting machine using mcu 89s52
Electronic voting machine using mcu 89s52Electronic voting machine using mcu 89s52
Electronic voting machine using mcu 89s52Saurav Kumar
 
Electronic voting machine presentation
Electronic voting machine  presentationElectronic voting machine  presentation
Electronic voting machine presentationRavikant Dhayal
 
8051 training an interactive tutorial
8051 training an interactive tutorial8051 training an interactive tutorial
8051 training an interactive tutorialFutura infotech
 
Plc scada by bhushan kumbhalkar
Plc scada by bhushan kumbhalkarPlc scada by bhushan kumbhalkar
Plc scada by bhushan kumbhalkarBhushan Kumbhalkar
 
MPC of TWT based Transmitter
MPC of TWT based TransmitterMPC of TWT based Transmitter
MPC of TWT based TransmitterAbhishek Sutrave
 
digitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfdigitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfsatyamsinha37
 
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERDIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERChirag Lakhani
 
project report on embedded system
project report on embedded systemproject report on embedded system
project report on embedded systemram avtar
 
Embeded system by Mitesh Kumar
Embeded system by Mitesh KumarEmbeded system by Mitesh Kumar
Embeded system by Mitesh KumarMitesh Kumar
 
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
UNIT 4 & 5 - I         nterfacing_Lecture7.pptxUNIT 4 & 5 - I         nterfacing_Lecture7.pptx
UNIT 4 & 5 - I nterfacing_Lecture7.pptxnaveen088888
 

Similar to Programming 8051 Timers, Interrupts, LCD & Keyboard Interfacing (20)

UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
UNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptxUNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptx
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdf
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interface
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and Robotics
 
Calculator design with lcd using fpga
Calculator design with lcd using fpgaCalculator design with lcd using fpga
Calculator design with lcd using fpga
 
Electronic voting machine using mcu 89s52
Electronic voting machine using mcu 89s52Electronic voting machine using mcu 89s52
Electronic voting machine using mcu 89s52
 
Electronic voting machine presentation
Electronic voting machine  presentationElectronic voting machine  presentation
Electronic voting machine presentation
 
Unit 3 mpmc
Unit 3 mpmcUnit 3 mpmc
Unit 3 mpmc
 
8051 training an interactive tutorial
8051 training an interactive tutorial8051 training an interactive tutorial
8051 training an interactive tutorial
 
Plc scada by bhushan kumbhalkar
Plc scada by bhushan kumbhalkarPlc scada by bhushan kumbhalkar
Plc scada by bhushan kumbhalkar
 
MPC of TWT based Transmitter
MPC of TWT based TransmitterMPC of TWT based Transmitter
MPC of TWT based Transmitter
 
8051 io interface
8051 io interface8051 io interface
8051 io interface
 
digitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfdigitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdf
 
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERDIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
 
project report on embedded system
project report on embedded systemproject report on embedded system
project report on embedded system
 
Embeded system by Mitesh Kumar
Embeded system by Mitesh KumarEmbeded system by Mitesh Kumar
Embeded system by Mitesh Kumar
 
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
UNIT 4 & 5 - I         nterfacing_Lecture7.pptxUNIT 4 & 5 - I         nterfacing_Lecture7.pptx
UNIT 4 & 5 - I nterfacing_Lecture7.pptx
 
8051
80518051
8051
 
Unit 4
Unit 4Unit 4
Unit 4
 

More from tamilnesaner

More from tamilnesaner (13)

BEEME UNIT V.ppt
BEEME UNIT V.pptBEEME UNIT V.ppt
BEEME UNIT V.ppt
 
Unit 2 mpmc
Unit 2 mpmcUnit 2 mpmc
Unit 2 mpmc
 
Unit 1 MPMC
Unit 1 MPMCUnit 1 MPMC
Unit 1 MPMC
 
Smart meter
Smart meterSmart meter
Smart meter
 
Lcr meter
Lcr meterLcr meter
Lcr meter
 
Tachometer and clamp meter
Tachometer and clamp meterTachometer and clamp meter
Tachometer and clamp meter
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit 4
Unit 4Unit 4
Unit 4
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 2
Unit 2Unit 2
Unit 2
 
Unit 1
Unit 1Unit 1
Unit 1
 
Unit 1 static and dynamic
Unit 1 static and dynamicUnit 1 static and dynamic
Unit 1 static and dynamic
 
Three phase voltage source inverter
Three phase voltage source inverterThree phase voltage source inverter
Three phase voltage source inverter
 

Recently uploaded

Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 

Recently uploaded (20)

Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 

Programming 8051 Timers, Interrupts, LCD & Keyboard Interfacing

  • 1. UNIT V INTERFACING MICROCONTROLLER Programming 8051 Timers - Serial Port Programming - Interrupts Programming – LCD & Keyboard Interfacing - ADC, DAC & Sensor Interfacing - External Memory Interface- Stepper Motor and Waveform generation - Comparison of Microprocessor, Microcontroller, PIC and ARM processors 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 1
  • 2. PROGRAMMING8051 TIMERS Mode 1 Programming • It allows values of 0000 H to FFFF H to be loaded into the timer’s registers TL and TH. • After TH and TL are loaded with a 16 - bit initial value, the timer must be started. • This is done by “SET B TR0” for Timer 0 and “SET B TR1” for Timer 1. • After the timer is started, it starts to count up. It counts up until it reaches its limit of FFFF H. When it rolls over from FFFF H to 0000H, it sets high a flag bit called TF (Timer Flag). • 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. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 2
  • 3. • After the timer reaches its limit and rolls over to repeat the process the registers TH and TL must be reloaded with the original value and TF must be reset to 0. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 3
  • 4. Programming in mode 1 to generate a time delay: • 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. • Load registers TL and TH with initial count values. • Start the Timer. • Keep monitoring the timer flag (TF). When TF becomes high get out of the loop. • Stop the timer. • Clear the TF flag for the next round. • Go back to step 2 to load TL and TH again. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 4
  • 5. Program • Write an ALP to generate a square wave of 50% duty cycle on the P2.2 bit. Timer 0 is used to generate the time delay. Crystal frequency = 11.0592 MHz. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 5
  • 6. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 6
  • 7. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 7
  • 8. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 8
  • 9. Mode 2 Programming • Mode 2 allows only values of 00 H to FF H to be loaded into the timer’s register TH. • After TH is loaded with the 8 bit value, the 8051 gives a copy of it to TL. Then the timer must be started. This is done by “SET B TR0” for Timer 0 and “SET B TR 1” for Timer 1. • After the timer is started, it started it starts to count up by incrementing the TL register. It counts up until it reaches its limit of FFH. When it rolls over from FFH to 00H, it sets high the timer flag (TF) TF0 is raised for Timer 0 and TF 1 is raised for Timer 1. • When the TL register rolls from FF H to 00 H and TF is set to 1, TL is reloaded automatically with the original value kept by the TH register. To repeat the process clear TF (anti - reloading). 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 9
  • 10. Programming in Mode 2 to generate a time delay: • Load the TMOD value register indicating which timer (Timer 0 or 1) is to be used and select the timer mode 2. • Load the TH registers with the initial count value. • Start the timer. • Keep monitoring the timer flag (TF) with “JNB TFx” instruction. When TF becomes high get out of the loop. • Clear the TF flag • Go back to step 4, since Mode 2 is auto - reload. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 10
  • 11. • Program : • Write an ALP to generate 2KHz square waveform on pin 1.3 use Timer 1, Auto reload mode. Assume crystal frequency is 12MHz. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 11
  • 12. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 12
  • 13. INTERRUPT PROGRAMMING • An interrupt is an internal or external event that interrupts the microcontroller to inform it that a device needs its service. • Every interrupt has a program associated with it called the interrupt service routine (ISR). The 8051 has 6 interrupts: • Reset • Timer interrupts : Timer 0 interrupt • Timer 1 interrupt • External hardware interrupts : INT 0, INT 1 • Serial communication interrupt • The 8051 can be programmed to enable or disable an interrupt and the interrupt priority can be altered. Register IE is responsible for enabling and disabling the interrupts. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 13
  • 14. Programming Timer Interrupts: 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 14
  • 15. Programming External Hardware Interrupts • The 8051 has two external hardware interrupts INT 0 and INT 1. Upon activation of these interrupts through Port pins P3.2 and P3.3, the 8051 gets interrupted in whatever it is doing and jumps to the interrupt vector table to perform the interrupt service routine (ISR). • There are two types of activation for the external hardware interrupts: Level triggered and Edge triggered. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 15
  • 16. KEYBOARD INTERFACING • A matrix keyboard having a 4 x 4 matrix of rows and columns. • The rows are connected to an output port and the columns are connected to an input port. • When a key is pressed, a row and a column make a contact, otherwise there is no connection between rows and columns. • If all the rows are grounded and a key is pressed, one of the columns will have 0 since the key pressed provides the path to ground. • If no key has been pressed, reading the input port will yield 1s for all columns since they are connected to Vcc. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 16
  • 17. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 17
  • 18. • To make sure that the preceeding key has been released, 0s are output to all rows at once and the columns are read and checked repeatedly until all the columns are high. • When all columns are found to be high, the program waits for a short amount of time before it goes to the next stage of waiting for a key to be pressed. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 18
  • 19. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 19
  • 20. LCD INTERFACING • The various types of LCD displays are, 16x2, 20x1, 20x2, 20x4, 40x2 and 40x4 LCDs. • 16x2 LCD means that it having two lines, 16 characters per line. Figure shows LCD interfacing with 8051. • The 8 bit data pins (D0–D7) are used to send information tot he LCD or read the contents of the LCD’s internal registers. • The data lines are connected to Port 1. Register Select (RS), Read/Write ( R/W ) and Enable (EN) plans are connected to Port 3. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 20
  • 21. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 21
  • 22. • There are two important registers are available inside the LCD. • They are (i) instruction command register, (ii) data registr. • The RS pin is used to select the register. If RS=0, the instruction command code register is selected, allowing the user to send a command. • If RS=1, the data register is selected, allowing the user to send data to be displayed on the LCD. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 22
  • 23. • R/W pin is used to write information to the LCD or read information from it. • EN (enable) pin is used to latch information presented to its data pins. • When data is supplied to data pins, a high-to-low pulse must be applied to EN pin in order for the LCD to latch in the data present at the data pins. This pulse must be a minimum of 450 ns. • When busy flas (D7)=1, the LCD is busy and will not accept any new informations. • When busy flas (D7) = 0, the LCD is ready to receive new information. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 23
  • 24. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 24
  • 25. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 25
  • 26. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 26
  • 27. ADC interfacing • ADCs are used to convert the analog signals to digital numbers so that the microcontroller can read them. • ADC [like ADC 0804 IC] works with +5 volts and has a resolution of 8 bits. • Conversion time is defined as the time taken to convert the analog input to digital (binary) number. • The conversion time varies depending upon the clock signals; it cannot be faster than 110 μs . 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 27
  • 28. • Analog input is given to the pins Vin (+) and Vin (-). • Vin (-) is connected to ground. • Digital output pins are D0 - D7. D7 is the MSB and D0 is the LSB. • There are two pins for ground, analog ground and digital ground. Analog ground is connected to the ground of the analog Vin and digital ground is connected to the ground of the VCC pin. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 28
  • 29. The following steps are followed for data conversion : • Make chip select ( CS ) = 0 and send a low - to - high pulse to pin WR to start the conversion. • Keep monitoring the INTR pin. If INTR is low, the conversion is finished and go to the next step. If INTR is high, keep polling until it goes low. • After the INTR has become low, we make CS = 0 and send a high- to-low pulse to the RD pin to get the data out. The timing for this process is shown in Fig. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 29
  • 30. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 30
  • 31. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 31
  • 32. DAC INTERFACING 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 32
  • 33. SENSOR INTERFACING Sensor : • Sensor converts the physical Pressure, Temperature or other variable to a proportional voltage or current. Types of Sensors : • Light Sensor • Temperature Sensor • Pressure Sensor • Force Sensor • Flow Sensor 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 33
  • 34. Temperature Sensor • There are many types of temperature sensors. Now we discuss about Semiconductor Temperature Sensor (LM 35). • The LM35 series sensors are precision integrated circuit temperature sensor whose output voltage is proportional to the Celsius (centigrade) temperature. • It outputs 10 mV for each degree of centigrade temperature. If the output is connected to a negative reference voltage VS, the sensor will give a meaningful output for a temperature range of – 550C to +1500C. • The output voltage can be amplified or filtered for a particular application. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 34
  • 35. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 35
  • 36. Sensor interfacing with 8051 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 36
  • 37. • The temperature sensor output (Vout) is given to signal conditioner. Signal conditioning is used for current-to- voltage conversion or a signal amplification. • The amplified signal is now given to analog-to-digital converter (ADC 0848). Since the ADC0848 has 8 bit resolution with a maximum of 256 (28) steps and the LM35 produces 10mV for every degree of temperature change, we can condition Vin of the ADC 0848 to produce a Vout of 256 x 10 = 2560 mV for full-scale output. • Therefore, in order to produce the full-scale Vout of 2560 mV (2.56 V) for the ADC 0848, we need to set Vref = 2.56 V. • This makes Vout of ADC 0848 corresponding directly to the temperaure as monitored by the LM35. Figure 5.18 shows the interfacing of a temperature sensor with 8051 microcontroller. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 37
  • 38. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 38
  • 39. STEPPER MOTOR INTERFACING • A stepper motor is a widely used device that translates electrical pulses into mechanical movement. • In applications such as disk drives, dot matrix printers and robotics the stepper motor is used for position control. • Every stepper motor has a permanent magnet rotor surrounded by four stator windings, that are paired with a center-tapped common. • The center tap allows a change of current direction in each of two coils when a winding is grounded, thereby resulting in a polarity change of the stator. The stepper motor shaft runs in a fixed repeatable increment which allows one to move it to a precise position. • This repeatable fixed movement is possible as a result of basic magnetic theory where poles of the same polarity repel and opposite poles attract. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 39
  • 40. • The direction of the rotation is dictated by the stator poles. • The stator poles are determined by the current sent through the wire coils. • As the direction of the current is changed, the polarity is also changed causing the reverse motion of the rotor As the sequence of power is applied to each stator winding, the rotor will rotate. • There are several used sequences where each has a different degree of precision. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 40
  • 41. • The driver must be able to handle the current and voltage involved. • Furthermore, because the load is inductive, the drivers must be protected against the inductive voltage surge which occurs when a transistor switch tries to open up and discontinue the current flow through a winding of the stepper. • The drivers include clamping diodes to deactivate this problem. Now when one of the drivers turns off, its diode permits the current which was flowing through the motor winding to continue, dying away at a rate determined by the L/R ratio of the motor winding. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 41
  • 42. Normal 4 step sequence 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 42
  • 43. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 43
  • 44. EXTERNAL MEMORY INTERFACING • When the data is located in the code space of 8051, MOVC instruction is used to get the data, where ‘C’ stands for code. • When the data memory space must be implemented externally, MOVX instruction is used, where ‘X’ stands for external. External ROM Interfacing •External ROM is accessed whenever the EA(external access) pin is connected to ground or when the PC contains an address higher than the last address in the internal 4K bytes ROM (0FFFH). •8051 designs can thus use internal and external ROM automatically; the 8031, having no internal ROM, must have EA grounded. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 44
  • 45. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 45
  • 46. External data RAM interfacing 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 46
  • 47. Interrupt Programming • An interrupt is an internal or external event that interrupts the microcontroller to inform it that a device needs its service. Every interrupt has a program associated with it called the interrupt service routine (ISR). The 8051 has 6 interrupts: Reset Timer interrupts : Timer 0 interrupt Timer 1 interrupt External hardware interrupts : INT 0 INT 1 Serial communication interrupt • The 8051 can be programmed to enable or disable an interrupt and the interrupt priority can be altered. Register IE is responsible for enabling and disabling the interrupts. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 47
  • 48. Programming Timer Interrupts • The timer flag (TF) is raised when the timer rolls over. In polling TF, we have to wait until the TF is raised. • In problem with polling method is that the microcontroller is tied down while waiting for TF to be raised and cannot do anything else. • Using interrupts solves this problem and avoids trying down the microcontroller. • If the timer interrupt in the IE register is enabled, whenever the timer rolls over, TF is raised and the microcontroller is interrupted in whatever it is doing and jumps to the interrupt vector table to service the ISR. • In this way the microcontroller can do other things until it is notified that the timer has rolled over. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 48
  • 49. Program Write an ALP that continuously gets 8-bit data from port 0 and sends it to port 1 while simultaneously creating a square wave of 200 ms period on pin 2.3. Use Timer 0 to create the square wave. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 49
  • 50. Programming External Hardware Interrupts Program Write a program in which the INT 1 pin is connected to a switch that is normally high (+Vcc). Whenever it goes low, it should turn on an LED. The LED is connected to Port 2.4 and is normally off. When it is turned on it should stay on for a fraction of a second. As long as the switch is pressed low, the LED should stay on. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 50
  • 51. Program : Write 8051 ALP to display the characters ‘MICRO’ in the first row, third position of 2 lines x 20 characters LCD. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 51
  • 52. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 52
  • 53. Program : Using ADC and 8051, digitize an input waveform for every 50 micro seconds until 1000 samples have been stored in external RAM location at 2000H. Assume crystal frequency = 12MHz. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 53
  • 54. Sine wave generation Program : • Write 8051 ALP to generate sine wave using DAC with 125 samples. Assume output voltage is 5V. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 54
  • 55. Program: Write 8051 ALP to generate the square wave on Port 1. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 55
  • 56. • Program: Write 8051 ALP to generate the triangular wave on Port 1. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 56
  • 57. Program: • Write 8051 ALP to generate the staircase wave with three levels of voltage V1 , V2 and V3. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 57
  • 58. Program: • Write 8051 ALP to generate the ramp wave increasing from 00H to FFH. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 58
  • 59. • Problem – Write a program in 8086 microprocessor to multiply two 8-bit numbers, where numbers are stored from offset 500 and store the result into offset 600. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 59
  • 60. • Problem – Write a program to multiply two 16-bit numbers where starting address is 2000 and the numbers are at 3000 and 3002 memory address and store result into 3004 and 3006 memory address. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 60
  • 61. • Problem – Write an assembly language program in 8086 microprocessor to find average of n eight bit numbers 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 61
  • 62. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 62
  • 63. • Write 8086 Assembly language program to find the largest number in a given array, which is starts from memory offset 501. The size of the series is stored at memory offset 500. Store the largest number at memory offset 600. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 63
  • 64. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 64
  • 65. 5/25/2021 Kongunadu College of Engineering and Technology(Autonomous) 65