FMPMC Notes3-5
FMPMC Notes3-5
FMPMC Notes3-5
Unit-3 Notes
8086 Microprocessor Interfacing
8255 microprocessor is a very popularly used programmable peripheral interface chip or PPI
chip. The function of the 8255 microprocessor is to transmit data in various conditions from
simple I/O to interrupt I/O. This microprocessor is also designed for interfacing the CPU with
its external world like ADC, keyboard, DAC, etc. This microprocessor is economical,
functional, and flexible although is a little complex, so it can be used with any microprocessor.
This microprocessor is used to connect peripheral devices & also for interfacing. So this
peripheral device is also called an I/O device because the I/O ports of this microprocessor are
used for connecting I/O devices. This processor includes three 8-bit bidirectional I/O ports
which can be configured based on necessity.
It includes three I/O ports which are programmed within different modes.
It operates in three modes like Mode 0 (Simple I/O), Mode 1 (Strobed I/O), and Mode
2 (Strobed bi-directional I/O).
It is TTL compatible.
The three I/O ports include a control register that defines each I/O port’s function & in
which mode they must operate.
3. Draw and explain the Pin configuration of 8255 Microprocessor.
The pin diagram of the 8255 microprocessor is shown below. This microprocessor includes 40-
pins like PA7-PA0, PC7-PC0, PC3-PC0, PB0-PB7, RD, WR, CS, A1 & A0, D0-D7 and
RESET. These pins are discussed below.
A0 & A1
A0 and A1 pins at pin8 & pin9 simply make a decision about which port will be preferred for
transmitting the data.
CS’
The pin6 like CS’ is a chip select input pin which is responsible for selecting a chip. A low
signal at CS’ pin simply allows the communication between the 8255 & the processor which
means at this pin, the operation of data transfer gets allowed by an active low signal.
RD’
The pin5 like RD’ is a read input pin that puts the chip within the reading mode. A low signal
at this RD’s pin provides data to the CPU by a data buffer.
WR’
The pin36 like WR’ pin is a write input pin that puts the chip within writing mode. So, a low
signal at WR’ pin simply allows the CPU to execute the write operation above the ports
otherwise microprocessor’s control register through the data bus buffer.
RESET
The pin35 like the RESET pin resets the whole data available in all the keys to their default
values when it is in set mode. It is an active high signal where the high signal at the RESET
pin clears the control registers &the ports are placed within the input mode.
GND
The pin7 is a GND pin of IC.
VCC
The pin26 like VCC is the 5V input pin of IC.
Port C
Port C includes an 8-bit data input buffer and 8-bit bidirectional data o/p latch or buffer. This
port is divided mainly into two sections – port C upper PCU & port C lower PC. So these two
sections are mainly programmed & separately used as a 4-bit I/O port. This port is used for
handshake signals, Simple I/O & status signal inputs. This port is used in combination with
port A & Port B for both the status and handshaking signals. This port provides only direct but
sets or resets capacity.
The 8255 microprocessor has two operating modes like bit set-reset mode and input/output
mode which are discussed below.
I/O Mode
I/O mode has three different modes like Mode 0, Mode 1 & Mode 2 where each mode is
discussed below.
Mode 0:
This is an I/O mode of 8255 which simply allows the programming of each port like either i/p
or o/p port. So, the I/O feature of this mode simply includes:
Mode 2:
Mode2 is a Bidirectional I/O port with handshaking. So, the ports in this type of mode can be
used for the bidirectional data flow through handshaking signals. The group A pins can be
programmed to perform like bidirectional data bus & PC7 – PC4 in port C are used through
the handshaking signal. The remaining lower port C bits are used for input/Output operations.
This mode has the capacity of interrupt handling.
Memory interfacing
Memory is an integral part of a microcomputer system. There are two main types of
memory.
(i) Read only memory (ROM): As the name indicates this memory is available
only for reading purpose. The various types available under this category are
PROM, EPROM, EEPROM which contain system software and permanent
system data.
(ii) Random Access memory (RAM): This is also known as Read Write Memory.
It is a volatile memory. RAM contains temporary data and software programs
generally for different applications.
While executing particular task it is necessary to access memory to get instruction codes
and data stored in memory. Microprocessor initiates the necessary signals when read or
write operation is to be performed. Memory device also requires some signals to
perform read and write operations using various registers. To do the above job it is
necessary to have a device and a circuit, which performs this task is known as
interfacing device and as this is involved with memory it-is known as memory
interfacing device. The basic concepts of memory interfacing involve three different
tasks. The microprocessor should be able to read from or write into the specified
register. To do this it must be able to select the required chip, identify the required
register and it must enable the appropriate buffers.
Fig: A Simple Memory Device
Any memory device must contain address lines and Input, output lines, selection input,
control input to perform read or write operation. All memory devices have address
inputs that select memory location within the memory device. These lines are labelled
as AO ...... AN. The number of address lines indicates the total memory capacity of the
memory device. A 1K memory requires 10 address lines A0-A9. Similarly, a 1MB
requires 20 lines A0-A19 (in the case of 8086). The memory devices may have separate
I/O lines or a common set of bidirectional I/O lines. Using these lines data can be
transferred in either direction. Whenever output buffer is activated, the operation is read
whenever input buffers are activated the operation is written. These lines are labelled
as I/O, ......... I/On or DO .............Dn. The size of a memory location is dependent upon
the number of data bits. If the number of data lines are eight D0 - D7 then 8 bits or 1
byte of data can be stored in each location. Similarly, if numbers of data bits are 16 (D0
- D15) then the memory size is 2 bytes. For example, 2K x 8 indicates there are 2048
memory locations and each memory location can store 8 bits of data.
Memory devices may contain one or more inputs which are used to select the memory
device or to enable the memory device. This pin is denoted by CS (Chip select) or CE
(Chip enable). When this pin is at logic '0' then only the memory device performs a read
or a write operation. If this pin is at logic ‘1’ the memory chip is disabled. If there are
more than one CS input then all these pins must be activated to perform read or write
operation.
All memory devices will have one or more control inputs. When ROM is used, we find
OE output enable pin which allows data to flow out of the output data pins. To perform
this task both CS and OE must be active. A RAM contains one or two control inputs.
They are R / W or RD and WR. If there is only one input R/ W then it performs read
operation when R/ W pin is at logic 1. If it is at logic 0 it performs write operation. Note
that this is possible only when CS is also active.
7. Briefly explain about the Seven segment Display Interfacing to 8086
microprocessors.
8. Briefly explain about the Keypad Interfacing to 8086 microprocessors.
Keyboard Interfacing
In most keyboards, the key switches are connected in a matrix of Rows and Columns.
Getting meaningful data from a keyboard requires three major tasks:
Key Debounce:
Whenever a mechanical push-bottom is pressed or released once, the mechanical
components of the key do not change the position smoothly; rather it generates a
transient response. These may be interpreted as the multiple pressures and responded
accordingly.
The rows of the matrix are connected to four output Port lines, &columns are
connected to four input Port lines.
When no keys are pressed, the column lines are held high by the pull-up resistors
connected to +5v.
Pressing a key connects a row & a column.
To detect if any key is pressed is to output 0‟s to all rows & then check columns
to see it a pressed key has connected a low (zero) to a column.
Once the columns are found to be all high, the program enters another loop,
which waits until a low appears on one of the columns i.e indicating a key press.
A simple 20/10 msec delay is executed to debounce task.
After the debounce time, another check is made to see if the key is still pressed.
If the columns are now all high, then no key is pressed & the initial detection
was caused by a noise pulse.
To avoid this problem, two schemes are suggested:
1. Use of Bistable multivibrator at the output of the key to debounce it.
2. The microprocessor has to wait for the transient period (at least for 10 ms),
so that the transient response settles down and reaches a steady state.
If any of the columns are low now, then the assumption is made that it was a
valid key press.
The final task is to determine the row & column of the pressed key &convert
this information to Hex-code for the pressed key.
The 4-bit code from I/P port & the 4-bit code from O/P port (row &column) are
converted to Hex-code.
The circuit for interfacing a winding Wn with an I/O port is given in fig.4.
Each of the windings of a stepper motor needs this circuit for its interfacing
with the output port. A typical stepper motor may have parameters like torque
3 Kg-cm, operating voltage 12V, current rating 0.2 A and a step angle 1.80 i.e.
200 steps/revolution (number of rotor teeth).
A simple schematic for rotating the shaft of a stepper motor is called a wave
scheme. In this scheme, the windings Wa, Wb, Wc and Wd are applied with
the required voltages pulses, in a cyclic fashion. By reversing the sequence of
excitation, the direction of rotation of the stepper motor shaft may be reversed.
Table.1 shows the excitation sequences for clockwise and anticlockwise
rotations.
10. Briefly explain about the Direct memory access with DMA controller 8237.
Suppose any device which is connected to input-output port wants to transfer data to
memory, first of all it will send input-output port address and control signal, input-
output read to input-output port, then it will send memory address and memory write
signal to memory where data has to be transferred. In normal input-output technique
the processor becomes busy in checking whether any input-output operation is
completed or not for next input output operation, therefore this technique is slow.
This problem of slow data transfer between input output port and memory or between
two memory is avoided by implementing Direct Memory Access (DMA) technique.
This is faster as the microprocessor/computer is bypassed and the control of address
bus and data bus is given to the DMA controller.
HOLD – hold signal
Suppose a floppy drive that is connected at input-output port wants to transfer data to
memory, the following steps are performed:
Step-1: First of all the floppy drive will send a DMA request (DREQ) to the
DMAC, it means the floppy drive wants its DMA service.
Step-2: Now the DMAC will send a HOLD signal to the CPU.
Step-3: After accepting the DMA service request from the DMAC, the CPU will
send hold acknowledgment (HLDA) to the DMAC, it means the microprocessor
has released control of the address bus the data bus to DMAC and the
microprocessor/computer is bypassed during DMA service.
Step-4: Now the DMAC will send one acknowledgement (DACL) to the floppy
drive which is connected at the input-output port. It means the DMAC tells the
floppy drive be ready for its DMA service.
Step-5: Now with the help of input-output read and memory write signal the data
is transferred from the floppy drive to the memory.
Modes of DMAC:
1. Single Mode – In this only one channel is used, means only a single DMAC is
connected to the bus system.
2. Cascade Mode – In this multiple channels are used, we can further cascade more
number of DMACs.
Advantages:
Improved performance: DMA improves system performance by freeing up the CPU to
perform other tasks while data is being transferred between memory and I/O devices. This
allows for faster and more efficient data transfer.
Reduced CPU overhead: With DMA, the CPU is not required to be involved in data
transfer, which reduces the CPU overhead and allows it to focus on other tasks. This is
particularly useful in real-time systems where low latency and fast response times are
important.
Support for high-bandwidth devices: DMA can support high-bandwidth devices such as
graphics cards and network interfaces that require fast data transfer rates.
Efficient use of system resources: DMA allows multiple devices to access memory
simultaneously, which makes more efficient use of system resources.
Disadvantages:
Complexity: DMA requires specialized hardware and software to function, which can add to
the complexity of a system. This can make it difficult to implement and troubleshoot.
Security risks: DMA can be a security risk if not properly configured or secured. Hackers
can exploit vulnerabilities in DMA to gain unauthorized access to a computer system or steal
data.
Limited control: Since the CPU is not involved in data transfer with DMA, it has limited
control over the transfer process. This can lead to data corruption or errors if the transfer
process is not properly managed.
Resource conflicts: DMA can lead to resource conflicts if multiple devices attempt to access
memory simultaneously. This can cause system instability and performance issues if not
properly managed.
8257 DMA Controller:
Features of 8257:
1. It is a 4-channel Direct Memory Access (DMAC) interface IC which allows data transfer
between memory and up to 4 I/O devices, bypassing CPU.
2. A maximum of 16 KB of data (= 214) can be transferred by this IC sequentially at a time.
When a DMA request comes from a peripheral, the DMAC 8257, via its HRQ (Hold Request)
pin, requests the CPU on its HOLD pin. CPU then acknowledges this request via its HLDA pin
which goes to HLDA pin of 8257. After this, DMAC generates the required MEMR, MEMW,
I/OR, I/OW signals.
3. Initialization of the DMAC is done under program control for each channel. The parameters
which need to be initialized for each channel are starting address, number of bytes of data to
be transferred, mode of operation, etc.
4. DMAC can be operated in three modes: (a) DMA Read (reading from memory, writing into
peripheral), (b) DMA Write (writing into memory, reading from peripheral), (c) DMA verify.
5. Priority for each of the 4 channels can be set in (a) fixed priority, (b) rotating priority.
6. A Terminal Count Register exists for each of 4 channels. The number of bytes of data to be
transferred is stored in the D13–D0 positions of the 16-bit Terminal Count Register. On
completion of data transfer, the Terminal Count (TC) pin goes high.
7. When the CPU is in control of its buses (address bus, data bus and control bus), it acts as
master and DMA controller acts as the slave. When DMA controller takes control of the buses,
it becomes the master and CPU becomes the slave.
Description of pins:
D0-D7:It is a bidirectional ,tri state ,Buffered ,Multiplexed data (D0-D7)and (A8-A15). In the
slave mode it is a bidirectional (Data is moving). In the Master mode it is a unidirectional
(Address is moving).
IOR: It is active low, tristate, buffered, Bidirectional lines. In the slave mode it functions as
an input line. IOR signal is generated by microprocessor to read the contents of 8257 registers.
In the master mode it functions as an output line. IOR signal is generated by 8257 during write
cycle.
IOW: It is active low, tristate, buffered, Bidirectional lines. In the slave mode it functions as
an input line. IOW signal is generated by microprocessor to write the contents of 8257 registers.
In the master mode it functions as an output line. IOR signal is generated by 8257 during read
cycle.
CLK: It is the input line, connected with TTL clock generator. This signal is ignored in slave
mode.
RESET: It is used to clear mode set registers and status registers.
A0-A3: These are the tristate, buffer, bidirectional address lines. In slave mode, these lines are
used as address inputs lines and internally decoded to access the internal registers. In master
mode, these lines are used as address outputs lines, A0-A3 bits of memory address on the lines.
CS: It is active low, Chip select input line. In the slave mode, it is used to select the chip. In
the master mode, it is ignored.
A4-A7: These are the tristate, buffer, output address lines. In slave mode, these lines are used
as address outputs lines. In master mode, these lines are used as address outputs lines, A0-A3
bits of memory address on the lines.
READY: It is a asynchronous input line. In master mode, When ready is high it is received the
signal. When ready is low, it adds wait state between S1 and S3. In slave mode,this signal is
ignored.
HRQ: It is used to receiving the hold request signal from the output device. HLDA: It is
acknowledgment signal from microprocessor.
MEMR: It is active low, tristate, Buffered control output line. In slave mode, it is tristated. In
master mode, it activated during DMA read cycle.
MEMW: It is active low, tristate, Buffered control input line. In slave mode, it is tristated. In
master mode, it activated during DMA write cycle.
AEN (Address enable): It is a control output line. In master mode, it is high. In slave mode, it
is low. Used it isolate the system address, data and control lines.
ADSTB: (Address Strobe) It is a control output line. Used to split data and address line. It is
working in master mode only. In slave mode it is ignore.
TC (Terminal Count): It is a status of output line. It is activated in master mode only. It is
high, it selected the peripheral. It is low, it free and looking for a new peripheral.
MARK: It is a modulo 128 MARK output line. It is activated in master mode only. It goes
high, after transferring every 128 bytes of data block.
DRQ0-DRQ3(DMA Request): These are the asynchronous peripheral request input signal.
The request signals are generated by external peripheral device.
DACK0-DACK3: These are the active low DMA acknowledge output lines. Low level
indicates s that, peripheral is selected for giving the information (DMA cycle). In master mode
it is used for chip select.
11. Briefly explain about the Intel 8251 USART Architecture and Interfacing.
Versatility: The 8251 USART can be used for both synchronous and asynchronous
communication, making it a versatile peripheral.
Error detection: The USART includes built-in error detection features, such as parity
checking, which help to ensure the accuracy of transmitted data.
Flow control: The USART includes flow control features, which allow for the regulation of
data transmission and reception, preventing data loss and overloading.
Compatibility: The 8251 USART is compatible with a wide range of microprocessors,
making it a popular choice for serial communication in many different systems.
Ease of use: The USART includes simple interface pins and registers, making it relatively
easy to use and program.
Disadvantages:
Limited speed: The 8251 USART has a relatively low maximum data transfer rate of 115.2
kbps, which may be insufficient for some applications.
Limited buffer size: The USART has a small internal buffer size, which may result in data
loss if data is not read from the buffer in a timely manner.
Complex programming: Although the interface pins and registers of the USART are
relatively simple, programming the USART can be complex, requiring careful attention to
timing and other parameters.
Cost: While the 8251 USART is relatively affordable, it does add cost to a system,
particularly if multiple USARTs are required.
Limited functionality: While the 8251 USART is a useful peripheral for serial
communication, it does not include more advanced features, such as DMA (direct memory
access) or advanced error correction.
Course name: Fundamentals of MPMC
Unit-4 Notes
8051 Microcontroller
Microprocessor Microcontroller
Since memory and I/O are connected Since memory and I/O are present
externally, the circuit becomes large in together, the internal circuit is small in
size. size.
Complex and expensive due to large Simple and inexpensive due to less
number of instructions to process. number of instructions to process.
As we know that the CPU is the brain of any processing device of the microcontroller. It
monitors and controls all operations that are performed on the Microcontroller units. The User
has no control over the work of the CPU directly. It reads program written in ROM memory
and executes them and do the expected task of that application.
Interrupts
As its name suggests, Interrupt is a subroutine call that interrupts of the microcontrollers main
operations or work and causes it to execute any other program, which is more important at the
time of operation. The feature of Interrupt is very useful as it helps in case of emergency
operations. An Interrupts gives us a mechanism to put on hold the ongoing operations, execute
a subroutine and then again resumes to another type of operations.
The Microcontroller 8051 can be configured in such a way that it temporarily terminates or
pause the main program at the occurrence of interrupts. When a subroutine is completed, Then
the execution of main program starts. Generally, five interrupt sources are there in 8051
Microcontroller. There are 5 vectored interrupts are shown in below
INTO
TFO
INT1
TF1
R1/T1
Out of these, (INT0) ̅ and (INT1) ̅ are external interrupts that could be negative edge triggered
or low level triggered. When All these interrupts are activated, set the corresponding flogs
except for serial interrupt,. The interrupt flags are cleared when the processor branches to the
interrupt service routine (ISR). The external interrupt flags are cleared when the processor
branches to the interrupt service routine, provides the interrupt is a negative edge triggered
whereas the timers and serial port interrupts two of them are external interrupts, two of them
are timer interrupts and one serial port interrupt terminal in general.
Memory
BUS
Basically Bus is a collection of wires which work as a communication channel or medium for
transfer of Data. These buses consists of 8, 16 or more wires of the microcontroller. Thus, these
can carry 8 bits,16 bits simultaneously. Hire two types of buses that are shown in below
Address Bus
Data Bus
Address Bus: Microcontroller 8051 has a 16 bit address bus for transferring the data. It is used
to address memory locations and to transfer the address from CPU to Memory of the
microcontroller. It has four addressing modes that are
Data Bus: Microcontroller 8051 has 8 bits of the data bus, which is used to carry data of
particular applications.
Oscillator
Generally, we know that the microcontroller is a device, therefore it requires clock pulses for
its operation of microcontroller applications. For this purpose, microcontroller 8051 has an on-
chip oscillator which works as a clock source for Central Processing Unit of the
microcontroller. The output pulses of oscillator are stable. Therefore, it enables synchronized
work of all parts of the 8051 Microcontroller.
Input/Output Port
Timers/Counters
8051 microcontrollers have two 16-bit timers and counters. These counters are again divided
into a 8 bit register. The timers are used for measurement of intervals to determine the pulse
width of pulses.
Based on the operation they perform, all the instructions in the 8051 Microcontroller
Arithmetic Instructions
Logical Instructions
program memory or external data memory. The Mnemonics associated with Data Transfer are
given below.
Mnemonic Description
MOV Move Data
The following table lists out all the possible data transfer instructions along with other details
like addressing mode, size occupied and number machine cycles it takes.
Arithmetic Instructions
Using Arithmetic Instructions, you can perform addition, subtraction, multiplication and
division. The arithmetic instructions also include increment by one, decrement by one and a
The Mnemonics associated with the Arithmetic Instructions of the 8051 Microcontroller
Mnemonic Description
DEC Decrement by 1
MUL Multiply
DIV Divide
The arithmetic instructions have no knowledge about the data format i.e., signed, unsigned,
ASCII, BCD, etc. Also, the operations performed by the arithmetic instructions affect flags like
carry, overflow, zero, etc. in the PSW Register.
All the possible Mnemonics associated with Arithmetic Instructions are mentioned in the
following table.
Logical Instructions
The next group of instructions are the Logical Instructions, which perform logical operations
like AND, OR, XOR, NOT, Rotate, Clear and Swap. Logical Instruction are performed on
Mnemonic Description
ORL Logical OR
XRL Ex-OR
The following table shows all the possible Mnemonics of the Logical Instructions.
know that there is a special bit-addressable area in the RAM and some of the Special Function
Mnemonic Description
JBC Jump if specified Bit is Set and also clear the Bit
ORL Bitwise OR
These instructions can perform set, clear, and, or, complement etc. at bit level.
The last group of instructions in the 8051 Microcontroller Instruction Set are the Program
Branching Instructions. These instructions control the flow of program logic. The mnemonics
Mnemonic Description
NOP No Operation
All these instructions, except the NOP (No Operation) affect the Program Counter (PC) in one
way or other. Some of these instructions has decision making capability before transferring
8051 Family of Microcontrollers allows five types of Addressing Modes for addressing the
Register Addressing
Direct Addressing
Indexed Addressing
Immediate Addressing
In Immediate Addressing mode, the operand, which follows the Opcode, is a constant data of
either 8 or 16 bits. The name Immediate Addressing came from the fact that the constant data
The constant value to be stored is specified in the instruction itself rather than taking from a
register. The destination register to which the constant data must be copied should be the same
Here, the Accumulator is loaded with 30 (hexadecimal). The # in the operand indicates that it
Immediate Addressing is very fast as the data to be loaded is given in the instruction itself.
Register Addressing
In the 8051 Microcontroller Memory Organization Tutorial, we have seen the organization of
RAM and four banks of Working Registers with eight Registers in each bank.
In Register Addressing mode, one of the eight registers (R0 – R7) is specified as Operand in
the Instruction.
It is important to select the appropriate Bank with the help of PSW Register. Let us see a
Example: MOV A, R5
Here, the 8-bit content of the Register R5 of Bank0 is moved to the Accumulator.
Direct Addressing
In Direct Addressing Mode, the address of the data is specified as the Operand in the
instruction. Using Direct Addressing Mode, we can access any register or on-chip variable.
This includes general purpose RAM, SFRs, I/O Ports, Control registers.
Here, the data in the RAM location 47H is moved to the Accumulator.
Operand is specified as the content of a Register. This will be clearer with an example.
The @ symbol indicates that the addressing mode is indirect. If the contents of R1 is 56H, for
example, then the operand is in the internal RAM location 56H. If the contents of the RAM
Only R0 and R1 are allowed in Indirect Addressing Mode. These register in the indirect
register and an offset register. The Base Register can be either Data Pointer (DPTR) or Program
In Indexed Addressing Mode, only MOVC and JMP instructions can be used. Indexed
Addressing Mode is useful when retrieving data from look-up tables.
Here, the address for the operand is the sum of contents of DPTR and Accumulator.
The 8051 microcontroller's memory is divided into Program Memory and Data Memory.
Program Memory (ROM) is used for permanent saving program being executed, while Data
Memory (RAM) is used for temporarily storing and keeping intermediate results and variables.
Memory block in the range of 20h to 2Fh is bit-addressable, which means that each bit being
there has its own address from 0 to 7Fh. Since there are 16 such registers, this block contains
in total of 128 bits with separate addresses (Bit 0 of byte 20h has the bit address 0, and bit 7
of byte 2Fh has the bit address 7Fh).
Three memory type specifiers can be used to refer to the internal data memory: data, idata,
and bdata.
SFR Memory
The 8051 provides 128 bytes of memory for Special Function Registers (SFRs). SFRs are bit,
byte, or word-sized registers that are used to control timers, counters, serial I/O, port I/O, and
peripherals.
Course name: Fundamentals of MPMC
Unit-5 Notes
Microcontroller Programming and Applications
1. What are the Key features of the 8051 Microcontroller?
The Key features of the 8051 Microcontroller
4 KB on-chip ROM (Program memory).
128 bytes on-chip RAM (Data memory).
The 8-bit data bus (bidirectional).
16-bit address bus (unidirectional).
Two 16-bit timers.
Instruction cycle of 1 microsecond with 12 MHz crystal.
Four 8-bit input/output ports.
128 user-defined flags.
Four register banks of 8 bit each.
16-byte bit-addressable RAM.
The general-purpose registers are 32 each is 8-bit.
8051 has two external and three internal interrupts.
8051 microcontroller specifies some special function features like UARTs, ADC, Op-
amp, etc.
It has a 16-bit program counter and data pointer.
The 8051 microcontroller is widely used in various applications due to its versatility,
flexibility, and easy-to-use architecture. Here are some of the applications of the 8051
microcontrollers:
Home automation:
The 8051 microcontrollers can be used in home automation systems to control lighting,
temperature, and security systems.
Industrial control:
The 8051 microcontroller is used in industrial control applications to control processes,
machinery, and equipment. It can also be used to monitor and control temperature, pressure,
and other environmental factors.
Robotics:
The 8051 microcontroller is used in robotics applications to control the movement of robots,
sensors, and actuators.
Automotive:
The 8051 microcontroller is used in the automotive industry for engine control, anti-lock
braking systems, airbag control, and other applications.
Medical devices:
The 8051 microcontroller is used in medical devices for patient monitoring, drug delivery
systems, and other applications.
Communication systems:
The 8051 microcontroller is used in communication systems for data transmission, signal
processing, and other applications.
Consumer electronics:
The 8051 microcontroller is used in consumer electronics such as remote controls, digital
cameras, and smart home devices.
In summary, the 8051 microcontroller is a versatile and widely used microcontroller that can
be applied in various fields, including home automation, industrial control, robotics,
automotive, medical devices, communication systems, and consumer electronics. Its ease of
use and flexibility make it a popular choice for embedded systems designers and engineers.
3. Write the steps that 8051 goes through in transmitting a character via TxD.
1. The byte character to be transmitted is written into the SBUF register
2. The start bit is transferred
3. The 8-bit character is transferred on bit at a time
4. The stop bit is transferred
It is during the transfer of the stop bit that 8051 raises the TI flag, indicating that the
last character was transmitted
5. By monitoring the TI flag, we make sure that we are not overloading the SBUF
If we write another byte into the SBUF before TI is raised, the un transmitted portion
of the previous byte will be lost
6. After SBUF is loaded with a new byte, the TI flag bit must be forced to 0 by CLR TI in
order for this new byte to be transferred
By checking the TI flag bit, we know whether or not the 8051 is ready to transfer
another byte
It must be noted that TI flag bit is raised by 8051 itself when it finishes data transfer
It must be cleared by the programmer with instruction CLR TI
If we write a byte into SBUF before the TI flag bit is raised, we risk the loss of a
portion of the byte being transferred
The TI bit can be checked by
The instruction JNB TI, xx Using an interrupt
4. write about the steps in programming the 8051 to receive character bytes serially.
1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode
2. (8-bit auto-reload) to set baud rate
3. TH1 is loaded to set baud rate
4. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-
bit data is framed with start and stop bits
5. TR1 is set to 1 to start timer 1
6. RI is cleared by CLR RI instruction
7. The RI flag bit is monitored with the use of instruction JNB RI, xx to see if an entire
character has been received yet
8. When RI is raised, SBUF has the byte, its contents are moved into a safe place.
9. To receive the next character, go to step 5.
Now the question is how to get the location of the pressed button?
1. First we have made all the Rows to Logic level 0 and all the columns to Logic level 1.
2. Whenever we press a button, column and row corresponding to that button gets shorted and
makes the corresponding column to logic level 0. Because that column becomes connected
(shorted) to the row, which is at Logic level 0. So, we get the column no. See main () function.
3. Now we need to find the Row no., so we have created four functions corresponding to each
column. Like if any button of column one is pressed, we call function row_finder1(), to find
the row no.
4. In row_finder1() function, we reversed the logic levels, means now all the Rows are 1 and
columns are 0. Now Row of the pressed button should be 0 because it has become connected
(shorted) to the column whose button is pressed, and all the columns are at 0 logic. So we have
scanned all rows for 0.
5. So whenever we find the Row at logic 0, means that is the row of pressed button. So now
we have column no (got in step 2) and row no., and we can print no. of that button using LCD
data function.
Same procedure follows for every button press, and we are using while (1), to continuously
check, whether button is pressed or not.
#include<reg51.h>
sbit C3 = P1^1;
sbit C2 = P1^2;
sbit C1 = P1^3;
sbit R4 = P1^4;
sbit R3 = P1^5;
sbit R2 = P1^6;
sbit R1 = P1^7;
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
display_port = command;
rs= 0;
rw=0;
e=1;
msdelay(1);
e=0;
display_port = disp_data;
rs= 1;
rw=0;
e=1;
msdelay(1);
e=0;
msdelay(10);
msdelay(10);
msdelay(10);
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('1');
if(R2==0)
lcd_data('4');
if(R3==0)
lcd_data('7');
if(R4==0)
lcd_data('*');
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('2');
if(R2==0)
lcd_data('5');
if(R3==0)
lcd_data('8');
if(R4==0)
lcd_data('0');
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('3');
if(R2==0)
lcd_data('6');
if(R3==0)
lcd_data('9');
if(R4==0)
lcd_data('#');
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('A');
if(R2==0)
lcd_data('B');
if(R3==0)
lcd_data('C');
if(R4==0)
lcd_data('D');
void main()
lcd_init();
while(1)
msdelay(30);
C1=C2=C3=C4=1;
R1=R2=R3=R4=0;
if(C1==0)
row_finder1();
else if(C2==0)
row_finder2();
else if(C3==0)
row_finder3();
else if(C4==0)
row_finder4();
In this project, we will have brief discussion on how to interface 16×2 LCD module to
AT89C51, which is an 8051-family microcontroller. We use LCD display for the displaying
messages in a more interactive way to operate the system or displaying error messages etc.
Interfacing 16×2 LCD with 8051 microcontroller is very easy if you understanding the working
of LCD.
A Brief Note on 16×2 LCD
16×2 Liquid Crystal Display which will display the 32 characters at a time in two rows (16
characters in one row). Each character in the display is of size 5×7-pixel matrix. This matrix
differs for different 16×2 LCD modules, if you take JHD162A, this matrix goes to 5×8. There
are 16 pins in the LCD module, the pin configuration us given below
So, by reading the above table you can get a brief idea how to display a character. For
displaying a character, you should enable the enable pin (pin 6) by giving a pulse of 450ns,
after enabling the pin6 you should select the register select pin (pin4) in write mode. To select
the register, select pin in write mode you have to make this pin high (RS=1), after selecting the
register select you have to configure the R/W to write mode that is R/W should be low
(R/W=0).
To send a command to the LCD just follows these steps:E=1; enable pin should be high
Components Required
11.0592MHz Crystal
2 X 33pF Capacitors
2 X 10 KΩ Resistors
1 KΩ X 8 Resistor Pack
10 KΩ Potentiometer
330Ω Resistor
Push Button
10μF/16V Capacitor
8051 Programmer
5V Power Supply
Connecting Wires
Initializing LCD To initialize LCD to the 8051 the following instruction and commands are
PROGRAM CODE for Interfacing 16×2 LCD with 8051 Circuit Diagram
#include<reg51.h>
#define lcd P0
sbit rs=P2^0;
sbit e=P2^1;
Servo motors are very useful in electronics and embedded systems. You can find the use of
Servo motor everywhere around you, they are used in toys, robots, CD tray of computer, cars,
aeroplane etc. The reason of this wide scope is that, servo motor is very reliable and precise.
We can rotate it to any particular angle. They are available in wide range, form high torque
motor to low torque motors. In this tutorial we are going to interface a servo motor to 8051
microcontroller (AT89S52).
First we need to understand the working principle of servo motors. Servo motor
works on PWM (Pulse width modulation) principal, means its angle of rotation is controlled
by the duration of applied pulse to its Control PIN. Basically servo motor is made up of DC
motor which is controlled by a variable resistor (potentiometer) and some gears. High
speed force of DC motor is converted into torque by Gears. We know that WORK= FORCE X
DISTANCE, in DC motor Force is less and distance (speed) is high and in Servo, force is High
and distance is less. Potentiometer is connected to the output shaft of the Servo, to calculate
the angle and stop the DC motor on required angle.
Servo motor can be rotated from 0 to 180 degree, but it can go up to 210 degree, depending on
the manufacturering. This degree of rotation can be controlled by applying a LOGIC level 1
pulse for a duration between 1ms to 2ms. A 1 ms can rotate servo to 0 degree, 1.5ms can rotate
to 90 degree and 2 ms pulse can rotate it to 180 degree. Duration between 1 to 2 ms can rotate
Servo motor to any angle between 0 to 180 degree.
Circuit Diagram and Working Explanation
Servo motor has three wires Red for Vcc (power supply), Brown for Ground, and Orange is
control wire. Control wire can be connected to 8051, we have connected it to Pin 2.1 of 8051.
Now we have to keep this pin to Logic 1 for 1ms to rotate it 0 degree, 1.5ms for 90 degree, 2
ms for 180 degree. We have used on chip Timers of 8051 to create delay. We have created
delay of 50us through the function “servo_delay”, and used “for” loop to create delay in
multiple of 50us.
We are using Timer 0 and in Mode 1, so we have put 01H in TMOD register. Mode 1 is 16-bit
timer mode and TH0 contain High byte and TL0 contain Low byte of 16-bit timer. We have
put FFD2 in 16-bit timer register, FF in TH0 and D2 in TL0. Putting FFD2 will create the delay
of approx. 50 us with the crystal of 11.0592MHz. TR0 and TF0 are the bits of TCON register,
TR pin used to start timer when set and stop when reset (0). TF is overflowing flag, set by
hardware when overflow and need to reset it by software. Basically, TF tells the completion of
Timer, and set by hardware when 16 timer transit from FFFFH to 0000H. You can read about
the “8051 Timers” to understand the calculation of value in timers registers, to create the 50 us
delay.
Now when measured from CRO, 13 loops of servo_delay function will give the delay of 1ms,
so we have started from 1ms (13 loops) and gone to 2 ms (26 loops) to rotate the servo from 0
to 180 degree. But we have slowly incremented the delay from 1ms, we have divided 1ms to 2
ms window into 7 parts like 1.14ms, 1.28 ms, 1.42ms and so on, so the servo will rotate in
multiple of approx. 26 degrees (180/7). After 180 it will automatically return to 0 degree.
#include<reg51.h>
sbit output=P2^0;
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
int m;
for(m=0;m<times;m++)
TH0=0xFF;
TL0=0xD2;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
void main()
int n;
output=0;
while(1)
{
for(n=13;n<28;n=n+2)
output=1;
servo_delay(n);
output=0;
servo_delay(260);
msdelay(200);
9. Write a program to interface DAC AD7523 with to generate Triangle wave of period
1 ms with Vmax 5v.
ORG C100H
X DW 00FFH ; the fall of rise and time I proportional
directly to the value.
ORG C000H
PA EQU D8H
PB EQU D9H
PC EQU DAH
CTRL EQU DBH
MVI A, 88H
OUT CTRL ; Purpose to configure 8255 ports
; The next 7 instructions will generate rising portion
of the triangular waveform.
; And it is done by sending to DAC through Port A
values from 00H to FFH,
; in steps of 01. Also the increment will be done after
a small time delay here.
POP PSW
INR A
JNZ ASCEND
DESCEND: OUT PA
PUSH PSW
CALL DELAY
POP PSW
DCR A
CPI FFH
JNZ DESCEND
JMP LOOP
; These Subroutines are used only for the generation of
delay
; which is proportional to all the contents of word
located at X.
DELAY: LHLD X
AGAIN: DCX H
MOV A, H
ORA L
JNZ AGAIN
RET
10. Write a program for 8051 Microcontroller to arrange the given 10 numbers in
ascending order.
Algorithm
To arrange the numbers in ascending order, first compare two numbers.
If first number > second number, then interchange these numbers.
Then compare second number and third number, interchange if needed.
Continue same process for remaining numbers in the array.
We have to repeat process until we get arranged data in ascending order.
For this process, two counters are required.
Byte counter, for accessing numbers from array.
Pass counter for repeating the comparison process.
Step 1: Initialize a counter for comparison (Pass counter).
Step2: Initialize memory pointer to read number from the array.
Step3: Initialize byte counter.
Step 4: Read numbers from array.
Step 5: Compare two numbers.
Step 6: If number less than or equal to next number, then go to step 8.
Step 7: Replace number with next number which is largest.
Step 8: Increment memory pointer to read next number in the array.
Step 9: Decrement byte counter by 1.
Step 10: If byte counter is not equal to zero then go to step 4.
Step 11: Decrement pass counter by 1.
Step 12: If pass counter is not equal to zero then go to step 2.
Step 13: Stop.
MOV A, 0F0H
MOVX @DPTR, A
then go to REPEAT.
DJNZ R0, REP1 ; Decrement pass counter if not zero then go to REP1
SAMPLE PROGRAMS: