MPMC PPT (R20)
MPMC PPT (R20)
(Autonomous)
(Approved by AICTE, New Delhi & Affiliated to JNTUA, Anantapuramu)
(NAAC Accredited Institution with ‘A’ Grade)
SIDDHARTH NAGAR, NARAYANAVANAM ROAD, PUTTUR – 517 583
CHITTOOR DIST., A.P., INDIA
🠶 Functions
🠶 General purpose, special purpose such image processing,
floating point c alc ulations
🠶 And more …
computer languages
Generally there are three types of computer languages I. Machine
Level Language II.Assembly Level language III. High Level Language
Machine Level Language: Machine language is the language understood by a
computer. It is very difficult to understand, but it is the only thing that the computer can work with.
All programs and programming languages eventually generate or run programs in machine
language. Machine language is made up of instructions and data that are all binary numbers
II)Assembly level language: Assembly language is almost the same as machine language,
except that the instructions, variables and addresses have names instead of just hex numbers. it acts
as the intermediate language between machine language and high-level programming languages.
III)High Level Language n comparison to machine language, assembly language is
easier to write and use; A high-level language (HLL) is a programming language such as
C, FORTRAN, or Pascal that enables a programmer to write
CLASSIFICATION OF COMPUTERS FROM
LARGE COMPUTERS TO SINGLE CHIP
MICROCONTROLLERS: Computers are classified into mainly three types
i)Large Computers
ii). Medium size Computers
iii). Microcomputers
i)Large computers Large computers are multipurpose, multiuser,
multitasking computers. These are used in computer scientific and
engineering calculations, handle large records for large corporations and
government agencies.
Large computers are two types
1) Main frames and
2) Super computers
Main frames A mainframe computer (as storage for large database and serve as
maximum number of users simultaneously) is a computer used primarily by large
organizations for critical applications, bulk data processing such as the census
and industry and consumer statistics, enterprise resource planning, and large-
scale transaction processing
Super computers Super computers (large and complex mathematical Computations)are
fastest high-performance systems available at any given time. Such computers have
been used primarily for scientific and engineering work requiring exceedingly high-
speed computations.
ii)Medium size computers
(Minicomputers support more than 100 users at a time with multi terminal and
time sharing) Medium-size computer systems provide faster operating speeds
and larger storage capacities than minicomputer systems. They can support a
large number of high-speed input/output devices and several disk drives can be
used to provide online access to large data files as required for direct access
processing and their operating systems also support both multiprogramming
and virtual storage.
iii)Microcomputers A microcomputer is a complete computer on a small scale,
designed for use by one person at a time. microcomputer is now primarily called
a personal computer (PC), or a device based on a single-chip microprocessor.
Common microcomputers include laptops and desktops.
PERSONAL COMPUTERS (PC)
These microcomputers are single-user systems and are used for a variety of
purposes, such as payroll, business accounts, word processing, legal and medical
record keeping, personal finance, accessing Internet resources (e-mail. Web
search, newsgroup), and instruction. They are also known as personal computers
(PC) or desktop computers.
Typically, the price ranges from $500 to $5000 for a single-user system. Examples
include such microcomput- ers as the IBM Personal Computer (Aptiva series),
the Hewlett-Packard Pavilion series, and the Apple Macintosh series. At the low
end of the microcomputer spectrum, a typical configuration includes a 32- bit
(or 64- bit) microprocessor, 32 to 256 MB (megabytes) of system memory, a
video screen (monitor), a 3" high-density floppy disk, a hard disk with storage
capacity of more than 10 gigabytes, a CDROM, and a Zip disk.
SINGLE-BOARD MICROCOMPUTERS
These microcomputers are primarily used in college
laboratories and industries for instructional purposes
or to evaluate the performance of a given
microprocessor. They can also be part of some larger
systems. Typically, these microcomputers include an 8
or 16-bit microprocessor, from 256 bytes to 8K bytes of
ser memory, a Hes keyboard, and seven-segment LEDs
as display. The interaction between the
microprocessor, memory, and I/Os in these small
systems is looked after by a program called a system
monitor program, which is generally small in size,
stored in less than 2K bytes of ROM.
SINGLE-CHIP MICROCOMPUTERS
(MICROCONTROLLERS)
These microcomputers are designed on a single chip,
which typically includes a micro- processor, 256 bytes
of R/W memory, from IK to 8K bytes of ROM, and
several signal limes to connect I/Os. These are
complete microcomputers on a chip: they are also
known as microcontrollers. They are used primarily
for such functions as controlling appliances and traffic
lights. Typical examples of these microcomputers
include such chips as the Zilog 28. Intel MCS 51 series,
Motorola 68HC11, and the Microchip Technology PIC
family.
APPLICATION: MICROPROCESSOR
CONTROLLED TEMPERATURE SYSTEM
MICROPROCESSOR ARCHITECTURE
AND ITS OPERATION
1)Microprocessor-initiated operations
2) Internal operations
3) Peripheral (or externally initiated) operations
Microprocessor-Initiated Operations and 8085 Organization The MPU
performs primarily four operations
1. Memory Read: Reads data (or instructions) from memory
2. Memory Write: Writes data (or instructions) into memory.
3. I/O Read: Accepts data from input devices.
4. I/O Write: Sends data to output devices.
All these operations are part of the communication process between the
MPU and peripheral devices (including memory). To communicate with
a peripheral (or a memory location), the MPU needs to perform the
following steps:
Step 1: Identify the peripheral or the memory location (with its address).
Step 2: Transfer binary information (data and instructions).
Step 3: Provide timing or synchronization signals.
ADDRESS BUS
The address bus is a group of 16 lines generally identified as A15 to A0. The
address bus is unidirectional: hits flow in one direction-from the MPU to
peripheral devices. The MPU uses the address bus to perform the first function:
identifying a peripheral or a memory location (Step 1). In a computer system,
each peripheral or memory location is identified by a binary called an address,
and the address bus is used to carry a 16-bit address.
DATA BUS
The data bus is a group of eight lines used for data flow (Figure 5). These lines are bidirectional data
flow in both directions between the MPU and memory and peripheral devices. The MPU uses the
data bus to perform the second function: transferring binary information (Step 2). The eight data
lines enable the MPU to manipulate 8 bit data ranging from 00 to FF (28=256 numbers). The largest
number that can appear on the data bus is 11111111 (25510) The 8085 is known as an 8-bit
microprocessor Microprocessors such as the Intel 8086, Zilog Z8000, and Motorola 68000 have 16
data lines; thus they are known as 16- bit microprocessors. The Intel 80386/486 have 32 data lines;
thus they are classified as 32-bit microprocessor
CONTROL BUS
The control bus is comprised of various single lines that carry synchronization
signals. The MPU uses such lines to perform the third function: providing
timing signals (Step 3). The term bus, in relation to the control signals, is
somewhat confusing. These are not groups of lines like address or data buses,
but individual lines that provide a pulse to indicate an MPU operation. The
MPU generates specific control signals for every operation (such as Memory
Read or I/O Write) it performs.
Memory Read Operation
Internal Data Operations and the
8085 Registers
The internal architecture of the 8085 uP determines
how and what operations can be performed with the
data..
These operations are: 1. Store 8-bit
2. Perform arithmetic and logical operations
3. Test for conditions
4. Sequence the execution of instructions
5. Store data temporarily during execution in the
defined R/W memory location called the stack
Peripheral or Externally Initiated
Operations
External devices (or signals) can initiate the following
operations, for which individual pins on the
microprocessor chip are assigned: Reset, Interrupt. Ready,
Hold. Reset: When the reset pin is activated by an external
key (also called a reset key), all internal operations are
suspended and the program counter is cleared (it holds
0000H) Now the program execution can again begin at the
zero memory address. The microprocessor can be
interrupted from the normal execution of instructions and
asked to execute some other instructions called a service
routine (for example, emergency procedures). The
microprocessor resumes its operation after completing the
service routine.
Four latches as 4-bit Register
calculation of Memory Address Lines
In the last two examples, the address lines of the memory
chips were given. The number of address lines necessary for
a given chip can be obtained from data sheets. However, we
need to know the relationship between the number of
registers in a memory chip and the number of address
lines. For a chip with 256 registers, we need 256 binary
numbers to identify each register. Each address line can
assume only two logic states (0 and 1); therefore, we need
to find the power of 2 that will give us 256 combinations.
The problem can be restated as follows: Find where 2256.
By taking the log of both sides, we get: log 2^x = log 256 ->
x log 2 = log 256 x = log 256/log 2 = 8
Memory Classification
INPUT AND OUTPUT (I/O) DEVICES
Input Device:
Input devices are used for feeding data into the
CPU, examples of these devices are toggle switches,
analog-to-digital converters, paper tape readers, card
readers, keyboards, disk etc.
Output Device
The output devices are used for delivering the results of
computations to the outside world; examples are light emitting
diodes, cathode ray tube (CRT) displays, digital-to-analog
converters, card and paper-tape punches, character printers,
plotters, communication lines etc.
Output devices
EXAMPLE OF A MICROCOMPUTER SYSTEM
On the basis of the discussion in the previous sections, we can expand the
microcomputer system shown in Figure 1 to include additional details. Figure 12
illustrates such a system. It shows the 8085 MPU, two types of memory (EPROM
and R/WM), input and output, and the buses linking all peripherals (memory and
I/Os) to the MPU.
References
https://www.youtube.com/watch?v=oNKqRPv8c9M
https://www.youtube.com/watch?v=eG3Vg_EZTYk
https://www.slideshare.net/Johnrebel999/microcontroller-8051-
22899728
https://www.youtube.com/watch?v=te5Xe3TgPC4(addition of two numbers
with animation)
https://what-when-how.com/8051-microcontroller/assembling-and-running-
an-8051-program/
Siddartha Institute of Science and Technology
(Autonomous)
(Approved by AICTE, New Delhi & Affiliated to JNTUA, Anantapuramu)
(NAAC Accredited Institution with ‘A’ Grade)
SIDDHARTH NAGAR, NARAYANAVANAM ROAD, PUTTUR – 517 583
CHITTOOR DIST., A.P., INDIA
ADDRESS BUS: The 8085 has 16 signal lines (pins) that are used as the
address bus; however, these lines are split into two segments: A15-A8,
and AD7-AD,0 The eight signal lines, A15-A8, a unidirectional and used
for the most significant bits, called the high-order address of a 16-bit
address. The signal lines AD7-AD0, are used for a dual purpose, as
explained in the next section
MULTIPLEXED ADDRESS/DATA BUS: The signal lines AD7-AD0, are
bidirectional: they serve a dual purpose. They are used as the loworder
address bus as well as the data bus. In executing an instruction, during
the earlier part of the cycle, these lines are used as the low-order
address bus.
PIN DIAGRAM
SIGNALS
This group of signals includes two control signals (RD’ and WR’), three status
signals (1O/M’, S1. and S0 to identify the nature of the operation, and one
special signal (ALE) to indicate the beginning of the operation. These signals
are as follows:
1) ALE-Address Latch Enable: This is a positive going pulse generated every
time the 8085 begins an operation (machine cycle); it indicates that the bits
on AD7-AD0, are address bits. This signal is used primarily to latch the low-
order address from the multiplexed bus and generate a separate set of eight
address lines, A7-A0.
2) RD’-Read: This is a Read control signal (active low). This signal indicates
that the selected 1/O or memory device is to be read and data are available on
the data bus.
3) WR’-Write: This is a Write control signal (active low). This signal indicates
that the data on the data bus are to be written into a selected memory or I/O
location.
4) IO/M’: This is a status signal used to differentiate between I/O and memory
operations. When it is high, it indicates an I/O operation; when it is low, it
indicates a memory operation. This signal is combined with RD’ (Read) and
WR’ (Write) to generate I/O and memory control signals
EXTERNALLY INITIATED SIGNALS, INCLUDING
INTERRUPTS
The 8085 has five interrupt signals that can be used to interrupt a program execution. One of the
signals. INTR (Interrupt Request), is identical to the 8080A microprocessor interrupt signal (INT);
the others are enhancements to the 8080A. The microprocessor acknowledges an interrupt request
by the INTA (Interrupt Acknowledge) signal. In addition to the interrupts, three pins-RESET.
HOLD, and READY-accept the externally initiated signals as inputs. To respond to the HOLD
request, the 8085 has one signal called HLDA (Hold Acknowledge).
RESET IN: When the signal on this pin goes low, the program counter is set to zero, the buses are
tristated, and the MPU is reset.
RESET OUT: This signal indicates that the MPU is being reset. The signal can be used to reset other
devices.
8085 Interrupts and Externally initiated Signals
INTR (Input); Interrupt Request: This is used as a general-purpose interrupt. it is similar to the INT
signal of the 8080A.
INTA’ (Output) :Interrupt Acknowledge: This is used to acknowledge an interrupt.
RST 7.5 (Inputs)RST6.5, RST5.5 : Restart Interrupts: These are vectored interrupts that transfer the
program control to specific memory locations. They have higher priorities than the INTR interrupt.
Among these three, the priority order is 7.5. 6.5, and 5.5.
HOLD (Input): This signal indicates that a peripheral such as a DMA (Direct Memory Access)
controller is requesting the use of the address and data buses.
HLDA (Output): Hold Acknowledge: This signal acknowledges the HOLD request.
READY (Input): This signal is used to delay the microprocessor Read or Write cycles until a slow
responding peripheral is ready to send or accept data. When this signal goes low, the
microprocessor waits for an integral number of clock cycles until it goes high.
MICROPROCESSOR COMMUNICATION AND
BUS TIMING
1. A courier gets the address from the office; he or she
drives the pickup van, finds the street, and looks for
your house number.
2. The courier rings the bell.
3. Somebody in the house opens the door and gives the
package to the courier, and the courier returns to the
office with the package.
4. The internal office staff disposes the package
according to the instructions given by the customer
Now let us examine the steps in the following example
of how the microprocessor fetches or gets a machine
code from memory.
Data Flow from Memory to the MPU
Timing: transfer byte from memory to MPU
DEMULTIPLEXING THE BUS AD7-AD0
Schematic to Generate Read/Write
Control Signals for meory and I/O
There are four different control signals
are generated by combining the signals
RD’, WR’, and IO/M’. The signal IO/M’
goes low for the memory operation.
This signal is ANDed with RD and WR
signals by using the 74LS32 quadruple
two-input OR gates, as shown in Figure
The OR gates are functionally
connected as negative NAND gates.
When both input signals go low, the
outputs of the gates go low and
generate MEMR’ (Memory Read) and
MEMW’ (Memory Write) control
signals. When the IO/M’ signal goes
high, it indicates the peripheral I/O
operation. Figure 5 shows that this
signal is complemented using the Hex
inverter 74LS04 and ANDed with the
RD’ and WR’ signals to generate IOR
(I/O Read) and IOW (I/O Write)
control signals.
The 8085A Microprocessor: Functional Block Diagram
TIMING AND CONTROL UNIT This unit synchronizes all the microprocessor operations
with the clock and generates the control signals necessary for communication between the
microprocessor and peripherals. The control signals are similar to a sync pulse in an
oscilloscope. The RD’ and WR’ signals are sync pulses indicating the availability of data on
the data bus.
INSTRUCTION REGISTER AND DECODER The instruction register and the decoder are
part of the ALU. When an instruction is fetched from memory, it is loaded in the
instruction register. The decoder decodes the instruction and establishes the sequence of
events to follow. The instruction register is not programmable and cannot be accessed
through any instruction
REGISTER ARRAY The programmable registers are used to store the data temporarily.
Two additional registers, called temporary registers W and Z, are included in the register
array. These registers are used to hold 8-bit data during the execution of some
instructions. However, because they are used internally, they are not available to the
programmer.
Decoding and Executing an Instruction Decoding and executing an instruction after it
has been fetched can be illustrated with the example Example: Assume that the accumulator
contains data byte 82H, and the instruction MOV C, A (4FH) is List the steps in decoding
and executing the instruction. To decode and execute the instruction, the following steps
are performed
Instruction Decoding and
Execution
Data Format of 8085 Microprocessor:
The operand is an another name for data. It may appear in different forms :
Addresses
Numbers/Logical data and
Characters
Addresses : The address is a 16-bit unsigned integer ,number used to refer a
memory location.
Numbers/Data : The 8085 supports following numeric data types.
• Signed Integer : A signed integer number is either a positive number or a
negative number. In 8085, 8-bits are assigned for signed integer, in which
most significant bit is used for sign and remaining seven bits are used for
Sign bit 0 indicates positive number whereas sign bit 1 indicates negative
number.
• Unsigned Integer : The 8085 microprocessor supports 8-bit unsigned
integer.
• BCD : The term BCD number stands for binary coded decimal number. It
uses ten digits from 0 through 9. The 8-bit register of 8085 can store two
digit BCD
Characters : The 8085 uses ASCII code to represent characters. It is a 7-bit
alphanumeric code that represents decimal numbers, English alphabets, and
other special characters.
DATA STORAGE: For storing data and Instructions Data
storage known as memory are used with microprocessor.
Memory is a storage of binary bits. Memory chips used in
most systems are 8-bit registers stacked one above the
other. It includes four registers and each register can store
8 bits. This chip can be referred to as a 4-byte or 32 bit
(4X8 ) bits memory chip. It has two address lines A0 and
A1 to identify four registers, 8 data lines to store 8 bits and
three timing control signals: Read (RD’), Write (WR’) and
Chip select (CS’): all control signals are designed to be
active low. The processor can select this chip and identify
its register and store (write) or access (read) 8 bit at a
time.The memory addresses assigned to these registers are
determined by the interfacing logic used in the system.
OVERVIEW OF THE 8085 INSTRUCTION SET
The 8085 microprocessor instruction set has 74
operation codes that result in 246 in- structions.
The set includes all the 8080A instructions plus two
additional instructions (SIM and RIM, related to serial
I/O). It is an overwhelming experience for a beginner
to study these instructions. You are strongly advised
not to attempt to read all these instructions at one
time. However, you should be able to grasp an
overview of the set by examining the frequently used
instructions listed below The following notations are
used in the description of the instructions
Data Transfer (Copy) Instructions:
These instructions perform the following six
operations.
(i) Load an 8-bit number in a register
(ii) Copy from register to register
(iii) Copy between I/O and accumulator
(iv) Load 16-bit number in a register pair
(v) Copy between register and memory
(vi) Copy between registers and stack memory
Summary – Data transfer
MOV Move
MVI Move Immediate
LDA Load Accumulator Directly from Memory
STA Store Accumulator Directly in Memory
LHLD Load H & L Registers Directly from
Memory
SHLD Store H & L Registers Directly in Memory
UNIT-III
The 8051 Microcontroller Architecture
SUBJECT: MICROPROCESSORS AND MICROCONTROLLERS
Academic Year-2022-23
Year/Semester-III/I
HDr. Savitesh M. Sharma
Mr Thyagarajan Prasad
COURSE OBJECTIVES
The 8051 contains two 16-bit registers: the program counter (PC) and the data pointer (DPTR). Each is used to
hold the address of a byte in memory.
Program instruction bytes are fetched from locations in memory that are addressed by the PC. Program ROM
may be on the chip at addresses 0000h to OFFFh, external to the chip for addresses that exceed 0FFFh, or
totally external for all addresses from 0000h to FFFFh. The PC is automatically incremented after every
instruction byte is fetched and may also be altered by certain instructions. The PC is the only register that does
not have an internal address
Flags and the Program Status Word (PSW)
Flags are 1-bit registers provided to store the results of certain program instructions. Other instructions can test
the condition of the flags and make decisions based upon the flag states. In order that the flags may be
conveniently addressed, they are grouped inside the program status word (PSW) and the power control (PCON)
registers.
INTERNAL MEMORY
A functioning computer must have memory for program code bytes, commonly in ROM, and RAM
memory for variable data that can be altered as the program runs. The 8051 has internal RAM and
ROM memory for these functions. Additional memory can be added externally using suitable circuits.
INTERNAL RAM
The 128-byte internal RAM, which is shown generally in Figure 1 and in detail in Figure 5, is
organized into three distinct areas:
1. Thirty-two bytes from address 00h to 1 Fh that make up 32 working registers organized as four
banks of eight registers each. The four register banks are numbered 0 to 3 and are made up of eight
registers named R0 to R 7. Each register can be addressed by name (when its bank is selected) or by
its RAM address. Thus R0 of bank 3 is R0 (if bank 3 is currently selected) or address 18h (whether
bank 3 is selected or not). Bits RS0 and RS 1 in the PSW determine which bank of registers is
currently in use at any time when the program is running. Register banks not selected can be used as
general-purpose RAM. Bank 0 is selected upon reset.
THE STACK AND THE STACK POINTER
The system designer is not limited by the amount of internal RAM and ROM available on chip. Two separate
external memory spaces are made available by the 16-bit PC and DPTR and by different control pins for
enabling external ROM and RAM chips. Internal control circuitry accesses the correct physical memory,
depending upon the machine cycle state and the op code being executed.
There are several reasons for adding external memory, particularly program memory, when applying the 8051 in
a system. When the project is in the prototype stage, the expense—in time and money—of having a masked
internal ROM made for each program "try" is prohibitive.
CONNECTING EXTERNAL MEMORY
COUNTER AND TIMERS
it is a device that counts down from a specified time interval and used to generate a time delay, for example, an
hourglass is a timer. a counter is a device that stores (and sometimes displays) the number of times a particular
event or process occurred, with respect to a clock signal.
C/T: (Counter/Timer)
•Set (1) - Acts as Counter (Counts external frequency on T1 and T0
pin inputs).
•Cleared (0) - Acts as Timer (Counts internal clock frequency,
fosc/12).
Gate: (Gate Enable Control bit)
•Set (1) - Timer controlled by hardware i.e. INTX signal.
•Cleared (0) – Counting independent of INTX signal.
M1, M0: (Mode Selection bits)
Computers must be able to communicate with other computers in modern multiprocessor distributed
systems. One cost-effective way to communicate is to send and receive data bits serially. The 8051 has a
serial data communication circuit that uses register SBUF to hold data. Register SCON controls data
communication, register PCON controls data rates, and pins RXD (P3.0) and TXD (P3.1) connect to the
serial data network.
SBUf is physically two registers. One is write only and is used to hold data to be transmitted out of the
8051 via TXD. The other is read only and holds received data from external sources via RXD. Both
mutually exclusive registers use address 99h.
There are four programmable modes for serial data communication that are chosen by setting the SMX
bits in SCON. Baud rates are determined by the mode chosen. Figure 13 shows the bit assignments for
SCON and PCON.
Serial Data Interrupts
Serial data communication is a relatively slow process, occupying many milliseconds per data byte to
accomplish. In order not to tie up valuable processor time, serial data flags are
THE SERIAL PORT CONTROL (SCON) SPECIAL FUNCTION REGISTER
0 IDL Idle mode bit. Set to 1 by program to enter idle mode configuration for CHMOS
processors. PCON is not bit addressable.
DATA TRANSMISSION
Transmission of serial data bits begins anytime data is written to SBUF. T1 is set to a 1 when the data has been
transmitted and signifies that SBUF is empty (for transmission purposes) and that another data byte can be sent.
If the program fails to wait for the T1 flag and overwrites SBUF while a previous data byte is in the process of
being transmitted, the results will be unpredictable (a polite term for "garbage out").
DATA RECEPTION
Reception of serial data will begin if the receive enable bit (REN) in SCON is set to 1 for all modes. In addition,
for mode 0 only, R1 must be cleared to 0 also. Receiver interrupt flag R1 is set after data has been received in all
modes. Setting REN is the only direct program control that limits the reception of unexpected data; the
requirement that R1 also be 0 for mode 0 prevents the reception of new data until the program has dealt with the
old data and reset R1.
SERIAL DATA TRANSMISSION MODES
The 8051 designers have included four modes of serial data transmission that enable data communication to be done
in a variety of ways and a multitude of baud rates. Modes are selected by the programmer by setting the mode bits
SM0 and SM1 in SCON. Baud rates are fixed for mode 0 and variable, using timer 1 and the serial baud rate modify
bit (SMOD) in PCON, for modes 1. 2. and 3.
SERIAL DATA MODE 0-SHIFT REGISTER MODE
Setting bits SM0 and SM 1 in SCON to 00b configures SBUF to receive or transmit eight data bits using pin
RXD for both functions. Pin TXD is connected to the internal shift frequency pulse source to supply shift pulses
to external circuits. The shift frequency, or baud rate, is fixed at 1/12 of the oscillator frequency, the same rate
used by the timers when in the timer configuration. The TXD shift clock is a square wave that is low for machine
cycle states S3-S4-S5 and high for S6-S1-S2. Figure 14 shows the timing for mode 0 shift register data
transmission.
INTERRUPTS
Interrupts are the events that temporarily suspend the main program, pass the control to other functions or
sources and execute their task. It then passes the control to the main program where it had left off.
As code size increases and your application handles multiple modules, sequential coding would be too long and
too complex. The interrupt mechanism helps to embed your software with hardware in a much simpler and
efficient manner. In this topic, we will discuss the interrupts in 8051 using AT89S52 microcontroller.
TIMER FLAG INTERRUPTS
Each Timer is associated with a Timer interrupt. When a timer has finished counting, the Timer interrupt will
notify the microcontroller by setting the required flag bit
EXTERNAL INTERRUPTS
8051 based AT89S52 microcontroller has two active-low external interrupts, INT0 and INT1.
See more information here: EXTERNAL INTERRUPT IN 8051 MICROCONTROLLER.
IE register (Interrupt Enable Register)
A reset can be considered to be the ultimate interrupts because the program may not block the action of the
voltage on the RST pin, this type of interrupt is often called non maskable ,because no combination of bit in any
register can stop or mask the reset action .unlike other interrupts the PC is not stored for later program
resumption .
INTERRUPT CONTROL
The program must be able at critical times to inhibit the action
of some or all of the interrupts so that crucial operational can be
finished. the IE register hold s the programmable bit that can
enable or disable all the interrupts as a group or if the group is
enabled each individual interrupt source can be enabled or
disabled
INTERRUPT ENABLE/DISABLE
Bits in the IE register are set to 1 if the corresponding interrupt
source is to be enabled and set to 0 to disable the interrupt
source. bit EA is a master or global bit that can enable or
disable all of the interrupts
INTERRUPT PRIORITY
Register IP bits determine if any interrupt is to have a hight or low priority, bits set to 1 give the accompanying
interrupt a high priority a 0 assigns a low priority. 0 assigns low priority.
IE0
TF0
1E1
TF1
SERIAL=RI OR TI
INTERRUPT DESTINATIONS
each interrupt source causes the program to do a hardware call to one of the dedicated addresses in program
memory it is the responsibility of the program to place a routine at the address that will service the interrupt.
References
TEXT BOOKS
1. Ramesh Gaonkar, Microprocessor Architecture, programming and applications with
the 8085, Penram International Publications Pvt Ltd. 6th Edition, 2015.
2.Kenneth J Ayala, The 8051 microcontroller, Penram International Publications Pvt Ltd,
2 nd Edition, 1997
REFERENCES
1. Ray Bhurchandi, Advanced Microprocessors & Peripheral interfacing, MC graw hill
Publications, 3 rd edition, 2012.
2. N.Senthil Kumar, M.Saravanan, S.Jeevanathan, Microprocessor and Microcontrollers,
Oxford Publishers. 1 st Edition, 2015.
References web sites
https://www.rcet.org.in/uploads/academics/rohini_50793
462648.pdf
https://www.slideshare.net/hello_priti/architecture-of-
8051
https://www.slideshare.net/thokalpv/8051-
microcontroller-213214599
https://slideplayer.com/slide/5975625/
https://slideplayer.com/slide/5740917/
92
Siddartha Institute of Science and Technology
(Autonomous)
(Approved by AICTE, New Delhi & Affiliated to JNTUA, Anantapuramu)
(NAAC Accredited Institution with ‘A’ Grade)
SIDDHARTH NAGAR, NARAYANAVANAM ROAD, PUTTUR – 517 583
CHITTOOR DIST., A.P., INDIA
UNIT-1V
PROGRAMMING THE 8051
SUBJECT: MICROPROCESSORS AND MICROCONTROLLERS
Academic Year-2022-23
Year/Semester-III/I
HDr. Savitesh M. Sharma
Mr Thyagarajan Prasad
COURSE OBJECTIVES
• JMP address – This instruction moves the execution of the program to the
specified address.
• LXI H 3000 – This instruction transfers the data, that is, 3000, to the H-L pair
register.
Register addressing mode
In this addressing mode, the instruction mentions a register which stores some data.
The operation specified by the instruction is performed in the register specified by it.
The instruction can also specify two registers. The size of the instructions in register
addressing mode is 1 byte. The instruction’s opcode includes both the register and
the operation to be performed. Examples of instructions that use register addressing
mode are:
• ADD B – This instruction adds the data within register B with the data in the
accumulator and stores the result in the accumulator.
• INR B – This instruction increases the data stored in register B by 1.
• MOVE B, D – This instruction moves the content of register D to register B.
• PCHL – This instruction transfers the contents stored in the HL pair to the program
counter.
Direct addressing mode
In this addressing mode, the instruction specifies some address which stores the
data. This memory location is mentioned in the instruction as an operand. The size
of an instruction in the direct addressing mode is 3 bytes. However, input/output
instructions in direct addressing mode are 2 bytes. Examples of instructions that use
direct addressing mode are:
• IN 35 – This instruction reads the data from a port. The address of the port is 35.
• LHLD address – This instruction loads the data stored in the memory location
specified by ‘address’ into the HL pair.
LDA 2050 – This instruction stores the contents of the memory location 2050H into
the accumulator
STA 2050 – This instruction stores the contents of the accumulator in the memory
location 2050H.
Register Indirect addressing mode
In this addressing mode, the operand is described implicitly in the definition of the
instruction. The operand is specified with the opcode of the instruction. The size of
an implied addressing mode instruction is 1 byte. The instructions generally operate
on data stored in the accumulator. Examples of instructions that use implied
addressing mode are as follows:
• RRC – This instruction rotates the contents of the accumulator to the right by one
bit.
• RLC – This instruction rotates the contents of the accumulator to the left by one
bit.
• CMA – This instruction complements the content stored in the accumulator. The
result is then stored in the accumulator itself.
EXTERNAL DATA MOVES
It is possible to expand RAM and Rom memory space by adding external memory
chips to the 8051 microcontroller the external memory can be as large as 64k for
each of the RAM &ROM memory areas. opcodes that access this external memory
always use indirect addressing to specify the external memory
Code memory read-only data moves
Data moves between RAM locations and 8051 registers are made by using MOV
and MOVX opcodes. The data is usually of a temporary or "scratch pad" nature and
disappears when the system is powered down.
There are times when access to a preprogrammed mass of data is needed, such as
when using tables of predefined bytes. This data must be permanent to be of
repeated use and is stored in the program ROM using assembler directives that store
programmed data anywhere in ROM that the programmer wishes.
Mnemonic Operation
MOVC A,@A+DPTR Copy the code byte, found at the ROM address formed by adding A and the DPTR,
to A
MOVC A,@A+PC Copy the code byte, found at the ROM address formed by adding A and the PC, to
A
PUSH AND POP OPCODE
The PUSH and POP opcodes specify the direct address of the data. The data
moves between an area of internal RAM, known as the stack, and the specified
direct address. The stack pointer special-function register (SP) contains the
address in RAM where data from the source address will be PUSHED, or where
data to be POPED to the destination address is found. The SP register actually is
used in the indirect addressing mode but is not named in the mnemonic. It is
implied that the SP holds the indirect address whenever PUSHING or POPING.
Figure 3.3 shows the operation of the stack pointer as data is PUSHED or
POPED to the stack
Mnemo area in internal RAM.
Operation Mnemonic Operation
nic MOV 81h,#30h Copy the immediate data 30h to the SP
PUSH Increment SP; copy the data in add to the MOV R0, #0ACh Copy the immediate data ACh to R0
PUSH 00h SP = 31h; address 31h contains the number
add internal RAM address contained in SP
ACh
POP addCopy the data from the internal RAM PUSH 00h SP = 32h; address 32h contains the number
address contained in SP to add; decrement ACh
the sp POP 0lh SP = 31 h; register R 1 now contains the
number Ach
POP 80h SP = 30h; port 0 latch now contains the
number ACh
Exchanges between A and any port location copy the data on the port pins to A,
EXCHANGEOPCODES
while the data in A is copied to the port latch. Register A is used for so many
instructions that the XCH opcode provides a very convenient way to "save" the
contents of A without the necessity of using a PUSH opcode and then a POP
opcode.Mnemonic Operation
Mnemonic Operation
Mnemonic Operation
Rotate a byte to the left; the Most Significant Bit (MSB) becomes the Least Significant Bit (LSB)
RL
Rotate a byte and the carry bit left; the carry becomes the LSB, the MSB becomes the carry
RLC
ANL A,@Rp AND each bit of A with the direct RAM address; put the results in the direct RAM address
ANL add.A AND each bit of the RAM address with the same bit in the number n; put the result in the RAM address
ANL add,#n OR each bit of A with the same bit of n; put the results in A
ORL A,#n OR each bit of A with the same bit of the direct RAM address; put the results in A
ORL A,add OR each bit of A with the same bit of register Rr; put the results in A OR each bit of A with the same bit of the contents of the RAM address
contained in Rp; put the results in A
ORL A,Rr OR each bit of A with the direct RAM address; put the results in the direct RAM address
ORL A,@Rp OR each bit of the RAM address with the same bit in the number n; put the result in the RAM address
ORL add.A XOR each bit of A with the same bit of n; put the results in A
ORL add,#n XOR each bit of A with the same bit of the direct RAM address; put the results in A
XRL A,#n XOR each bit of A with the same bit of register Rr; put the results in A XOR each bit of A with the same bit of the contents of the RAM address
contained in Rp; put the results in A
XRL A,add XOR each bit of A with the direct RAM address; put the results in the direct RAM address
Certain internal RAM and SFRs can be addressed by their byte addresses or by the
address of each bit within a byte. Bit addressing is very convenient when you wish
to alter a single bit of a byte, in a control register for instance, without having to
wonder what you need to do to avoid altering some other crucial bit of the same
byte. The assembler can also equate bit addresses to labels that make the program
more readable. For example, bit 4 of TCON can become TR0, a label for the timer 0
run bit.
Internal RAM Bit Addresses
The availability of individual bit addresses in internal RAM makes the use of the
RAM very efficient when storing bit information. Whole
BYTE ADDRESS (HEX)
bytes do not have to be
BIT ADDRESSES (HEX)
used up to store one or
20 two bits of data. 00-07
21 08-0F
22 10-17
23 18-lF
24 20-27
25 28-2F
26 30-37
27 38-3F
28 40-47
29 48-4F
2A 50-57
28 58-5F
2C 60-67
20 68-6F
2E 70-77
2F 78-7F
SFR Bit Addresses
All SFRs may be addressed at the byte level by using the direct address assigned
to it, but not all of the SFRs are addressable at the bit level. The SFRs that are
also bit addressable form the bit address by using the five most significant bits of
the direct address for that SFR, together with the three least significant bits that
identify the bit position from position 0 (LSB) to 7 (MSB).
SFR DIRECT ADDRESS (HEX) BIT ADDRESSES (HEX)
A OED OEO-OE7
6 OFO OFO-OF7
IE OAS OAS-OAF
IP 06S 06S-06F
PO so SO-S7
Pl 90 90-97
P2 OAO OAO-OA7
P3 060 060-067
TCON SS SS-SF
SCON 9S 9S-9F
Bit-Level Boolean Operations
The bit-level Boolean logical opcodes operate on any addressable RAM or SFR
bit. The carry flag (C) in the PSW special-function register is the destination for
most of the opcodes because the flag can be tested and the program flow
changed using instructions covered
The following table lists the Boolean bit-level operations.
Mnemonic Operation
ANL C,b AND C and the addressed bit; put the result in C
ANL C,/b AND C and the complement of the addressed bit; put the result in C; the addressed bit is not altered
7 6 5 4 3 2 1 0
Bit Function
7 Carry flag
6 Auxiliary carry flag
5 User flag 0
4 Register bank select bit 1
3 Register bank select bit 0
2 Overflow flag
1 Not used (reserved for future)
0 Parity flag
INTERRUPT ENABLE (IE) SPECIAL
FUNCTION REGISTER. BIT ADDRESSES
A8h TO AFh.
Bit Function
7 6 5 4 3 2 1 0
Bit Function
7 Not implemented
6 Not implemented
5 Not used (reserved for future)
4 Serial port interrupt priority
3 Timer 1 interrupt priority
2 External interrupt 1 priority
1 Timer 0 interrupt priority
TIMER/COUNTER CONTROL (TCON) SPECIAL FUNCTION
REGISTER. BIT ADDRESSES 88h to 8Fh
7 6 5 4 3 2 1 0
Bit Function
All flags can be set by the indicated hardware action; the flags are cleared when
interrupt is serviced by the processor
SERIAL PORT CONTROL (SCON) SPECIAL FUNCTION
REGISTER. BIT ADDRESSES 98h to 9Fh
7 6 5 4 3 2 1 0
SM0 SM1 SM2 REN TBB RBB TI RI
Bit Function
7 Serial port mode bit 0
6 Serial port mode bit 1
5 Multiprocessor communications enable
4 Receive enable
3 Transmitted bit in modes 2 and 3
2 Received bit in modes 2 and 3
1 Transmit interrupt flag
0 Receive interrupt flag
Rotate and Swap Operations
The ability to rotate data is useful for inspecting bits of a byte without using
individual bit opcodes. The A register can be rotated one bit position to the left
or right with or without including the C flag in the rotation. If the C flag is not
included, then the rotation involves the eight bits of the A register. If the C flag is
included, then nine bits are involved in the rotation. Including the C flag enables
the programmer to construct rotate operations involving any number of bytes.
Mnemonic Operation
Rotate the A register one bit position to the left; bit A0 to bit A I, A I to A2. A2 to A3. A3
RL A
to A4, A4 to A5, A5 to A6. A6 to A 7, and A 7 to A0
Rotate the A register and the carry flag. as a ninth bit, one bit position to the left; bit A0
RLC A to bit Al, Al to A2, A2 to A3, A3 to A4, A4 to A5. A5 to A6, A6 to A 7, A 7 to the carry flag,
and the carry flag to A0
Rotate the A register one bit position to the right; bit A0 to bit A 7, A6 to A5, A5 to A4,
RR A
A4 to A3, A3 to A2. A2 to Al, and At to A0
Rotate the A register and the carry flag, as a ninth bit, one bit position to the right; bit
RRC A A0 to the carry flag. carry flag to A 7, A 7 to A6, A6 to A5, A5 to A4, A4 to A3, A3 to A2,
A2 to Al, and Al to A0
Interchange the nibbles of register A; put the high nibble in the low nibble position and
SWAP A
the low nibble in the high nibble position
Figure Register a rotate operation
The following table shows examples of rotate and swap
operations:
Mnemonic Operation
All addition is done with the A register as the destination of the result. All
addressing modes may be used for the source: an immediate number, a register, a
direct address, and an indirect address. Some instructions include the carry flag as an
additional source of a single bit that is included in the operation at the least
significant bit position.
The following table lists the addition mnemonics
Mnemonic Operation
ADD A.#n Add A and the immediate number n; put the sum in A
ADD A,add Add A and the address contents; put the sum in A
ADD A,@Rp Add A and the contents of the address in Rp; put the sum in A
Unsigned and Signed Addition
The programmer may decide that the numbers used in the program are to be unsigned
numbers-that is, numbers that are 8-bit positive binary numbers ranging from 00h to
FFh. Alternatively, the programmer may need to use both positive and negative
signed numbers.
Unsigned Addition
Unsigned numbers make use of the carry flag to detect when the result of an ADD
operation is a number larger than Ffb. If the carry is set to one after an ADD, then the
carry can be added to a higher order byte so that the sum is not lost. For instance,
95d = 0101111 lb
189d = 10111101b
The C flag is set to I to account for the carry out from the sum. The program could
add the carry flag to another byte that forms the second byte of a larger number.
Signed Addition
Signed numbers may be added two ways: addition of like signed numbers and
addition of unlike signed numbers. If unlike signed numbers are added, then it is not
possible for the result to be larger than -128d or + 127d, and the sign of the result
will always be correct. For example,
-001d 11111111b
SUBB A,add Subtract the contents of add and the C flag from A; put the result in A
SUBB A,Rr Subtract Rr and the C flag from A; put the result in A
SUBB A,@Rp Subtract the contents of the address in Rp and the C flag from A; put the result in A
Unsigned and Signed Subtraction
Again, depending on what is needed, the programmer may choose to use bytes
as signed or unsigned numbers. The carry flag is now thought of as a borrow flag
to account for situations when a larger number is subtracted from a smaller
number. The OV flag indicates results that must be adjusted whenever two
numbers of unlike signs are subtracted and the result exceeds the planned signed
magnitudes
Unsigned Subtraction
Because the C flag is always subtracted from A along with the source byte, it
must be set to 0 if the programmer does not want the flag included in the
subtraction. If a multi-byte subtraction is done, the C flag is cleared for the first
byte and then included in subsequent higher byte operations.
Multiplication and Division
The 8051 has the capability to perform 8-bit integer multiplication and
division using the A and B registers. Register B is used solely for these
operations and has no other use except as a location in the SFR space of
RAM that could be used to hold data. The A register holds one byte of data
before a multiply or divide operation, and one of the result bytes after a
multiply or divide operation.
Multiplication Multiplication operations use registers A and B as both source
and destination addresses for the operation. The unsigned number in register A is
multiplied by the unsigned number in register B, as indicated in the following
table:
Mnemoni Operation
c
MULAB Multiply A by B: put the low-order byte of the product in A,
put the high-order byte in B
Division
Division operations use registers A and B as both source and destination
addresses for the operation. The unsigned number in register A is divided by the
unsigned number in register B, as indicated in the following table:
Mnemonic Operation
DIV AB Divide A by B; put the integer part of quotient in register A
and the integer part of the remainder in B
Decimal Arithmetic
Most 8051 applications involve adding intelligence to machines where the
hexadecimal numbering system works naturally. There are instances, however,
when the application involves interacting with humans, who insist on using the
decimal number system. In such cases, it may be more convenient for the
programmer to use the decimal number system to represent all numbers in the
program
The 8051 does all arithmetic operations in pure binary. When BCD numbers are
being used the result will often be a non-BCD number, as shown in the following
example:
Mnemoni
Operation
c
Adjust the sum of two packed BCD numbers found in A register; leave the
DA A
The Jump and Call Program Range
A jump or call instruction can replace the contents of the program counter with a
new program address number that causes program execution to begin at the code
located at the new address. The difference, in bytes, of this new address from the
address in the program where the jump or call is located is called the range of
the jump or call. For example, if a jump instruction is located at program address
0100h, and the jump causes the program counter to become 0 I 20h, then the
range of the jump is 20h bytes
Mnemonic Operation
Unconditional jumps do not test any bit or byte to determine whether the jump
should be taken. The jump is always taken. All jump ranges are found in this group
of jumps. and these are the only jumps that can jump to any location in memory.
The following table shows examples of unconditional jumps
Mnemonic Operation
Jump to the address formed by adding A to the DPTR; this is an unconditional
JMP@A+DPTR jump and will always be done; the address can be anywhere in program memory;
A, the DPTR, and the flags are unchanged
Jump to absolute short range address sadd; this is an unconditional jump and is
AJMP sadd
always taken; no flags are affected
Jump to absolute long range address ladd; this is an unconditional jump and is
LJMP !add
always taken; no flags are affected
Jump to relative address radd; this is an unconditional jump and is always taken;
SJMP radd
no flags are affected
Do nothing and go to the next instruction; NOP (no operation) is used to waste
NOP time in a software timing loop; or to leave room in a program for later additions; no
flags are affected
Calls and Subroutines
The life of a microcontroller would be very tranquil if all programs could run with no
thought as to what is going on in the real world outside. However, a microcontroller is
specifically intended to interact with the real world and to react, very quickly, to events
that require program attention to correct or control.
Subroutines
A subroutine is a program that may be used many times in the execution of a larger pro-
gram. The subroutine could be written into the body of the main program everywhere it is
needed, resulting in the fastest possible code execution. Using a subroutine in this manner
has several serious drawbacks.
Common practice when writing a large program is to divide the total task among many
programmers in order to speed completion. The entire program can be broken into
smaller parts and each programmer given a part to write and debug. The main program
can then call each of the parts, or subroutines. that have been developed and tested by
each individual of the team
Calls and the Stack
A call, whether hardware or software initiated, causes a jump to the address where
the called subroutine is located. At the end of the subroutine the program resumes
operation at the opcode address immediately following the call. As calls can be
located anywhere in the program address space and used many times, there must
be an automatic means of storing the address of the instruction following the call so
that program execution can continue after the subroutine has executed
Figure diagrams the following sequence of events
1. A call opcode occurs in the program software, or an interrupt is generated in the ardware
circuitry.
2. The return address of the next instruction after the call instruction or interrupt is found in the
program counter.
3. The return address bytes are pushed on the stack, low byte first.
4. The stack pointer is incremented for each push on the stack.
5. The subroutine address is placed in the program counter.
6. The subroutine is executed.
7. A RET (return) opcode is encountered at the end of the subroutine.
8. Two pop operations restore the return address to the PC from the stack area in internal RAM.
9. The stack pointer is decremented for each address byte pop.
All of these steps are automatically handled by the 8051 hardware. It is the responsibility of the
programmer to ensure that the subroutine ends in a RET instruction and that the stack does not
grow up into data areas that are used by the program.
Calls and Returns
Mnemonic Operation
ACALL sadd Call the subroutine located on the same page as the address of the opcode
immediately following the ACALL instruction: push the address of the
instruction immediately after the call on the stack
LCALL Ladd Call the subroutine located anywhere in program memory space; push the
address of the instruction immediately following the call on the stack
RET Pop two bytes from the stack into the program counter
The keyboard application program must guard against the following possibilities:
More than one key pressed (simultaneously or released in any sequence)
Key pressed and held
Rapid key press and release
All of these situations can be addressed by hardware or software means; software,
which is the most cost effective, is emphasized here.
Key Switch Factors
The universal key characteristic is the ability to bounce: The key contacts vibrate
open and close for a number of milliseconds when the key is hit and often when it is
released.
These rapid pulses are not discernible to the human, hut they last a relative eternity
in the microsecond-dominated life of the microcontroller. Keys may be purchased
that do not bounce, keys may be debounced with RS flip-flops, or debounced in
software with time delays.
Keyboard Configurations
The program "lnkey" uses hardware timer T1 to generate all time delays. The
keyboard sequence is initiated when a key is found to be down; otherwise, the
program continues and checks for a key down in the next look. A key down initiates
a de bounce time delay in timer T1 and sets a timer Hag to notify the interrupt
program of the use of the timer. The interrupt program checks that a key is still
down and is valid. Valid keys are stored, and a Hag is set that may be tested by the
main program.
Code key
A 64-key keyboard, arranged as an 8-row by 8-column matrix will be interfaced to the 8051
rnicrocontroller, as shown in Figure 8.5. Port I will be used to bring each row low, one row at a time,
using an 8-bit latch that is strobed by port 3.2. Pl will then read the 8-bit column pattern by enabling
the tri-state buffer from port 3.3. A pressed key will have a unique row-column pattern of one row
low, one column low.
Multiple key presses are rejected by either an invalid pattern or a failure to match for three complete
cycles. Each row is scanned at an interval of I millisecond, or an 8 millisecond cycle for the entire
keyboard. A valid key must be seen to be the same key for 3 cycles (24 milliseconds). There must
then be three cycles with no key down before a new key will be accepted. The I millisecond delay
between scans is generated by timer TO in an interrupt mode.
Big key
The "Big key" program scans an 8 x 8 keyboard matrix using TO to generate a periodic I ms delay in
an interrupt mode. Each row is scanned via an external latch driven by port I and strobed by port 3.2.
Columns are read via a tri-state buffer under control of port 3.3. Keys found to be valid are passed to
the main program by setting the flag "new fig" and placing the key identifiers in locations "new row"
and "new col." The main program resets "new flag" when the new key is fetched. R4 is used as a
cycle counter for successful matches and up time cycles. R5 is used to hold the row scan pattern: only
one bit low
Displays
If keyboards are the predominant means of interface to human input, then visible displays
are the universal means of human output. Displays may be grouped I͞NT
͞ 0͞ three broad
categories:
1. Single light(s)
2. Single character(s)
3. Intelligent alphanumeric
Single light displays include incandescent and, more likely, LED indicators that are treated
as single binary points to be switched off or on by the program. Single character displays
include numeric and alphanumeric arrays. These may be as simple as a seven segment
numeric display up to intelligent dot matrix displays that accept an 8-bit ASCII character and
convert the ASCII code to the corresponding alphanumeric pattern. Intelligent alphanumeric
displays are equipped with a built-in microcontroller that has been optimized for the
application. Inexpensive displays are represented by multicharacter LCD windows, which
are becoming increasingly popular in hand-held wands, factory fl00r terminals, and
automotive dashboards. The high-cost end is represented by CRT ASCII terminals of the
type commonly used to interface to a multi-user computer.
Seven-Segment Numeric Display
Sensors used for industrial and commercial control applications frequenT1y produce pulses that
contain information about the quantity sensed. Varying the sensor output frequency, using a constant
duty cycle but variable frequency pulses to indicate changes in the measured variable, is most
common. Varying the duration of the pulse width, resulting in constant frequency but variable duty
cycle, is also used. In this section, we examine programs that deal with both techniques.
Measuring Frequency
Timers TO and T 1 can be used to measure external frequencies by configuring one timer as a counter
and using the second timer to generate a timing interval over which the first can count. The frequency
of the counted pulse train is.then
Unknown frequency = Counter/timer
For example, if the counter counts 200 pulses over an interval of .1 second generated by the timer. the
frequency is
UF = 200/. 1 = 2000 Hz
Certain fundamental limitations govern the range of frequencies that can be measured. An input pulse
must make a l-to-0 transition lasting two machine cycles. or f/24, to be counted. This restriction on
pulse deviation yields a frequency of 667 kilohertz using our 16 megahertz crystal (assuming a square
wave input).
Pulse Width Measurement
Theoretically, if the input pulse is known to be a perfect square wave, the pulse frequency can be measured by
finding the time the wave is high (Th). The frequency is then
If Th is 200 microseconds, for example, then UF is 2500 hertz. The accuracy of the measurement
will fall as the input wave departs from a 50 percent duty cycle.
Timer X may be configured so that the internal clock is counted only when the corresponding I͞N͞TX ͞ pin is high
by setting the GATE X bit in TMOD. The accuracy of the measurement is within approximately one-half of the
timer clock period, or .375 microsecond for a 16 megahertz crystal. This accuracy can only be attained if the
measurement is started when the input wave is low and stopped when the input next goes low. Pulse widths
greater than the capacity of the counter, which is 49.152 milliseconds for a 16 megahertz crystal, can be
measured by counting the overflows of the timer flag and adding the final contents in the counter.
D/ A and A/D Conversions
Conversion between the analog and digital worlds requires the use of integrated
circuits that have been designed to interface with computers. Highly intelligent
converters are commercially available that all have the following essential
characteristics:
Parallel data bus: tri-state, 8-bit
Control bus: enable (chip select), read/write, ready/busy
The choice the designer must make is whether to use the converter as a RAM
memory location connected to the memory busses or as an I/O device connected to
the ports. Once that choice is made, the set of instructions available to the
programmer becomes limited. The memory location assignment is the most
restrictive, having only MOVX available. The design could use the additional 32K
RAM address space with the addition of circuitry for A 15. By enabling the RAM
when A 15 is low, and the converter when A 15 is high, the designer could use the
upper 32K RAM address space for the converter, as was done to expand port
capacity by memory mapping in Chapter 7. All of the examples examined here are
connected to the ports.
D/A Conversions
The design tension is high frequency versus high resolution. For a io00 hertz wave, S
could be 200d samples. In reality, we cannot use this many samples; the program
cannot fetch the data, latch it to port I, and strobe port 3.3 in 5 microseconds. An
inspection of the program will show that the time needed for a single wave point is
6 microseconds, and setting up for the next wave takes another 2.25 microseconds.
S becomes 166d samples using the 6 microseconds interval. and the addition of 2.25
microseconds at the end of every wave yields a true frequency of io01. 75 hertz
A/D Conversion
The easiest A/D converters to use are the "flash" types, which make Conversions
based upon an array of internal comparators. The Conversion is very fast, typically
in less than 1 microsecond. Thus, the converter can be told to start, and the digital
equivalent of the input analog value will be read one or two instructions later.
Modern successive approximation register (SAR) converters do not lag far behind,
however, with Conversion times in the 2-4 microsecond range for eight bits.
A/D Converter Circuit
Multiple Interrupts
The 8051 is equipped with two external interrupt input pins: I͞NT͞ ͞0 and INTI (P3.2
and P3.3). These are sufficient for small systems, but the need may arise for more
than two interrupt points. There are many schemes available to multiply the
number of interrupt points; they all depend upon the following strategies
Hardware Circuits for Multiple Interrupts
Solutions to the expanded interrupt problem proposed to this point have emphasized
using a minimal amount of external circuitry to handle multiple, overlapping
interrupts. A hardware strategy, which can be expanded to cover up to 256 interrupt
sources, is shown in Figure 8.13. This circuit is a version of the "daisy chain"
approach, which has long been popular.
The overall philosophy of the design is as follows:
1. The most important interrupt source is physically connected first in the chain,
with those of lesser importance next in line. Lower priority interrupt sources are
"behind" (connected further from I͞N͞T͞0 ) those of a higher priority.
2. Each interrupting source can disable all signals from sources that are wired
behind it. All sources that lose the INACTOUT signal (a low level) from the
source(s) ahead of it will place their source address buffer in a tri-state mode until
INACTOUT is restored.
3. A requesting source pulls its I͞N͞T͞0 UT line low and places its 8-bit identifier on the
tri-state bus connected to port I . The interrupt routine at the I͞N͞T͞0 vector location
reads Pl and, using a lookup table, finds the address of the subroutine that handles
that interrupt. The address is placed on the stack and a RETI executed to go to that
routine and re-arm the interrupt structure
Multi-tasking circuit using memory mapping i/o
Summary
This chapter introduced the RS232 serial communications standard and placed it
in context with newer forms of serial communications. It also discussed the role
of the UART and external transceiver circuits necessary to transmit bits of data
at the proper voltage.
On the software side, this chapter discussed how to configure the serial port
using the special function registers and also discussed issues pertaining to baud
rate generation. Finally, reading and writing to the serial port was addressed and
both software and hardware handshaking concepts were introduced.
References
TEXT BOOKS
1. Ramesh Gaonkar, Microprocessor Architecture, programming and applications with
the 8085, Penram International Publications Pvt Ltd. 6th Edition, 2015.
2. Kenneth J Ayala, The 8051 microcontroller, Penram International Publications Pvt
Ltd, 2 nd Edition, 1997
REFERENCES
1. Ray Bhurchandi, Advanced Microprocessors & Peripheral interfacing, MC graw hill
Publications, 3 rd edition, 2012.
2. N.Senthil Kumar, M.Saravanan, S.Jeevanathan, Microprocessor and Microcontrollers,
Oxford Publishers. 1 st Edition, 2015.
WEB SITE
https://exploreembedded.com/wiki/LCD_16_x_2_Basics
https://www.tutorialspoint.com/interfacing-8279-keyboard-
with-8085-microprocessor
https://www.youtube.com/watch?v=XiXMdcvX2Lc
https://www.youtube.com/watch?v=yFIiJ6bJUNE
https://circuitdigest.com/microcontroller-
projects/interfacing-adc0808-with-8051-microcontroller
https://openlabpro.com/guide/adc-interfacing-with-8051/
https://www.circuitstoday.com/interfacing-adc-to-8051
http://8051-microcontrollers.blogspot.com/2014/10/8051-
logical-operations-byte-level.html
https://archive.nptel.ac.in/courses/108/105/108105102/