SlideShare a Scribd company logo
UNIT – 5
INTERFACING
MICROCONTROLLER
PROGRAMMING 8051 TIMERS
Mode 1 Programming
Operations of mode 1:
• 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.
• 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
TIMER FOR MODE 1
PROCEDURE
• 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.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
PROGRAM
UNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptx
Mode 2 Programming
Operations of Mode 2:
• 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).
UNIT 5 Interfacing and Mixed Signal Controller.pptx
PROCEDURE
• 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.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
COUNTER PROGRAMMING
• When C/T = 1, the timer is used as a counter and gets
its pulses from outside the 8051. The counter counts up
as pulses are fed from pins T0 (Timer 0 input) and T1
(Timer 1 input). These two pins belong to port 3. For
Timer 0, when C/T = 1 pin 3.4 provides the clock pulse
and counter counts up for each clock pulse coming
from that pin.
• Similarly for Timer 1, when C/T = 1 each clock pulse
coming in from pin 3.5 makes the counter countup.
P3.4 - T0 - Timer/Counter 0 external input
P3.5 - T1 - Timer/Counter 1 external input
• In counter mode, the TMOD, TH and TL registers are
the same as for the timer. Counter programming also
same as timer programming.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
SERIAL PORT PROGRAMMING
Programming the 8051 to transfer data
serially
• The TMOD register is loaded with the value
20H, indicating the use of Timer 1 in mode 2
(8 bit auto - reload) to set the baud rate.
• The TH 1 is loaded with one of the values in
Table to set the baud rate for serial data
transfer.
• The SCON register is loaded with the value 50
H, indicating serial mode 1, where 8-bit data is
framed with start and stop bits.
• TR 1 is set to start Timer 1.
• TI is cleared by the “CLR TI” instruction.
• The character byte to be transferred serially is
written into the SBUF registers.
• The TI flag bit is monitored with the use of the
instruction “JNB TI, XX ” to see if the
character has been transferred completely.
• To transfer next character, go to step 5.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
Programming the 8051 to receive data serially
• The first 4 steps are as same in programming
to transfer data serially.
• RI is cleared with “CLR RI “ instruction.
• The RI flag bit is monitored with the use of the
instruction “JNB RI, XX” to see if the
character has been received yet.
• When RI is raised, SBUF has the byte. Its
contents are moved into a safe place.
• To receive the next character, go to step 5.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
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 and 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.
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 tying
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.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
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.
KEYBOARD INTERFACING
• 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.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
• If any key is pressed, the columns are scanned
again and again until one of them has a 0 on it.
• After the key press detection, it waits 20 milli
seconds for the bounce and then scans the
columns again.
• After 20 ms delay, the key is still pressed, it goes
to detect which row it belongs to. To detect the
row it grounds one row at a time, reading the
columns each time.
• If all columns are high, the pressed key cannot
belong to that row. Therefore it grounds the next
row and continues until it finds the row the key
press belongs to.
• After finding the row, it sets up the starting
address for the look-up table holding the
ASCII codes for that row and goes to the next
stage to identify the key.
• Now it rotates the column bits, one bit at a
time into the carry flag and checks if it is low.
• When carry flag is zero, it pulls out the ASCII
code for that key from look-up table; otherwise
it increments the pointer to point to the next
element of the look-up table.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptx
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.
• 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.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
• There are two important registers are available inside the LCD. They
are (i) instruction command register, (ii) data register.
• 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.
• 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.
• If RS=0 and R/W = 0
When busy flag (D7)=1, the LCD is busy and will not accept any
new information.
• When busy flag (D7) = 0, the LCD is ready to receive new
information.
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 .
• 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.
• 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.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
The program presents the concept to monitor the
INTR pins and bring an analog input into
register A. Then call a hex - to - ASCII
conversion and data display subroutines
continuously.
• P2.6 = WR (start conversion needs to low - to -
high pulse)
• P2.7 = INTR, when low, end - of - conversion
• P2.5 = RD (a high-to-low will read the data
from ADC chip)
• P1.0 - P1.7 = D0 - D7 of ADC 804
UNIT 5 Interfacing and Mixed Signal Controller.pptx
DAC INTERFACING
• The digital - to - analog converter (DAC) is used
to convert digital pulses to analog signals.
The methods of creating a DAC are:
• Binary weighted
• R/2R ladder.
• Mostly R/2R method with DAC 0808 (MC 1408)
is used since it can achieve a much higher degree
of precision. Port 1 furnishes the digital byte to be
converted to an analog Voltage and port 3 controls
the conversion process.
• In DAC 0808, the digital inputs are converted to
current. The total courrent provided by the Iout pin
is a function of the binary numbers at the D0 – D7
inputs of DAC and the reference current Iref.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
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
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.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
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 data RAM interfacing
• To connect the 8051 to an external SRAM, we
must use both RD (P3.7) and WR (P3.6).
• In writing data to external data RAM, the
instruction “MOVX @DPTR, A” is used, where
the contents of register A are written to external
RAM whose address is pointed to by the DPTR
register.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptx
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. 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.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
WAVEFORM GENERATION:
• Steps to generate sine wave on 8051 microcontroller.
• Generate digital values of sine wave on a port that is 8 bit binary value.
• Convert that digital value into analog value to take that 8 bit output on 1
pin.
• Generated sine wave is in steps hence to obtain a pure sine wave, pass it
through low pass filter. Thus by remove high frequency part, obtain
smoother sine wave.
• First, generate digital values for sine wave. For this example take 16 points
in 1 cycle. Thus 1 value will hold for 1/16th of 360 degree. Hence use
sine(360 * (i/16)) where i runs from 0 to 15.
• This will cover 16 equally spaced points in one cycle. Place this cycle in
while (1) loop so that will get continuous sine wave.
• In a cycle of sine wave, half cycle is positive and remaining half cycle is
negative. Since microcontroller cannot have negative voltage, will shift
sine wave to half of maximum value.
• As maximum value is 255 for 8 bits, half of it is 127.5.Thus digital value to
be assigned to port is 127.5 + 127.5 * sine(360*(i/16)) where i runs from 0
to 15. Here minimum value is 127.5 - 127.5 = 0 and maximum value is
127.5 + 127.5 = 255
• Hence sine wave will be between 0 and 255 and which can be assigned to
port. Since most of the values will come in fraction, have to round figure to
assign integer value.
UNIT 5 Interfacing and Mixed Signal Controller.pptx
UNIT 5 Interfacing and Mixed Signal Controller.pptx
COMPARISON OF MICROPROCESSOR,
MICROCONTROLLER, PIC AND ARM
PROCESSORS
Microprocessor
• Microprocessor has only a CPU inside them in one or
few Integrated Circuits. Like microcontrollers it does
not have RAM, ROM and other peripherals. They are
dependent on external circuits of peripherals to work.
But microprocessors are not made for specific task but
they are required where tasks are complex and tricky
like development of software’s, games and other
applications that require high memory and where input
and output are not defined. It may be called heart of a
computer system. Some examples of microprocessor
are Pentium, I3, and I5 etc.
Microcontroller
• A micro-controller can be comparable to a little stand alone
computer; it is an extremely powerful device, which is able
of executing a series of pre-programmed tasks and
interacting with extra hardware devices. Being packed in a
tiny integrated circuit (IC) whose size and weight is
regularly negligible, it is becoming the perfect controller for
as robots or any machines required some type of intelligent
automation.
• A single microcontroller can be enough to manage a small
mobile robot, an automatic washer machine or a security
system. Several microcontrollers contains a memory to
store the program to be executed, and a lot of input/output
lines that can be a used to act jointly with other devices, like
reading the state of a sensor or controlling a motor.8051
microcontroller is an 8-bit family of microcontroller is
developed by the Intel in the year 1981.
PIC Microcontroller
• Peripheral Interface Controller (PIC) is microcontroller
developed by a Microchip, PIC microcontroller is fast and
simple to implement program when we contrast other
microcontrollers like 8051. The ease of programming and
simple to interfacing with other peripherals PIC become
successful microcontroller. Microcontroller is an integrated
chip which is consists of RAM, ROM, CPU, TIMER and
COUNTERS.
• The PIC is a microcontroller which as well consists of
RAM, ROM, CPU, timer, counter, ADC (analog to digital
converters), DAC (digital to analog converter). PIC
Microcontroller also support the protocols like CAN, SPI,
UART for an interfacing with additional peripherals. PIC
mostly used to modify Harvard architecture and also
supports RISC (Reduced Instruction Set Computer) by the
above requirement RISC and Harvard we can simply that
PIC is faster than the 8051 based controllers which is
prepared up of Von-Newman architecture.
ARM Processor
• An ARM processor is also one of a family of CPUs based
on the RISC (Reduced Instruction Set Computer)
architecture developed by Advanced RISC Machines
(ARM). An ARM makes at 32-bit and 64-bit RISC multi-
core processors. RISC processors are designed to perform a
smaller number of types of computer instructions so that
they can operate at a higher speed, performing extra
millions of instructions per second (MIPS).
• By stripping out unnecessary instructions and optimizing
pathways, RISC processors give outstanding performance at
a part of the power demand of CISC (complex instruction
set computing) procedure. ARM processors are widely used
in customer electronic devices such as smart phones,
tablets, multimedia players and other mobile devices, such
as wearables. Because of their reduced to instruction set,
they need fewer transistors, which enable a smaller die size
of the integrated circuitry(IC).

More Related Content

PDF
Unit 5
PDF
EC8691 - UNIT 5.pdf
PPTX
KTU_Microprocessor and Microcontrollers_Module2
PPTX
timer counter (1).pptx
PPTX
AVRTIMER.pptx
PPT
Microcontroller 8051 timer and counter module
PPTX
8051 training an interactive tutorial
PPTX
Module-03 Timers and serial port communication
Unit 5
EC8691 - UNIT 5.pdf
KTU_Microprocessor and Microcontrollers_Module2
timer counter (1).pptx
AVRTIMER.pptx
Microcontroller 8051 timer and counter module
8051 training an interactive tutorial
Module-03 Timers and serial port communication

Similar to UNIT 5 Interfacing and Mixed Signal Controller.pptx (20)

PPTX
UNIT V - INTERFACING MICROCONTROLLER (1).pptx
PPTX
26676.Instruction cycle_IO interrupt_computer description (1).pptx
PPT
8051e
PPTX
8051 MICROCONTROLLER TIMER AND ITS APPLICATIONS
PPTX
Digital Electronics Unit_4_new.pptx
PPT
Interrupt programming with 8051 microcontroller
PDF
8051 timers--2
PPTX
INTERFACING 8051-MICROCONTROLLER with timer and display
PPT
UNIT-5.ppt
PDF
8051 Timers, Interrupts and Serial Communication
PPTX
PDF
9 timer programming
PPTX
TIMERS.pptx
PPTX
visitor counter_POLICE_NEWT0N_789456.pptx
PDF
Timer And Counter in 8051 Microcontroller
PDF
PPT
Microcontroller 8051 introduction
PPT
Microcontroller Timer Counter Modules and applications
PPTX
Timer programming for 8051 using embedded c
PPT
8051 microcontroller timer summary presentation
UNIT V - INTERFACING MICROCONTROLLER (1).pptx
26676.Instruction cycle_IO interrupt_computer description (1).pptx
8051e
8051 MICROCONTROLLER TIMER AND ITS APPLICATIONS
Digital Electronics Unit_4_new.pptx
Interrupt programming with 8051 microcontroller
8051 timers--2
INTERFACING 8051-MICROCONTROLLER with timer and display
UNIT-5.ppt
8051 Timers, Interrupts and Serial Communication
9 timer programming
TIMERS.pptx
visitor counter_POLICE_NEWT0N_789456.pptx
Timer And Counter in 8051 Microcontroller
Microcontroller 8051 introduction
Microcontroller Timer Counter Modules and applications
Timer programming for 8051 using embedded c
8051 microcontroller timer summary presentation
Ad

Recently uploaded (20)

PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
communication and presentation skills 01
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
introduction to high performance computing
PPT
Occupational Health and Safety Management System
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
737-MAX_SRG.pdf student reference guides
PPTX
Current and future trends in Computer Vision.pptx
PPT
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPT
Total quality management ppt for engineering students
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPTX
Fundamentals of Mechanical Engineering.pptx
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
communication and presentation skills 01
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
introduction to high performance computing
Occupational Health and Safety Management System
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Exploratory_Data_Analysis_Fundamentals.pdf
737-MAX_SRG.pdf student reference guides
Current and future trends in Computer Vision.pptx
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
Visual Aids for Exploratory Data Analysis.pdf
Total quality management ppt for engineering students
Categorization of Factors Affecting Classification Algorithms Selection
UNIT 4 Total Quality Management .pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Fundamentals of Mechanical Engineering.pptx
Fundamentals of safety and accident prevention -final (1).pptx
Ad

UNIT 5 Interfacing and Mixed Signal Controller.pptx

  • 2. PROGRAMMING 8051 TIMERS Mode 1 Programming Operations of mode 1: • 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.
  • 3. • 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. • 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. PROCEDURE • 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.
  • 10. Mode 2 Programming Operations of Mode 2: • 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).
  • 12. PROCEDURE • 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.
  • 14. COUNTER PROGRAMMING • When C/T = 1, the timer is used as a counter and gets its pulses from outside the 8051. The counter counts up as pulses are fed from pins T0 (Timer 0 input) and T1 (Timer 1 input). These two pins belong to port 3. For Timer 0, when C/T = 1 pin 3.4 provides the clock pulse and counter counts up for each clock pulse coming from that pin. • Similarly for Timer 1, when C/T = 1 each clock pulse coming in from pin 3.5 makes the counter countup. P3.4 - T0 - Timer/Counter 0 external input P3.5 - T1 - Timer/Counter 1 external input • In counter mode, the TMOD, TH and TL registers are the same as for the timer. Counter programming also same as timer programming.
  • 16. SERIAL PORT PROGRAMMING Programming the 8051 to transfer data serially • The TMOD register is loaded with the value 20H, indicating the use of Timer 1 in mode 2 (8 bit auto - reload) to set the baud rate.
  • 17. • The TH 1 is loaded with one of the values in Table to set the baud rate for serial data transfer.
  • 18. • The SCON register is loaded with the value 50 H, indicating serial mode 1, where 8-bit data is framed with start and stop bits.
  • 19. • TR 1 is set to start Timer 1. • TI is cleared by the “CLR TI” instruction. • The character byte to be transferred serially is written into the SBUF registers. • The TI flag bit is monitored with the use of the instruction “JNB TI, XX ” to see if the character has been transferred completely. • To transfer next character, go to step 5.
  • 21. Programming the 8051 to receive data serially • The first 4 steps are as same in programming to transfer data serially. • RI is cleared with “CLR RI “ instruction. • The RI flag bit is monitored with the use of the instruction “JNB RI, XX” to see if the character has been received yet. • When RI is raised, SBUF has the byte. Its contents are moved into a safe place. • To receive the next character, go to step 5.
  • 23. 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 and 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.
  • 24. 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 tying 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.
  • 26. 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.
  • 27. KEYBOARD INTERFACING • 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.
  • 29. • If any key is pressed, the columns are scanned again and again until one of them has a 0 on it. • After the key press detection, it waits 20 milli seconds for the bounce and then scans the columns again. • After 20 ms delay, the key is still pressed, it goes to detect which row it belongs to. To detect the row it grounds one row at a time, reading the columns each time. • If all columns are high, the pressed key cannot belong to that row. Therefore it grounds the next row and continues until it finds the row the key press belongs to.
  • 30. • After finding the row, it sets up the starting address for the look-up table holding the ASCII codes for that row and goes to the next stage to identify the key. • Now it rotates the column bits, one bit at a time into the carry flag and checks if it is low. • When carry flag is zero, it pulls out the ASCII code for that key from look-up table; otherwise it increments the pointer to point to the next element of the look-up table.
  • 34. 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. • 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.
  • 36. • There are two important registers are available inside the LCD. They are (i) instruction command register, (ii) data register. • 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. • 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. • If RS=0 and R/W = 0 When busy flag (D7)=1, the LCD is busy and will not accept any new information. • When busy flag (D7) = 0, the LCD is ready to receive new information.
  • 37. 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 . • 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.
  • 38. • 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.
  • 40. The program presents the concept to monitor the INTR pins and bring an analog input into register A. Then call a hex - to - ASCII conversion and data display subroutines continuously. • P2.6 = WR (start conversion needs to low - to - high pulse) • P2.7 = INTR, when low, end - of - conversion • P2.5 = RD (a high-to-low will read the data from ADC chip) • P1.0 - P1.7 = D0 - D7 of ADC 804
  • 43. • The digital - to - analog converter (DAC) is used to convert digital pulses to analog signals. The methods of creating a DAC are: • Binary weighted • R/2R ladder. • Mostly R/2R method with DAC 0808 (MC 1408) is used since it can achieve a much higher degree of precision. Port 1 furnishes the digital byte to be converted to an analog Voltage and port 3 controls the conversion process. • In DAC 0808, the digital inputs are converted to current. The total courrent provided by the Iout pin is a function of the binary numbers at the D0 – D7 inputs of DAC and the reference current Iref.
  • 45. 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 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.
  • 47. 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 data RAM interfacing • To connect the 8051 to an external SRAM, we must use both RD (P3.7) and WR (P3.6). • In writing data to external data RAM, the instruction “MOVX @DPTR, A” is used, where the contents of register A are written to external RAM whose address is pointed to by the DPTR register.
  • 50. 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. 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.
  • 52. WAVEFORM GENERATION: • Steps to generate sine wave on 8051 microcontroller. • Generate digital values of sine wave on a port that is 8 bit binary value. • Convert that digital value into analog value to take that 8 bit output on 1 pin. • Generated sine wave is in steps hence to obtain a pure sine wave, pass it through low pass filter. Thus by remove high frequency part, obtain smoother sine wave. • First, generate digital values for sine wave. For this example take 16 points in 1 cycle. Thus 1 value will hold for 1/16th of 360 degree. Hence use sine(360 * (i/16)) where i runs from 0 to 15. • This will cover 16 equally spaced points in one cycle. Place this cycle in while (1) loop so that will get continuous sine wave. • In a cycle of sine wave, half cycle is positive and remaining half cycle is negative. Since microcontroller cannot have negative voltage, will shift sine wave to half of maximum value. • As maximum value is 255 for 8 bits, half of it is 127.5.Thus digital value to be assigned to port is 127.5 + 127.5 * sine(360*(i/16)) where i runs from 0 to 15. Here minimum value is 127.5 - 127.5 = 0 and maximum value is 127.5 + 127.5 = 255 • Hence sine wave will be between 0 and 255 and which can be assigned to port. Since most of the values will come in fraction, have to round figure to assign integer value.
  • 55. COMPARISON OF MICROPROCESSOR, MICROCONTROLLER, PIC AND ARM PROCESSORS Microprocessor • Microprocessor has only a CPU inside them in one or few Integrated Circuits. Like microcontrollers it does not have RAM, ROM and other peripherals. They are dependent on external circuits of peripherals to work. But microprocessors are not made for specific task but they are required where tasks are complex and tricky like development of software’s, games and other applications that require high memory and where input and output are not defined. It may be called heart of a computer system. Some examples of microprocessor are Pentium, I3, and I5 etc.
  • 56. Microcontroller • A micro-controller can be comparable to a little stand alone computer; it is an extremely powerful device, which is able of executing a series of pre-programmed tasks and interacting with extra hardware devices. Being packed in a tiny integrated circuit (IC) whose size and weight is regularly negligible, it is becoming the perfect controller for as robots or any machines required some type of intelligent automation. • A single microcontroller can be enough to manage a small mobile robot, an automatic washer machine or a security system. Several microcontrollers contains a memory to store the program to be executed, and a lot of input/output lines that can be a used to act jointly with other devices, like reading the state of a sensor or controlling a motor.8051 microcontroller is an 8-bit family of microcontroller is developed by the Intel in the year 1981.
  • 57. PIC Microcontroller • Peripheral Interface Controller (PIC) is microcontroller developed by a Microchip, PIC microcontroller is fast and simple to implement program when we contrast other microcontrollers like 8051. The ease of programming and simple to interfacing with other peripherals PIC become successful microcontroller. Microcontroller is an integrated chip which is consists of RAM, ROM, CPU, TIMER and COUNTERS. • The PIC is a microcontroller which as well consists of RAM, ROM, CPU, timer, counter, ADC (analog to digital converters), DAC (digital to analog converter). PIC Microcontroller also support the protocols like CAN, SPI, UART for an interfacing with additional peripherals. PIC mostly used to modify Harvard architecture and also supports RISC (Reduced Instruction Set Computer) by the above requirement RISC and Harvard we can simply that PIC is faster than the 8051 based controllers which is prepared up of Von-Newman architecture.
  • 58. ARM Processor • An ARM processor is also one of a family of CPUs based on the RISC (Reduced Instruction Set Computer) architecture developed by Advanced RISC Machines (ARM). An ARM makes at 32-bit and 64-bit RISC multi- core processors. RISC processors are designed to perform a smaller number of types of computer instructions so that they can operate at a higher speed, performing extra millions of instructions per second (MIPS). • By stripping out unnecessary instructions and optimizing pathways, RISC processors give outstanding performance at a part of the power demand of CISC (complex instruction set computing) procedure. ARM processors are widely used in customer electronic devices such as smart phones, tablets, multimedia players and other mobile devices, such as wearables. Because of their reduced to instruction set, they need fewer transistors, which enable a smaller die size of the integrated circuitry(IC).