Professional Documents
Culture Documents
OBJECTIVES:
To study the Architecture of P8085 & C 8051
To study the addressing modes & instruction set of 8085 & 8051.
To introduce the need & use of Interrupt structure 8085 & 8051.
To develop skill in simple applications development with programming
8085 & 8051
To introduce commonly used peripheral / interfacing
UNIT I 8085 PROCESSOR 9
Hardware Architecture, pin outs Functional Building Blocks of Processor Memory
organization I/O ports and data transfer concepts Timing Diagram Interrupts.
UNIT II PROGRAMMING OF 8085 PROCESSOR 9
Instruction -format and addressing modes Assembly language format Data transfer, data
manipulation & control instructions Programming: Loop structure with counting & Indexing
Look up table - Subroutine instructions - stack.
UNIT III 8051 MICRO CONTROLLER 9
Hardware Architecture, pin outs Functional Building Blocks of Processor Memory
organization I/O ports and data transfer concepts Timing Diagram Interrupts-Comparison
to Programming concepts with 8085.
UNIT IV PERIPHERAL INTERFACING 9
Study on need, Architecture, configuration and interfacing, with ICs: 8255,
8254,8237,8251,8279, - A/D and D/A converters &Interfacing with 8085 & 8051.
8259,
The MPU uses the address bus to perform the first function: identifying a
peripheral or a memory location.
The data bus is a group of eight lines used for data flow.
These lines are bi-directional - 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.
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.
Control Bus
The control bus carries synchronization signals and providing timing signals.
The MPU generates specific control signals for every operation it performs.
These signals are used to identify a device type with which the MPU wants to
communicate.
Registers of 8085
The 8085 have six general-purpose registers to store 8-bit data during
program execution.
These registers are identified as B, C, D, E, H, and L.
They can be combined as register pairsBC, DE, and HLto perform some
16-bit operations.
Accumulator (A)
Flags
The ALU includes five flip-flops that are set or reset according to the result of
an operation.
The microprocessor uses the flags for testing the data conditions.
They are Zero (Z), Carry (CY), Sign (S), Parity (P), and Auxiliary Carry (AC)
flags. The most commonly used flags are Sign, Zero, and Carry.
The bit position for the flags in flag register is,
D7
D6
D5
D4
D3
D2
D1
D0
S
AC
CY
The function of the program counter is to point to the memory address of the
next instruction to be executed.
When op code is being fetched, the program counter is incremented by one
to point to the next memory location.
Interrupt Control Unit: It receives hardware interrupt signals and sends an acknowledgement
for receiving the interrupt signal.
S
1
0
0
1
0
1
1
3 output states are high & low states and additionally a high impedance
state.
When enable E is high the gate is enabled and the output Q can be 1 or 0 (if
A is 0, Q is 1, otherwise Q is 0). However, when E is low the gate is disabled
and the output Q enters into a high impedance state.
E
A
Q
State
1(hig
0
1
High
h)
1
1
0
Low
0(low
0
0
High impedance
)
0
1
0
High impedance
For both high and low states, the output Q draws a current from the input of
the OR gate.
When E is low, Q enters a high impedance state; high impedance means it is
electrically isolated from the OR gates input, though it is physically
connected. Therefore, it does not draw any current from the OR gates input.
When 2 or more devices are connected to a common bus, to prevent the
devices from interfering with each other, the tri state gates are used to
disconnect all devices except the one that is communicating at a given
instant.
The CPU controls the data transfer operation between memory and I/O
device. Direct Memory Access operation is used for large volume data
transfer between memory and an I/O device directly.
The CPU is disabled by tri-stating its buses and the transfer is effected
directly by external control circuits.
HOLD signal is generated by the DMA controller circuit. On receipt of this
signal, the microprocessor acknowledges the request by sending out HLDA
signal and leaves out the control of the buses. After the HLDA signal the DMA
controller starts the direct transfer of data.
READY (input)
Memory and I/O devices will have slower response compared to
microprocessors.
Before completing the present job such a slow peripheral may not be able to
handle further data or control signal from CPU.
The processor sets the READY signal after completing the present job to
access the data.
The microprocessor enters into WAIT state while the READY pin is disabled.
8. Single Bit Serial I/O ports:
SID (input)
- Serial input data line
SOD (output)
- Serial output data line
A microprocessor will have its own address space for accessing physical memory. The memory
locations that are directly addressed by the microprocessor is called physical memory space.
For example a microprocessor like 8085 has 16 address lines, and it can access a physical
memory space of 64K starting from 0000H to FFFFH as shown in Table 1.3.1. The
process of interfacing memories to microprocessor and allocating address to each memory
location is called memory mapping. The complete address space may be considered as a
single memory block. But practically, when ICs are used as memory devices, instead of a
single IC (Integrated Chip), few devices that fit into the address space will be used. This is
due to the fact a microprocessor based system requires at least one ROM/EPROM and a
RAM. For example instead of using a memory device of size 64KB (Kilo Bytes), we can use
8 memory devices with a capacity of 8KB each. This will reduce the chip replacement cost
while servicing the microprocessor-based system. When memory blocks are used, to access all
the locations in a block n address lines are needed so that
n
2 =8K
3
=2 K
3
10
=2 x2
= 213
Therefore n = 13
Address Decoding and memory mapping
Memory address decoding is nothing but to assign an address for each location in the memory
chip. The data stored in the memory is accessed by specifying its address. Memory address
can be decoded in two ways
i)
Absolute or Fully decoding
and
ii)
Linear Select or Partial decoding
There are many advantages in absolute address decoding. They are
i
Each memory location has only one address, there is no duplication in the
address
ii
Memory can be placed contiguously in the address space of the
microprocessor
iii
Future expansion can be made easily without disturbing the existing
circuitry
There are few disadvantages in this method
i
Extra decoders are necessary
ii
Some delay will be produced by these extra decoders.
The main advantage of linear select decoding is its simplified decoding circuit. This reduces
the hardware design cost. But there are many disadvantages in this decoding.
i
Multiple addresses are provided for the same location
ii
Complete memory space of the microprocessor is not efficiently used
iii
Adding or interfacing ICs with already existing circuitry is difficult.
Absolute Address Decoding
16
The 8085 microprocessor has 16 address lines. Therefore it can access 2
locations in the
physical memory. If all these lines are connected to a single memory device, it will decode
16
these 16 address lines internally and produces 2 different addresses from 0000H to FFFFH
so that each location in the memory will have a unique address as shown in table 1 . 3.1 and
figure 1 . 3.1. This is called absolute address decoding. Figure 1 . 3.1 is called the memory
map of 8085 address space and it shows how each location in the physical memory gets
an address from the address space of the microprocessor.
A15 A14 A13
0
0 0
0
A11 A10 A9
0 0 0 0
A7 A6 A5 A4 A3 A2
A0 Hex Address
0 0 0 0 0 0 0 0
0000H
0
0
0
0
-
1
1
0
0
-
1
1
0
0
0
0
1
1
0
0
-
1
1
1
1
0
0
-
1
1
0
0
0
0
0
0
-
0
0
-
0
0
-
0
0
-
0 0
0 1
- - -
1
1 1 1
1 1 1 1
1
1 1 1
1 1 1 1
Table 1.3.1: Memory Address
1
1
1
0
0001H
0002H
- - - - -
0
1
FFFEH
FFFFH
Bloc
k No A15A14A13
A12
1
0 0 0
0
A11 A10
A9A8
0 0
0
Hex
A7 A6 A5 A4 A3
A1 A0 Address
range
A2
0 0
0 0 0 0 0 0 0000H to
2
3
4
5
6
7
8
0 0
0 0
0 0
0 1
0 1
0 1
0 1
1 0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1FFFH
2000H to
3FFFH
4000H to
5FFFH
6000H to
7FFFH
8000H to
9FFFH
A000H to
BFFFH
C000H to
DFFFH
E000H to
FFFFH
require at least few RAM locations to store temporary data. Specifically there should be a
RAM for stack operations. So, though we are using eight memory chips of 8KB size each, at
least one of the eight ICs must be an EPROM and it should be placed at the starting
address of 0000H. The memory map for this case can be given as shown in figure 1.3.2. The
EPROM chip must be selected using the chip select signal CS1 and the RAM1 chip must be
selected using CS2. The memory interface diagram may be given as shown in Figure 1.3.4.
In this type of memory interfacing, all the address lines (A0 to A15) have been used. Each
location in the memory will have a single address. This type of address decoding is
called as absolute or fully decoded addressing.
Most of the microprocessor based systems do not use the complete 64 KB memory space.
Even one EPROM and a RAM will be sufficient. For example in the memory map shown
in figure 1 . 3.2, if only the EPROM and RAM 2 are used in the practical system, the
memory map of such a system can be given as shown in figure 1.3.5. Still each location has
single address. Therefore it is also called absolute address decoding. The main advantage of
this type of decoding is, you can add memory devices for this system without disturbing the
already connected devices. The memory interface diagram for this case is given in figure
1.3.6.
A15 A1 A12 A1 A1 A9 A8 A A
0 0 0 0 0 0 0 0
0 0
0
0
0
1
0
0
1
0
1
0
1
0
1 1
0 0
1 1
0 0
0
1
1
0
0
0
1
0
1
0
1
0
1 1
0 0
1 1
0 0
1
1
0
1
0
0
1
0
1
0
1
0
1 1
0 0
1 1
0 0
1 1
7
1
Hex Address
A5 A4 A3 A A0 range
0 0 0 0 0 0 0000H
to
1 1 1 1 1 1 1FFFH
0 0 0 0 0 0 4000H
to
1 1 1 1 1 1 5FFFH
0 0 0 0 0 0 8000H
to
1 1 1 1 1 1 9FFFH
0 0 0 0 0 0 C000H
to
1 1 1 1 1 1 DFFFH
The same EPROM is selected both for the address range 0000H to 1FFFH and 8000H to
9FFFH. This is due to the signals A13 and A14 which have same values in both the cases
and hence activates the same chip select signal CS1. Similarly the RAM is selected both
for the address range 4000H to 5FFFH and C000H to DFFFH. The memory map for this case
is as shown in figure 1.3.9.
NB: Instead of connecting the RD or WR signals to the input or output of the address
decoder, the best practice to avoid bus contention is to connect the RD signal to the OE pin
of EPROM/RAM and WR signal to R/W pin of RAM.
Example 1 . 3.1:
Interface a 4K EPROM, one 4K RAM and one 8K RAM to a microprocessor with the
following Memory Map.
A11) must be used. Since 8085 has 16 address lines the decoding can be indicated as shown
below.
Block No
A1 A1 A1 A12 A1 A1 A A8 A7 A A A4 A3 A
6 5
2
5 4 3
1 0 9
0 0 0 0
0 0 0 0
0 0 0 0
0 0
0
0
0 0 0
0 0 1
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1
0 0
0
0
0 0 1
0 1 0
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1
0 0
0
0
0 1 0
0 1 1
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1
0 0
0
0
0 1 1
1 0 0
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1
0 0
0
0
1 0 0
1 0 1
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1
0 0
1 0 1
1 1
1 1
1 1 1
1 1 1 1
:
:
0
0 0
0
15
1 1
0 0 0
Hex Address
A A0 Range
1
0 0 0000H
to
1 1 0FFFH
0 0 1000H
to
1 1 1FFFH
0 0 2000H
to
1 1 2FFFH
0 0 3000H
to
1 1 3FFFH
0 0 4000H
to
1 1 4FFFH
0 0 5000H
to
1 1 5FFFH
0 0 0 0
F000H
to
1 1 1 1
1 1 1 1
1 1 1 1 FFFFH
Table 3.5: Memory Map
The 74LS138 decoder has three input pins marked as CBA when all these three pins are 0
then the output pin O0 will be activated i.e. O0 becomes zero. When CBA is 001 the O1
will be activated and all other output pins will be at high state. i.e. any one of the output pins
O0 to O7 is selected based on the input A, B and C and this will happen only if the control
pins G1, G2 and G3 are properly activated. Table 3.5 shows that address line A15 is
always zero for the address range 0000H to 6FFFH. So this can be connected to G3 pin of
the 74LS138. The output pins of 74LS138 must be selected only for memory operations.
During memory operations IO/M = 0. So IO/ M is connected to G2 pin of the 74LS138 and
hence for any IO operation the chip 74LS138 will not activate any of the output pins.
The pin G1 is connected to +5V through a resistor to enable 74LS138.
The O0 pin of 74LS138 is connected to the chip select (CS) signal of the 4K EPROM.
This allows selecting this EPROM chip when the microprocessor sends address in the range
0000H to 0FFFH. Similarly O1 pin of 74LS138 is connected to the CS of 4K RAM. Since
no memory chip is connected in the address range 2000H to 3FFFH, the output pin Q2 is
left free. The 8K RAM requires address from 4000H to 5FFFH and these addresses are
covered by Q4 and Q5 pins. So these two pins are connected to a two input AND gate. The
output of the AND gate is connected to the chip select pin of the RAM and this CS will be
activated (active low) if either Q4 or Q5 is low.
i.e. the output of the AND gate will be 0 for the addresses 4000H to 5FFFH and hence the 8K
RAM chip is selected for this address range.
C B A
Output pin Activated
0 0 0
O0
0 0 1
O1
0 1 0
O2
0 1 1
O3
1 0 0
O4
1 0 1
O5
1 1 0
O6
1 1 1
O7
Table 3.1: Function Table of 74LS138
The address lines A0 to A11 of 8085 MPU must be connected to the corresponding address
pins of the memory chip and the data lines D0 to D7 of MPU must be connected to the
corresponding data pins of all the memory chips. Since 8K RAM has 13 address lines in
addition to the twelve address lines (A0 to A11) A12 of MPU must also be connected to
the A12 pin of the 8K RAM. You note that bus contention is not addressed in this circuit.
1
1 1 1
To avoid bus contention, the RD or WR signal of the microprocessor is used along with
the address decoding to produce the CS signal for the memory. The RD or WR signal starts
approximately in the middle of the T2 state and available up to the end T3 state. If the
microprocessor operates at 3 MHz, these signals are available for approximately 1.5 T state
or 500 ns (1.5 / 3 MHz = 0.5 micro seconds) and hence the memory access time should be
less than 500 ns. If the memory access time is more than this value the data cannot be read.
If a low speed memory has access time greater than this value, Wait cycles are introduced
between T2 and T3. In such a case, the CS select signal need not be delayed until RD or WR
signals are issued by the microprocessor. The memory can decode the address as soon as it gets
the address from the microprocessor. In this case the total delay introduced will be equal to
the sum of the delays introduced by the decoder, wait cycles and the delay introduced due
to memory access time. For example 2716 EPROM has access time of 450 ns and therefore it
can be directly interfaced with 3 MHz 8085, but one wait cycle is necessary if it is
interfaced with a microprocessor operating at 5 MHz. A low speed memory can also be
interfaced with a high speed processor by using low frequency crystal but this will slow down
not only the memory read/write operation but all activities of the processor.
The READY pin of 8085 processor is used to introduce wait states. For normal operations
of the processor this pin should be connected to logic high. When this pin is made low, the
processor will enter into wait state until it is made high again. A special circuitry called Wait
State Generator as shown in figure 1.3.16 is required for this purpose. This circuit will
introduce a wait state equal to one T-state of the processor cycle as shown in figure
1.3.17. The ALE signal fed to the clock input of the first D-type flip-flop will transfer the
logic high input (+5V) placed on its D0 pin to Q0 during its positive edge. The Q0 output is
connected to D1 input of the second flip-flop. So, the logic high output on Q0 will be
transferred to the output Q1 of the second flip-flop during the positive edge of T2 state. The
complement value of Q1 is available on Q1 pin of the second flip-flop. This will reset the
first flip-flop i.e. Q0 will become logic 0 as shown in figure 1.3.17. At the same time since
Q1 has been connected to the READY pin of the processor, the processor enters into wait
state. It will remain in that state until Q1 becomes high. This extends the length of the RD
signal as shown in figure 1.3.17 and allows memory to take one more clock period time to
place the contents on the bus. The logic 0 placed on D1 pin during this time will be transferred
to Q1 in the positive edge of the next clock cycle (T3 state). This will make Q1 logic high
and hence the READY signal becomes high and the processor continues its work. It should be
noted that wait state can be introduced in any machine cycle of 8085 except in bus idle cycle.
The 8085 checks the READY signal at the second T-state of every machine cycle.
the chip select signal CS3 will select RAM 2 if the jumper connects B and C and it will select
RAM 3 if the jumper connects A and B. Similarly CS4 will select RAM 4 if the port bit is
zero and RAM 5 if the port bit is one. The main difference between jumper selection and
port bit selection is the manual selection in the first case and automatic or program
activated selection in the second case.
Opcode
3E
9A
Mnemonic
MVI A, 9AH
The Timing diagram shown in figure 2.8 indicates that the MVI A, 9AH instruction
stored at the address 4100H is executed with two machine cycles i.e. one Opcode
Fetch cycle and one Memory Read cycle. The opcode fetch cycle uses 4 clock signals
(T1, T2, T3 and T4) and memory read cycle uses 3 clock signals. Each clock signal (a
logic low part and a logic high part) is called a T-State. So an opcode fetch machine
cycle has 4T states. Generally the opcode fetch cycle of any 8085 instruction uses 4T
states. But some instructions like INX H uses 6T states for opcode fetch.
All operations with in 8085 are synchronized with the clock signal. The frequency of the
clock signal depends on the crystal connected with 8085. If a 6 MHz crystal is
connected, a 3 MHz clock will be generated i.e. the clock is internally divided by 2. This
3 MHz clock is called the operating frequency of the Microprocessor. In the above
example the instruction is executed using 7 T-stats. If F is the operating frequency in Hertz
and T is the time taken by a T-state then,
T = 1/ F Seconds----------------------------------------------------------------2.1
If an instruction has N number of T-states, then the execution time for that instruction is
given by
Execution Time = N x T Seconds------------------------------------------2.2
In the above example the operating frequency is 3MHz; therefore each T-state will have
6
a time equal to 1/3MHz i.e. 1/3x10 seconds or 1/3 micro seconds. Hence this instruction
will be executed in 7 x 1/3 microseconds.
The table given below shows the status signals for each type of machine cycle and the
number of T-stats required for each machine cycle.
Opcode Fetch Cycle
At T1 state of figure 2.8, the microprocessor starts the process of reading the first byte of
an instruction (opcode) stored in the memory and it sets the signals IO/M=0, S1=1,
S0=1 to indicate an Opcode Fetch cycle (refer Table 2.2 for the states of these signals
for other operations). The Microprocessor places the higher order byte of the address
(41H) on the address lines A15 A8 and the lower order address on the multiplexed lines
AD7 - AD0. Since this address exists only during T1 period this address must be captured
and stored using an external latch as explained in section 2.3.1. So the ALE (Address
Latch Enable) signal is generated during this T1 time, which is used to enable the
external latch to capture the address and this signal is disabled at the end of the T1 as
shown in figure 2.8.
At T2 state, the processor issues a RD signal which enables the memory to place the data
(stored in the address provided during T1 state) on AD7 - AD0 lines. This data goes in
to the instruction register. At T2 state the program counter is incremented by one. The RD
signal extends up to the end of T3 state. The arrow marks indicate that the point at the tail
activates point at the head i.e. until the tail point occurs the head point is blocked.
This is necessary because the memory should not place the opcode immediately after it
receives the address; it should be sufficiently delayed otherwise both address and opcode
will be placed at the same time on the same lower order data lines during T1 state.
At T4 state 8085 microprocessor decodes the opcode and finds out that a second byte
(data 9AH) is to be read from the memory. During this time the contents of the bus A15
A8 are not important and the data bus AD7 AD0 goes in to high impedance state (Hi Z
state). High impedance state indicates that AD7 AD0 pins of the Microprocessor isolates
it from other ICs such as memory and ports.
The status signals for opcode fetch cycle will be set to IO/M =0 S0 = 1 and S1 =1 as per
the details given in table 2.2.
Memory Read cycle
The second machine cycle of this instruction is Memory Read cycle. This cycle consists
of 3T states.
At T1 state of this cycle, Microprocessor issues IO/M=0, S1=1, S0=0. Microprocessor
places the next memory address 4101H on the bus i.e. the microprocessor places the higher
order address 41H on the bus lines A15 A8 and the lower order address 01H on AD7
AD0 lines and makes ALE signal high to latch the lower order address.
At T2 state ALE will be in deactivated state. So the lower order address latched already
will be available on the output of the latch but the lines AD7 AD0 need not have that
address. At the rising edge of T2 state the memory places the data (9AH) stored in the
corresponding address (4101H) on AD7 AD0 lines. At the same time the
Microprocessor issues read signal (RD becomes 0) and the program counter is
automatically incremented by one.
At T3 state 8085microprocessor reads the data from AD7 AD0 bus and stores it in the
accumulator.
The status signals for memory read cycle will be set to IO/M =0 S1 = 1 and S0 =0 as per
the details given in table 2.2.
NB: Memory Write machine cycle will be generated when the microprocessor wants to
store any byte in the memory. In this cycle instead of RD signal, the microprocessor issues
WR signal and data flows from microprocessor to memory. Other operations are same.
You note that when RD signal becomes active i.e. 0, the WR signal will be at logic high
and vice versa. During T1 and T4 states both RD and WR signals will be at logic 1. For
I/O operations IO/M signal will be at logic high, the status signals S0 and S1 will also
change as per the details given in table 2.2. More examples on timing diagram can be
found in chapter 5.
Generally to draw
needed.
a
b
c
Table 2.3 shows some of the important instructions and the machine cycles used for
executing those instructions.
Instruction
(Mnemonic)
STA 4100H
Opcode
Machine Cycles
32 00 41
LXI H, 4567H
21 67 45
MVI A, 80H
3E 80
LHLD 4200H
2A 00 42
OUT 80H
D3 80H
Opcode Fetch
Memory Read
Memory Read
Memory Write
Opcode Fetch
Memory Read
Memory Read
Opcode fetch
Memory Read
Opcode Fetch
Memory Read
Memory Read
Memory Read
Memory Read
Opcode Fetch
Memory Read
I/O Write
Total no. of T
states
4+3+3+3=13
4+3+3=10
4+3=8
4+3+3+3+3=16
4+3+3=10
Call 4300H
CD 00 43
RET
C9
DAD B
09
Opcode Fetch
Memory Read
Memory Read
Memory Write
Memory Write
Opcode Fetch
Memory Read
Memory Read
Opcode Fetch
Bus Idle
Bus Idle
4+3+3+3+3=16
4+3+3=10
4+3+3=10
are
processor
used
has
for
five
conditional
hardware
execution
of
the
program.
The
8085
implementing serial data transfer. The data and the lower order address are
time multiplexed. The status signals indicate the type of operation
the
Interrupt Priority:
when more than one interrupts occur at the same time, then processor responds to
them according to the following priority
TRAP(highest)
RST 7.5
RST 6.5
RST 5.5
INTR (lowest)
Interrupt vector locations:
TRAP 0024H(it is same as RST 4.5)
RST 5.5 002CH
RST 6.5 0034H
RST 7.5 003CH
To get the vector location for RST interrupts, interrupt value is multiplied by 8 and the
result is converted to hexadecimal notation. For example RST 5.5 instruction,
multiply 5.5*8=44. 44 in hexadecimal notation is 2CH. So vector address is 002CH.
Trigger levels:
TRAP is level and edge triggered
RST 7.5 is positive edge triggered
RST 6.5, RST 5.5 are level triggered.
Masking of interrupts:
SIM instruction sets mask pattern for RST 5.5, RST 6.5, RST 7.5.
SIM instructions reads accumulator bit pattern and accordingly masks the interrupts.
The bit pattern is shown in below figure. It also resets D flip-flop of RST 7.5 interrupt.
And it also implements serial I/O.
Hardware interrupts:
(5) INTR
TRAP:
RST 7.5:
The RST 7.5 interrupt is a maskable interrupt.
It has the second highest priority.
It is edge sensitive. ie. Input goes to high and no need to maintain high
state until it recognized.
Enabled by EI instruction.
Enabled by EI instruction.
The RST 6.5 has the third priority whereas RST 5.5 has the fourth priority.
INTR:
Enabled by EI instruction.
Non- vectored interrupt. After receiving INTA (active low) signal, it has to
supply the address of ISR.
It has lowest priority.
It is a level sensitive interrupts. ie. Input goes to high and it is necessary
to maintain high state until it recognized.
The following sequence of events occurs when INTR signal goes high.
1. The 8085 checks the status of INTR signal during execution of each
instruction.
2. If INTR signal is high, then 8085 complete its current instruction and sends
active low interrupt acknowledge signal, if the interrupt is enabled.
3. In response to the acknowledge signal, external logic places an instruction
OPCODE on the data bus. In the case of multibyte instruction, additional interrupt
acknowledge machine cycles are generated by the 8085 to transfer the
additional bytes into the microprocessor.
4. On receiving the instruction, the 8085 save the address of next instruction on
stack and execute received instruction.
SIM and RIM for interrupts:
The 8085 provide additional masking facility for RST 7.5, RST 6.5 and RST
5.5 using SIM instruction.
The status of these interrupts can be read by executing RIM instruction.
The masking or unmasking of RST 7.5, RST 6.5 and RST 5.5 interrupts can
be performed by moving an 8-bit data to accumulator and then executing
SIM instruction.
The format of the 8-bit data is shown below.
Execute operation:
The op-code fetched from the memory goes to the instruction register (IR).
From the instruction register it goes to the decoder circuitry which decodes the
instruction. After the instruction is decoded, execution begins. If the operand is in
general purpose registers execution is immediately performed.
The time taken for decoding and execution is one clock cycle. If an instruction
contains data or operand and address which are still in the memory, the
microprocessor has to perform some read operations to get the desired data. After
receiving the data it performs execute operation. A read cycle is similar to a fetch
cycle. In case of a read cycle the quantity received from the memory are data or
operand address instead of an op-code. In some instructions write operation is
performed. In write cycle data are sent from the microprocessor to the memory or an
output device. Thus we see that in some cases an execute cycle may involve one or
more read or write cycles or both.
Twobyte instructions: At two byte instruction is one which contains an 8-bit opcode and 8-bit operand (Data).
Ex: 1. MVI A, 09
2. ADD B, 07
3. SUB A, 05
DATA FORMATS: The 8085 is an 8-bit microprocessor which process only binary
numbers. But it is very difficult to understand these binary numbers by a common
user. So, we have to code these binary numbers into different data formats. The
commonly known data formats are ASCII, BCD, signed integers and unsigned
integers. The ASCII code is a 7-bit alpha-numeric code that represents decimal
numbers, English alphabets and certain special characters. The ASCII stands for
American Standard code for Information Interchange
The term BCD stands for binary coded decimal, used for decimal numbers
from 0-9.An 8-bit register can store two BCD numbers. A signed integer is either a
D7
positive or a negative number. In 8085 microprocessor the most significant bit
is
used for the sign. Here 0 denotes positive sign and 1 denotes the negative sign. An
integer without a sign can be represented by all the 8-bits in a microprocessor
register. So, the largest number that can be processed at one time is FFH. The
numbers larger than 8-bits like 16, 24, 32 bits can be processed by dividing them in
groups of 8-bits.
CLASSIFICATION OF INSTRUCTIONS
An instruction is a binary pattern designed inside a microprocessor to perform
a specific function. The entire group of instructions, called the instruction set,
determines what functions the microprocessor can perform. The 8085
microprocessor instruction set has 74 operation codes that result in 246 instructions.
This instruction set includes all the 8080A instructions plus two additional instructions
namely SIM and RIM.
The instruction set of 8085 microprocessor is classified into five groups. They are:
1. Data transfer (copy) group.
2. Arithmetic group
3. Logic group
4. Branch control group
5. Machine control and I/O group.
Arithmetic instructions modify all the flags according to the data conditions of the
result. The INR and DCR instructions affect all flags except the carry flag.
Logical Group of Instructions:
Since the microprocessor is a programmable logic chip, it can be perform all
the logic functions of the hard-wired logic through its instruction set. The 8085
processor can perform the logic instructions like, AND, OR, NOT (Complement) and
X-OR (Exclusive OR) etc The mnemonics of these instructions are given below.
ANA :
ANI :
ORA :
OR :
XRA :
XRI :
CMA :
All the logic operations are performed in relation to the contents of the accumulator.
The CMA instruction does not affect any flags. The executions of the logical
instruction do not affect the contents of the operand register.
Branch Instructions
These instructions are very important because they allow the microprocessor
to change the sequence of a program either conditionally or unconditionally. The
conditional branch instructions transfer the program to the specified label when
certain condition is satisfied. The unconditional branch instructions transfer the
program to the specified location unconditionally.
We know that the microprocessor is a sequential machine. So, it executes machine
codes from one memory location to the next. Branch instructions instruct the
microprocessor to go to a different memory location and the processor continues
executing machine codes from the new location. The address of the new locations
either specified explicitly or provided by the microprocessor or some times by
additional hardware. The Branch instructions are classified into three categories.
They are
(a). Jump instructions
(b). Call and return instructions
(c). Restart instructions.
Jump instructions specify memory locations explicitly and they are 3-byte
instructions. These Jump instructions are of two types. They are , Unconditional
Jump and Conditional Jump.
Unconditional Jump:
This is similar to Unconditional Go to statement in BASIC. When this
instruction is executed the 16-bit address available immediately in the instruction is
loaded into the program counter , so that the next sequence of instruction execution
starts from this location. This Unconditional Jump instruction enables the
programmer to create continuous loops.
JMP (16 bit address). So, this is a 3-byte instruction where the first
byte is op-code and the second, third bytes specify memory address.
For example, the instruction JMP 8500H, instructs the microprocessor to go to the
memory location8500H unconditionally. Sometimes, the jump location is specified
using a label also.
Conditional Jump:
Instruction
JC (16 bit Addr)
JNC (16 bit Addr)
JZ (16 bit Addr)
JNZ (16 bit Addr)
JP (16 bit Addr)
JM (16 bit Addr)
JPE (16 bit Addr)
JPO (16 bit Addr)
Description
Jump on carry (if CY=1)
Jump on no carry (if CY=0)
Jump on Zero (if Z=1)
Jump on no Zero (if Z=0)
Jump on plus (if D7=0; S=0)
Jump on minus (if D7=1; S=1)
Jump on Even Parity (if P=1)
Jump on Odd Parity (if P=0)
Mnemonics
RST 0
RST1
RST2
RST3
RST4
RST5
RST6
RST7
Hex code
C7
CF
D7
DF
E7
EF
F7
FF
IN (port address)
OUT (port address)
This port address is an 8-bit address. In both these instructions the default register is
Accumulator.
Ex: (i) IN 01H. This instruction will copy the contents into the Accumulator through
the port whose address is 01H. It takes three machine cycles and takes 10 states.
The op-code is DBH.
(ii)OUT 02H. This instruction sends the contents of Accumulator to the outport
whose address is 02H. It is a two byte instruction which requires 10 states. The opcode for this instruction is D3H.
ADDRESSING MODES
Majority of the instructions of 8085 microprocessor requires an operand
(either data or address) on which the intended operation can be performed. Some
instructions may require only one operand and some other instructions require two
operands for its instruction execution. The speed of execution mainly depends on the
position of the operand in the instruction. The scheme involved in identifying the
position of operands in an instruction is known as addressing mode.
There are five addressing modes 8085 processor. They are
i. Immediate addressing mode
ii. Direct addressing mode
iii. Register addressing mode.
iv. Register indirect addressing mode.
v. Implicit addressing mode.
(i). Immediate Addressing mode: The mode of addressing in which the operand is
a part of the instruction itself is known as Immediate Addressing mode. If the
immediate data is 8-bit, the instruction will be of two bytes. If the immediate data is
16 bit, the instruction is of 3 bytes.
Ex: (1). ADI DATA ; Add immediate the data to the contents of the accumulator.
(2).LXIH 8500H : Load immediate the H-L pair with the operand 8500H
(3). MVI 08H
; Move the data 08 H immediately to the accumulator
(4). SUI 05H
; Subtract immediately the data 05H from the accumulator
(ii) Direct Addressing mode: The mode of addressing in which the 16-bit address
of the operand is directly available in the instruction itself is called Direct Addressing
mode. i.e., the address of the operand (data) is available in the instruction itself. This
is a 3-byte instruction.
Ex: (1). LDA 9525H ; Load the contents of memory location into Accumulator.
(2). STA 8000H ; Store the contents of the Accumulator in the location 8000H
(3). IN 01H ; Read the data from port whose address is 01H.
(iii). Register addressing modes: The mode, in which the operand is in one of the
general purpose registers, is known as the register addressing mode.
Ex: (1). MOV A, B;
Move the contents of B register to A register.
(2). SUB D;
Subtract the contents of D register from Accumulator.
(3). ADD B, C; Add the contents of C register to the contents of B register.
(iv). Register indirect addressing modes: The 16-bit address location of the
operand stored in a register pair (H-L) is given in the instruction. The address of the
operand is given in an indirect way with the help of a register pair. Hence it is called
Register indirect addressing mode
Ex: (1).LXIH 9570H; Load immediate the H-L pair with the address of the location
9570H
MOV A, M; Move the contents of the memory location pointed by the H-L pair
to accumulator
(v). Implicit Addressing mode: The mode of instruction which do not specify the
operand in the instruction but it is implicated is known as implicit addressing mode.
i.e., the operand is automatically considered to be in the Accumulator.
Ex: (1).CMA; complement the contents of Accumulator
(2).CMC; Complement carry
(3). RLC; Rotate Accumulator left by one bit
(4). RRC; Rotate Accumulator right by one bit
(5). STC; Set carry.
Beginning to use 8085 Assembly Language
The Intel 8085 microprocessor has 7 eight bit registers. These registers can hold a quantity as
large as 0FF H, 11111111 B, or 255 Decimal. These are 8 bit registers A, B, C, D, E, H, and
L.
An 8 bit register is loaded or initialized with the MVI instruction. Variations on this
are MVI A, byte ; MVI B, byte; etc.
The coding for MVI B, 4CH would be 06 4C, a 2 byte instruction.
You can copy (duplicate) the contents of one 8 bit register to another 8 bit register
with the MOV instruction. The format for this is MOV to, from. An example is MOV A, E
with the one byte code of 7BH. Here the contents of E is duplicated in the A register.
Certain of these registers can be used as pairs. These are BC, DE, and HL. A register pair acts
as though it is a 16 bit register. A 16 bit register can hold a quantity as large as 0FFFF H,
65535 Decimal, or 1111111111111111 B. These 16 bit registers are known by their first letter
only. BC is designated B, DE is designated D, HL is designated as H.
The register pairs are initialized with the LXI instruction. LXI B, 1234H would load the B
register with 12H and the C register with 34H. The coding for this would be 01 34 12. 01
represents LXI B, with 3412 being the data in Intel byte swapped form. Of course, you could
also initialize BC with separate MVI B, 12H and MVI C, 34H instructions.
Review:
Load an 8 Bit register, use MVI r, byte. (r = A,B,C,D,E,H,L)
THE next instruction is here if B=0 and we don't do the jump back up to loop.
Not all instructions have an effect on the ZERO flag. DCR, INR, ORA, ANA, ADD, SUB,
XRA, CMP, CMA all work because they are 8 bit instructions.
Simply loading a register does not affect the zero flag. For instance, MVI B, 0 does not set
the zero flag into operation. MOV instructions don't affect the zero flag either.
Certain 16 bit instructions also don't do anything to the zero flag. These include DCX, INX,
LXI. We use the 16 bit instructions in longer delay loops. For example, if we write a delay
program using the BC register pair, we get a whole lot more delay since a double register can
hold a much larger number. 65535 in fact. That's 0FFFFH. ( 4 F's )
A double register delay loop requires a TRICK to discover if the pair is empty. JNZ isn't good
enough by itself to work with a 16 bit decrement (DCX).......
A 16 bit Decrement (DCX) or Increment (INX) doesn't affect the zero flag so we cannot use
the JNZ instruction directly. We must use this software test or trick to discover if we have
emptied BC and finished 65535 decrements.
The idea behind the 'trick' is that if we OR B with C the result will only be zero if both B and
C are already zero. Since there is no instruction that directly OR's B with C, we move one of
these into A and use the ORA instruction to accomplish OR ing B with C. That's how we
learn if BC is zero having done 65535 decrements.
The 16 bit delay loop provides much more delay than the 8 bit delay loop. 255 decrements vs
65535 decrements. We will be using both of these programming structures. Memorize them;
study them to be sure you understand how they operate.
SUBROUTINES
Subroutines are easy with the CALL and the RET instructions. A delay subroutine is easily
created by beginning with the NAME and ending with the RET instruction. The main
program then CALLs the subroutine and return is automatic when the job is done. One thing
though......
The Stack Pointer register (SP) must be initialized for any CALL or RET instruction to work
reliably. This is done with the LXI SP instruction. We load the SP with an address from valid
memory, away from our software, for use by the CPU. The processor will store return
addresses in its stack area. A counter program that uses a subroutine would look like this:
Hex
code
Label
Mnemonics
OpOperand
code
Comments
21,00,90
LXI
H, 9000
8003
8004
8005
3E
00
86
MVI
A, 00
ADD
A, M
8006
23
INX
8007
86
ADD
A, M
8008
32
STA
9002
8009
02
800A
90
800B
76
HLT
Stop the execution
Example 1: Addition of two 8-bit numbers whose sum is 8-bits.
Explanation: This assembly language program adds two 8-bit numbers stored in two
memory locations .The sum of the two numbers is 8-bits only. The necessary
algorithm and flow charts are given below.
ALGORITHM:
Step1. : Initialize H-L pair with memory address XX00 (say: 9000).
Step2. : Clear accumulator.
Step3. : Add contents of memory location M to accumulator.
Step4. : Increment memory pointer (i.e. XX01).
Step5. : Add the contents of memory indicated by memory pointer to accumulator.
Step6. : Store the contents of accumulator in 9002.
Step7. : Halt
PROGRAM:
Ex :(ii) 9000 49 H
9001 32 H
Ex :( ii) 9002 7B
Flow Chart
Start
Clear Accumulator
Stop
Fig 3.18
Example 2: Addition of two 8-bit numbers whose sum is 16 bits.
Explanation: The first 8-bit number is stored in one memory location (say 8500) and
the second 8-bit number is stored in the next location (8501).Add these two numbers
and check for carry. Store the LSB of the sum in one memory location (8502) and the
MSB (carry) in the other location(8503).
ALGORITHM:
Step1. : Initialize H-L pair with memory address X (say: 8500).
Step2. : Clear accumulator.
Step3. : Add contents of memory location M to accumulator.
Step4. : Increment memory pointer (i.e. 8501).
Step5. : Add the contents of memory indicated by memory pointer to accumulator.
Step6. : Check for Carry
Step 7 : Store the sum in 8502.
Step8 : Store the Carry in 8503 location
Step 9 : Halt
Flow Chart
Start
Clear Accumulator
(00) A
Add
contents of
# Increment memory
pointer(XX01) &
# Add contents of M to A
Is
Carry
exists ?
Yes
No
Store carry
in the XX03
Store Zero
in the XX03
Stop
Fig 3.19
PROGRAM:
Address of Hex
the
code
memory
location
Lab
el
Mnemonics
OpOperand
code
Comments
8000
LXI
H, 8500 H
8003
8004
8005
21,00
,85
3E
00
86
MVI
A,00
ADD
A, M
8006
8007
8008
0E
00
23
MVI
C,00
INX
8009
86
ADD
A, M
800A
32
JNC
FWD
800B
800C
800D
800E
0E
80
0C
32
INR
STA
C
8502 H
800F
8010
8011
8012
8013
8014
8015
02
85
79
32
03
85
76
MOV
STA
A,C
8503 H
FW
D
HLT
Ex: Input:
Ex :
8500 97 H
8501 98H
RESULT: 8502 32 H
8503 -- 01 H
Start
Add contents of M
to Accumulator
# Increment memory
pointer(XX01) &
# Add contents of M to A
Is
Carry
Exists?
No
Store Zero in
the XX03
location
Yes
Stores carry in
the XX03
location
Stop
Fig .20
PROGRAM
Address of
the memory
location
Hex
code
Label
Mnemonics
OpOperand
code
Comments
8000
LXI
8003
8004
8005
21,
00,85
0E
00
7E
MVI
MOV
A, M
8006
23
INX
8007
86
ADD
A, M
8008
8009
27
D2
DAA
JNC
FWD
800C
800D
800E
800F
8010
8011
0D
80
0C
32
02
85
79
32
INR
STA
C
8502 H
Make carry =1
The contents of accumulator are
stored in memory location 8502.
MOV
STA
A, C
8503 H
8012
8013
8014
03
85
76
FWD
HLT
Ex: Input:
Ex :
8500 67 D
8501 85 D
RESULT:
8502 52 D
8503 01 (Carry)
25
After PUSH operation the status of the Stack is as shown in Fig 3.30
PUSH
DELAY
.
.
.
POP
CALL
.
.
.
H
Push
contents.
the
Subroutine: It is a set of instructions written separately from the main program to execute a
function that occurs repeatedly in the main program.
For example, let us assume that a delay is needed three times in a program. Writing delay
programs for three times in a main program is nothing but repetition. So, we can write a
subroutine program called delay and can be called any number of times we need
Similarly, in 8085 microprocessor we do not find the instructions for multiplication and
division. For this purpose we write separate programs. So, in any main program if these
operations are needed more than once, the entire program will become lengthy and complex.
So, we write subroutine programs MUL & DIV separately from main program and use the
instruction CALL MUL (or) CALL DIV in the main program. This can be done any number
of times. At the end of every subroutine program there must be an instruction called RET.
This will take the control back to main program.
The 8085 microprocessor has two instructions to implement the subroutines. They are CALL
and RET. The CALL instruction is used in the main program to call a subroutine and RET
instruction is used at the end of the subroutine to return to the main program. When a
subroutine is called, the contents of the program counter, which is the address of the
instruction following the CALL instruction is stored on the stack and the program execution
is transferred to the subroutine address. When the RET instruction is executed at the end of
the subroutine, the memory address stored on the stack is retrieved and the sequence of
execution is resumed in the main program.
Diagrammatic representation
Let us assume that the execution of the main program started at 8000 H. It continues until a
CALL subroutine instruction at 8020 H is encountered. Then the program execution transfers
to 8070 H. At the end of the subroutine 807B H. The RET instruction is present. After
executing this RET, it comes back to main program at 8021 H as shown in the following Fig.
3.34
Mnemonics
Operand
Comments
8000
|
|
|
8020
8021
8022
8023
|
|
|
802F
LXI
SP, 8400 H
CALL
8070 H
Next instruction
|
|
|
HLT
Subroutine Program:
Memory
Address
8070
|
Mnemonics
Instructions
Operand
Comments
Beginning of the Subroutine.
|
|
|
807B
807C
RET
Next Subroutine
807F
RET
Delay programs:
In many situations it may be desired to provide some delay between the execution of
two instructions by a microprocessor. The delay can be produced by either hardware chip like
8253 or by writing a software program using registers of the processor. Here we will discuss
the software delay program. This delay program is not a part of the main program. Hence it is
called delay sub-routine program. For small delays we can use only one register. But for
longer delays one has to use two or three registers. The technique involved here is, a register
is loaded with a number and then decremented by using the instruction DCR until it becomes
zero. The time of execution of the microprocessor is equal to the delay time produced.
For example, we have constructed a display system where the LEDs receive the input from a
microprocessor. Since the microprocessor is a very fast device it sends the signal at very high
speeds there by our eye cannot recognize the display pattern. So, if you provide some delay
between two input signals, the display can be visualized clearly. Similarly to observe the
rotations of a stepper motor, a delay is needed between every two excitation signals applied
to the motor.
Delay Subroutine with one register:
Program
Address
Label
Machine
code
Mnemonics
Operand
Comments
MVI
A, FF
Get FF in register A
DCR
Decrement register A.
9003
JNZ
LOOP
9006
RET
9000
9002
LOOP
Instructions
MVI A, FFH
(loop) DCR A
JNZ loop
RET
States
7
4
7/10
10
Total T States=3584
The time required for one T-state in INTEL 8085 microprocessor is nearly 330n.sec
Delay time is= 3584 x 333n.sec
= 3.584 x 0.333 x 10-3 seconds
= 1.18272 x 10-3 seconds
= 1. 193472 milliseconds
Delay Subroutine with two registers
Program:
Addres
s
Label
Mnemoni
c
Operan
d
Comments
MVI
B, 10H
MVI
C, 56H
DCR
Decrement C.
8405
JNZ
LOOP2
8408
DCR
Decrement register B
8409
JNZ
LOOP1
840C
RET
8400
8402
8404
LOOP
1
LOOP
2
Machin
e
Code
Label
Machine
Code
8000
LOOP
Mnemonic
Operand
Comments
LXI
D, FFFF
DCX
Decrement count
MOV
A, D
ORA
JNZ
LOOP
RET
Label
Machine
Code
Mnemonic
Operand
Comments
8400
MVI
A, 98H
8402
OUT
03
8404
MVI
B, 50H
8406
MVI
C, FFH
8408
MVI
D, FFH
840A
DCR
840B
JNZ
LOOP3
840E
DCR
840F
JNZ
LOOP2
8412
DCR
8413
JNZ
LOOP1
8416
MVI
A, 01
8418
OUT
01
8419
HLT
From the above discussion it is clear that with increase of T-states required for a delay
subroutine, the delay time also increases.
UNIT III 8051 MICRO CONTROLLER 9
Hardware Architecture, pin outs Functional Building Blocks of Processor Memory
organization I/O ports and data transfer concepts Timing Diagram InterruptsComparison to Programming concepts with 8085.
MICROCONTROLLER
The INTEL 805 F is an 8-bit microcontroller with 128 byte internal RAM and 4kb
internal ROM.
The INTEL 8031 is same, as 8051 except that it does not have internal ROM.
The 8051 is a pin 40 pin IC available in Dual-In line package (DIP).
Requires a single power supply of +5V.
Its maximum internal clock frequency rating is 12 MHz.
1. The 8031/8051 microcontroller has 32 I/O pins and they are organized as four numbers of
8-bit parallel port.
2. The ports are denoted as port-0, port-1, port-2 and port-3. Each port can be used as either
8-bit parallel port or 8 numbers of 1-bit ports.
3. The ports behave as latches during output operation and behave as buffers during input
operation.
4. Port-1 can be used only for I/O operation
5. When external memory is employed, the port-0 function as multiplexed low byte address
or data lines, and port-2 function as high byte address lines. Therefore for accessing
external memory the microcontroller uses 16-bit address and access the memory in bytes.
Hence the addressable memory space is 64 kb (216 = 64kb).
6. The 8031/8051 allows the external memory to be organized as two banks of 64 kb. One is
program/code memory and the other is data memory.
PSEN (low signal): pin 29
The XTAL 1 and XTAL2 pins are provided for external quartz crystal connection,
in order to generate the required clock for the microcontroller. The maximum frequency of
quartz crystal that can be connected to 8051 microcontroller is 12 MHz.
RST (low): pin 9
The RST(low) signal is used to reset the microcontroller in order to bring the
controller to a known state.
In this two interrupts are external interrupt as INT0 (Low), INT1 (Low) and the
remaining three are internal interrupts as timer-0, timer-1 and serial port.
2. The unit can perform logical operations such as AND, OR; and Exclusive-OR, as
well as rotate, clear, and complement.
3. The ALU can also manipulate one bit as well as eight-bit data types.
4. Individual bits may be set, cleared, complemented, tested, and used in logic
computation.
2. Accumulator:
1. It is an 8-bit register.
2. It holds a data and receives the result of the arithmetic instructions.
3. B register: An 8-bit general-purpose register.
4. Program Status Word:
1. Many instructions implicitly or explicitly affect (or are affected by) several status
flags, which are grouped together to form the Program Status Word.
2. It also used to select the memory bank.
1. The 8051 has four numbers of 8-bit ports namely port-0, port- 1, port-2 and port-3.
2. Each port has a latch and driver (or buffer).
3. When external memory is employed the port-0 lines will function as multiplexed low
byte address/data lines and port-2 lines will function as high byte address lines.
4. Also the port pins P3.7 and P3.6 are used to output read and write control signals
respectively.
5. The port-1 is dedicated I/O port and does not have any alternate function.
6. The ports are also mapped as internal memory in the controller and so they can be
addressed as memory locations for 8-bit operation.
Instruction Register (IR) & timing and control unit:
1. The 8051 has 8-bit ALU, which performs arithmetic and logical operations on binary
data.
2. The A and B registers are used to hold the input data and the result of ALU operation.
3. The controller will fetch the instructions one by one, starting from the address stored
in PC and store in IR, which decodes the instructions and give information to timing
and control unit.
4. Using the information supplied by the IR unit the control signals necessary for
internal and external operations are generated by the timing and control unit.
Timer/Counter & Serial port:
1. The 8031/8051 has two 16-bit programmable timer/counter namely timer-1 and timer
0.
2. In the counter mode of operation they can count the number of high to low transitions
of the signal applied to the timer pins.
3. In timer mode of operation they can be independently programmed to work in any one
of the four operation modes. They are called mode-0, mode-1, mode-2 and mode-3.
4. In mode-0 the serial port can either receive or transmit at fixed baud rate.
5. In mode-2 it can simultaneously transmit and receive at any one of the two selectable
baud rate.
6. In mode-1 and mode-3 it can work as full duplex serial port with variable baud rate,
which is programmed using timer-1.
Memory Organization:
1. Since the size of address pointers are 16-bit they can address up to 2 16 = 64kb memory
locations.
2. A microcontroller based system requires both EPROM and RAM. The EPROM is
required for permanent program and permanent data storage. The RAM is required for
temporary data storage and stack. The 8031/8051 has 64kb program memory address
space and 64kb data memory address space.
3. The microcontroller can only read from program memory such as ROM/EPROM/
EEPROM and the signal PSEN (Low) is used as read control for reading program
memory.
4. The microcontroller can read and write with data memory RAM. It has separate read
control signal RD(Low), and write control signal WR(Low) for reading and writing
with data memory respectively.
5. In 8031/8051 based system only memory mapped I/O is possible.
Program Memory:
1. In 8031 there is no internal ROM/EPROM and so the entire 64 kb program memory space
in the range 0000H to FFFFH is external. Therefore in 8031 based systems the pin
EA(Low) is always tied low or grounded (0V).
2. The 8051 has 4kb internal ROM which can be mapped to first 4kb address space of
program memory.
3. If EA(Low) pin is tied high or tied to V CC (+5V), then the internal 4kb ROM be mapped
as program memory in the address range 0000H to 0FFFH and the external program
memory 60kb will have the address range l000H to FFFFH
4. If EA(Low) pin is tied low or grounded (0V), then the internal ROM is ignored or cannot
be accessed. The entire 64 kb program memory address space is external with address
range 0000H to FFFFH.
Interrupt/Vector location
Data Memory:
1. In 8031/8051 microcontroller the entire 64kb data memory space is external.
2. The address range of external data memory is 0000H to FFFFH.
3. Apart from external data memory the 8031/8051 has 256 bytes of internal data
memory in which the first 128 bytes are called RAM and next 128 byte is called SFR.
4. The address range of SFRs and internal RAM are 00H to FFH
5. The MOVX instruction is used to access the external data memory.
6. The internal data memory space for 8051 is divided into three blocks: Lower
128bytes, Upper 128 bytes and SFRs.
7. The upper addresses and SFRs occupy the same block of address space, 80H through
FFH, and they are physically separate entities.
8. The upper address is accessible by indirect addressing only and SFRS are accessible
by direct addressing only.
9. Lower address space can be accessed either by direct addressing or by indirect
addressing.
a.
10. The 8051 Data Memory
11. The circuit diagram for connecting external data memory is shown. The multiplexed
address / data bus is provided by port 0.
12. Port 2 gives the higher order address bus.
13. The RD (Low) and WR (Low) signals from 8051 selects the memory read and
memory write operation, respectively.
A and B Registers:
1. The A and B registers are called CPU registers.
2. They are used to hold the data for most of the CPU (ALU) operations.
3. The size of A and B registers are 8-bit.
4. In ALU operation, the result is stored in A-register and so it is also known as
accumulator.
Data Pointer (DPTR):
1. The data pointer is a 16-bit register used to hold the 16-bit address of data memory.
2. This can also be used as two numbers of 8-bit data pointer namely DPH and DPL.
3. The 8-bit data pointers are used for accessing internal RAM and SFR.
4. The 16-bit data pointer is used for accessing external data memory.
5. The contents of data pointer are programmable using instructions.
Program Status Word (PSW):
1. The PSW is also known as flag register.
2. The flags are useful for the programmer to test the condition of the result and make
decisions.
3. The format of PSW of 8031/8051 microcontroller is shown in fig.
4. The PSW consists of four math flags and two register bank select bits. The math flags
are Carry, Auxiliary Carry, and Overflow and Parity flags.
5. The flags are altered after arithmetic and logical operations depending on the result.
6. The carry flag is set when the result has a carry.
7. When there is a carry from lower nibble to upper nibble the auxiliary carry is set.
8. When the result has even parity, the parity flag is set.
9. In certain mathematical operations if the size of the result exceeds the size of
destination register then overflow flag is set.
10. The register bank select bits RS1 and RS0 are used to select any one of the four
register banks of the internal RAM. At any one time the microcontroller can work
with (or access) only one register bank selected by these bits.
11. The bank select bits are programmable and after reset the controller defaults to bank0. The selection of register bank using the RS1 and RS0 bits are listed in table.
3. The lower four bits of TMOD register is used to control timer-0 and the upper four
bits are used to control timer-1.
4. The two timers can be independently program to operate in various modes.
5. The TMOD register has two separate two bit field M0 and Ml to program the
operating mode of timers. The operating modes of timers are mode-0, mode-1, mode2 and mode-3. In all these operating modes the oscillator clock is divided by 12 and
applied as input clock to timer.
Mode-0
1. In mode-0 the timer register is configured as 13-bit register.
2. For timer-1 the 8 bits of TH1 and lower 5 bits of TL1 are used to form 13-bit register.
3. For timer-0 the 8-bit of TH0 and lower 5 bits of TL0 are used to form 13-bit register.
4. The upper three bits of TL registers are ignored.
5. For every clock input to timer the 13-bit timer register is incremented by one When
the timer count rolls over from all 1s to all 0s, (i.e., 1 1111 1111 1111 to 0 0000 0000
0000) the timer interrupt flag in TCON register is set to one
Mode-1
1. The mode-1 is same as mode-0 except the size of the timer register. In mode-1 the TH
and TL registers are cascaded to form 16-bit timer register.
Mode-2
1. In mode-2, the timers function as 8-bit timer with automatic reload feature. The TL
register will function as 8-bit timer count register and the TH register will hold an
initial count value.
2. When the timer is started, the initial value in TH is loaded to TL and for each clock
input to timer the 8-bit timer count register is incremented by one.
3. When the timer count rolls over from all 1s to all 0s (i.e., 1111 1111 to 0000 0000),
the timer interrupt flag in TCON register is set to one and the content of TH register is
reloaded in TL register and the count process starts again from this initial value.
Mode-3
1. In mode-3, the timer-0 is configured as two separate 8-bit timers and the timer-1 is
stopped.
2. In mode-3 the TL0 will function as 8-bit timer controlled by standard timer-0 control
bits and the TH0 will function as 8-bit timer controlled by timer-1 control bits.
3. While timer-0 is programmed in mode-3, the timer-0 can be programmed in mode-0,
1 or 2 and can be used for an application that does not require an interrupt.
a. The C/T(Low) bit of TMOD register is used to program the counter or timer
operation of the timer. When C/T bit is set to one, the timer will function as event
counter. The C/T(Low) bit is programmed to zero for timer operation.
b. The timer will run only if clock input is allowed.
c. When GATE = 1, the clock input to timer is allowed only if the signal at pin is
high and when GATE =0 the signal at INT (low) pin is ignored.
Serial Port Control Register (SCON):
Mode 0:
In this mode the serial port function as half duplex serial port with fixed baud rate.
The 8- bit serial data is received and transmitted through RxD pin and the controller
output the shift clock through TxD pin during reception and transmission.
The baud rate is fixed at 1 / 12 of the oscillator frequency.
Mode 1:
In this mode the serial port function as full duplex serial port with variable baud rate.
In this mode one data consists of 10 bits, which includes one start bit, eight data bit
and one stop bit. During reception the stop bit is stored as RB8 in SCON register.
Baud rate in mode-1 depends on the value of SMOD bit in PCON register and the
timer-1overflow rate.
Mode 2:
In this mode the serial port function as full duplex serial port with a baud rate of either
1/32 or 1/64 of the oscillator frequency.
In this mode one data consists of 11 bits which includes one start bit, eight data bit, a
programmable 9th data bit and one stop bit.
During transmission the TB8 of SCON register is added as 9th data bit and during
reception the 9th data bit is stored as RB8 in SCON register.
The baud rate depends on the value of SMOD bit in PCON register.
Mode 3:
1. The mode-3 is same as mode-2, except the baud rate.
2. In mode-3, the baud rate is variable. The baud rate depends on the value of SMOD
bit in PCON register and the timer- 1 overflow rate.
3. The serial mode bit-2 (SM2) has no effect in mode-0 and when programmed for
mode-0, the SM2 should be equal to zero.
4. In mode-1, SM2 is used to check a valid stop bit during reception. In mode-1, if
SM2 = 1, then receive interrupt (RI) is activated only when a valid stop bit is
received.
5. In mode-2 and mode-3 the SM2 bit is used to enable multiprocessor
communication.
6. In multiprocessor communication the serial port of a number of microcontrollers
can be connected to a common serial bus. One controller will act as a master and
all other controller will act as slave.
7. A unique 8-bit address is assigned to each slave and the SM2 bit in all the slaves is
set to 1.
8. When SM2 bit is one, the slaves will consider the received byte as address and
when SM2 bit is zero the slaves will consider the received byte as data.
9. For communication with a slave the master will first send as address byte and then
a data byte.
10. The master initiates communication with a slave by sending the address of the
slave on the bus. All the slaves will receive the address byte. Since SM2 = 1
initially in all the slaves, the received byte will be considered as address and the
slaves will verify whether the received address matches with assigned address.
The slave whose assigned address matches with received address will clear its
SM2 bit. Now SM2 bit of only one of the slave will be zero.
11. Next the master will send a data byte which is also received by all the slave, but
the data byte is accepted by the slave whose SM2 = 0 and so the receive interrupt
is activated only in one of the slave whose SM2 = 0.
12. After reading the received data from SBUF register, the SM2 bit of the slave
should be set to one again to receive next data.
13. The REN bit of SCON register can be used to enable or disable the serial
reception. When REN = 1, the serial reception is enabled and when REN = 0, the
serial reception is disabled.
14. The bits TI and RI of SCON register are transmitting interrupt flag and receive
interrupt flag respectively.
15. The controller will set the TI bit during the transmission of stop bit of a data
character in mode 1 to 3 and during the transmission 0 bit of a data character in
mode-0.
16. The controller will set the RI bit during the reception of stop bit of a data character
in mode 1 to 3 and during the reception of 8th bit of a data character in mode- 0.
Timer Control Register (TCON):
1. The TCON register consists of timer overflow flags, timer run control bits, external
interrupt flags and external interrupt type control bits.
2. The format of TCON register is,
When clock signal is applied, after reaching maximum value (i.e., the content of counter
is all 1s), the content of counter will become zero (i.e., all 0s). This condition is called
timer overflow and this is also the end of timing maintain by using the timer.
The TCON register has a 1-bit flag, TF for each timer to indicate the timer overflow or
end of timing.
Whenever the timer/counter overflows, the TF flag is set to one.
The TF flag is also used as an interrupt signal to initiate the execution of a subroutine.
When the controller executes a subroutine, the TF flag is cleared.
The TR bit is used to start/stop the timer/counter. When TR bit is set to one, the timer/
counter will start counting and continue the counting as long as TR bit is one. The
timer/counter will stop counting when TR bit is cleared to zero.
When a valid external interrupt signal is detected the IE flag is set to one. When the
controller accepts the external interrupt and start processing it, the IE flag is cleared to
zero.
The IT = 1, when it recognize falling edge triggered external interrupt and IT = 0, when it
recognize logic low level external interrupt.
Interrupt Enable Register (IE):
The IE register is used to enable/disable the interrupts of 8051.
The interrupts are recognized by the controller only if they are enabled.
The format of IE register is,
ADDRESSING MODES:
An "addressing mode" refers to how you are addressing a given memory location.
In summary, the addressing modes are as follows, with an example of each:
Immediate Addressing
Direct Addressing
Indirect Addressing
External Direct
MOV A,#20h
MOV A,30h
MOV A,@R0
MOVX A,@DPTR
Code Indirect
MOVC A,@A+DPTR
MOV
R0,#99h
;Load
the
address
of
the
serial
port
MOV @R0,#01h ;Send 01 to the serial port -- WRONG!!
This is not valid. Since indirect addressing always refers to Internal RAM these two
instructions would write the value 01h to Internal RAM address 99h on an 8052. On an 8051
these two instructions would produce an undefined result since the 8051 only has 128 bytes
of Internal RAM.
External Direct
External Memory is accessed using a suite of instructions which use what I call "External
Direct" addressing. I call it this because it appears to be direct addressing, but it is used to
access external memory rather than internal memory.
There are only two commands that use External Direct addressing mode:
MOVX A,@DPTR
MOVX @DPTR,A
As you can see, both commands utilize DPTR. In these instructions, DPTR must first be
loaded with the address of external memory that you wish to read or write. Once DPTR holds
the correct external memory address, the first command will move the contents of that
external memory address into the Accumulator. The second command will do the opposite: it
will allow you to write the value of the Accumulator to the external memory address pointed
to by DPTR.
External Indirect
External memory can also be accessed using a form of indirect addressing which I call
External Indirect addressing. This form of addressing is usually only used in relatively small
projects that have a very small amount of external RAM. An example of this addressing mode
is:
MOVX @R0,A
Once again, the value of R0 is first read and the value of the Accumulator is written to that
address in External RAM. Since the value of @R0 can only be 00h through FFh the project
would effectively be limited to 256 bytes of External RAM. There are relatively simple
hardware/software tricks that can be implemented to access more than 256 bytes of memory
using External Indirect addressing; however, it is usually easier to use External Direct
addressing if your project has more than 256 bytes of External RAM.
INTERRUPTS:
What Happens When an Interrupt Occurs?
When an interrupt is triggered, the following actions are taken automatically by the
The current Program Counter is saved on the stack, low-byte first.
Interrupts of the same and lower priority are blocked.
In the case of Timer and External interrupts, the corresponding interrupt flag is set.
Program execution transfers to the corresponding interrupt handler vector address.
The Interrupt Handler Routine executes.
What Happens When an Interrupt Ends?
An interrupt ends when the program executes the RETI (Return from Interrupt)
instruction. When the RETI instruction is executed the following actions are taken by the
microcontroller:
Two bytes are popped off the stack into the Program Counter to restore normal program
execution.
Interrupt status is restored to its pre-interrupt status.
Types of Interrupts:
The 8051 provide 5 interrupt sources.
They are,
1. External interrupt 0
2. Timer interrupt 0
3. External interrupt 1
4. Timer interrupt 1
5. Serial port interrupt
Interrupt Destinations:
The interrupts are stored in the lower addresses in program memory.
Interrupt
Address(HEX)
IEO
TF0
IE1
TF1
SERIAL
0003
000B
0013
001B
0023
Interrupt priority:
The normal priority of the interrupts are,
1. External interrupt 0
2. Timer interrupt 0
3. External interrupt 1
4. Timer interrupt 1
5. Serial port interrupt
The priority will be changed by the special function register IP and they are enabled by
IE register.
Interrupt Enable Register (IE):
The interrupts are recognized by the controller only if they are enabled.
The format of IE register is,
Mov a,#num
Mov Rx,a
Mov a,Rx
Mov Rx,#num
Mov a,add
Mov add,a
Mov add,#num
Mov add1,add2
Mov Rx,add
Mov add,Rx
Mov @Rp,a
Mov a,@Rp
Mov add,@Rp
Mov @Rp,add
Mov
@Rp,#num
Movx a,@Rp
Movx
a,@DPTR
Movx @Rp,a
Movx
@DPTR,a
Movc
a,@a+DPTR
Movc a,
@a+PC
Push add
Pop add
mode
occupied
cycles used
immediate
register
register
1
1
1
1
immediate
direct
direct
direct
direct
direct
direct
Indirect
Indirect
Indirect
Indirect
Indirect
Indirect
Indirect
Indirect
Indirect
indirect
indirect
Direct
direct
Xch a, Rx
Xch a, add
Xch a,@Rp
Xchd a, @Rp
Register
Direct
Indirect
indirect
Arithmetic Instructions
The arithmetic instructions are used to performing addition, subtraction, multiplication,
division, and increment and decrement operation on binary data.
The mnemonic used in arithmetic instructions are ADD, ADDC, SUBB, INC, DEC, MUL,
DIV and DA.
The result of most of the arithmetic operation is stored in accumulator except a few
decrement and increment operations.
The arithmetic instructions except increment and decrement instructions modify the flags of
8031/8051
Arithmetic Instructions: Operational description
Mnemonics
Inc a
Inc Rr
Inc add
Inc @rp
Inc DPTR
dec a
dec Rr
dec add
dec @rp
Add a, #num
Add a, Rx
Add a, add
Add a, @Rp
Add 1 to acc
Add 1 to register Rr
Add 1 to the content of add
Add 1 to the content of the address
in Rp
Add 1 to DPTR
Subtract 1 from acc
Subtract 1 from Rr
Subtract 1 from content of add
Subtract 1 from the content of
address
Add the immediate num with acc
and stores result in acc
Add the data in Rx with acc and
stores result in acc
Add the data in add with acc and
stores result in acc
Add the data at the address in Rp
with acc and stores result in acc
Addressing
mode
Register
Register
Direct
No. of bytes
No. of
occupied
cycles used
1
1
1
1
2
1
indirect
Register
Register
Register
Direct
1
1
1
2
2
1
1
1
indirect
immediate
Register
Direct
Indirect
immediate
Register
Direct
Indirect
immediate
Register
Direct
Indirect
---
---
---
Logical Instructions:
The logical instructions are used to perform logical AND, OR, Exclusive-OR,
Complement and rotate left and right.
The various mnemonics used for logical instructions are ANL, ORL, XRL, CLR,
CPL, RL, RLC, RR and RRC AND SWAP.
Only the rotate through the carry instruction will affect the flag.
In most of the result of logical instruction is stored in accumulator and in some instructions
the result is stored in RAM/SFR.
Logical Instructions: Operational description
Addressing No. of bytes
No. of
Mnemonics
mode
occupied
cycles used
AND each bit of acc with same
Anl a, #num
bit of immediate num, stores Immediate
2
1
result in acc
AND each bit of acc with same
Anl a, add
bit of content in add, stores result
Direct
2
1
in acc
AND each bit of acc with same
Anl a, Rx
bit of content of Rx, stores result
Register
1
1
in acc
AND each bit of acc with same
Anl a, @Rp
bit of content of add given by Rp,
Indirect
1
1
stores result in acc
AND each bit of acc with same
Anl add, a
bit of direct add num, stores
Direct
2
1
result in add
Anl add, #num AND each bit of direct add with
direct
3
2
orl a, #num
orl a, add
orl a, Rx
orl a, @Rp
orl add, a
orl add, #num
Xrl a, #num
Xrl a, add
Xrl a, Rx
Xrl a, @Rp
Xrl add, a
Xrl add, #num
Clr a
Cpl a
Anl c, b
Anl c, /b
Orl c, b
Orl c, /b
Cpl c
Immediate
Direct
Register
Indirect
Direct
direct
Immediate
Direct
Register
Indirect
Direct
direct
Direct
direct
1
1
1
1
--
-----
Cpl b
Clr c
Clr b
Mov c, b
Mov b, c
Setb c
Setb b
Rl a
Rr a
Rlc a
Rrc a
Swap a
Complement bit b
Clear carry flag
Clear given bit b
Copy bit b to carry
Copy carry to bit b
Set carry flag
Set bit b
Rotate acc one bit left
Rotate acc one bit right
Rotate acc one bit left with carry
Rotate acc one bit right with
carry
Exchange upper and lower nibble
of acc
-----------
2
1
2
2
2
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
--
--
Branching Instructions:
The branching instructions will modify the content of PC so that the program
execution sequence is changed to new address.
There are two types of branching instructions like condition and unconditional
instructions.
In conditional branching the content of PC is changed only if the condition specified
is true.
In unconditional branching the PC is always modified.
The program branching instructions are ACALL, LCALL, RET, AJMP, LJMP, SJMP,
JMP, JZ, JNZ, CJNE, DJNZ and NOP.
Branching Instructions: Mnemonic
Operational description
Jc label
Jnc label
Jb b,label
Jnb b,label
Jbc b,label
Cjne a, add,
label
Cjne
a,
#num, label
Cjne Rx,
#num, label
Cjne @Rp,
#num, label
Djnz Rx,
label
Djnz add,
label
No of bytes
occupied
2
2
3
3
3
No. of cycles
used
2
2
2
2
2
Jz label
Jnz label
Jmp
@a+dptr
Ajmp sadd
Ljmp ladd
Sjmp radd
nop
Acall sadd
Lcall ladd
Ret
reti
2
3
2
2
2
2
Boolean Instructions:
The Boolean variable instructions operate on a particular bit of a data.
These instructions perform clear, complement or move a particular bit of bit addressable
RAM/SFR or carry flag.
If a particular bit is set or cleared then this instruction will transfer the PC address to new
address.
The Boolean instructions are CLR, SETB, CPL, ANL, ORL, MOV, JC and JNC.
BOOLEAN VARIABLE MANIPULATION
Mnemonic
Operational description
CLR
CLR
SETB
SETB
CPL
CPL
ANL
ANL
ORL
ORL
MOV
MOV
JC
JNC
JB
JNB
JBC
C
bit
C
bit
C
bit
C,bit
C,/bit
C,bit
C,/bit
C,bit
bit,C
rel
rel
bit,rel
bit,rel
bit,rel
No of bytes
occupied
Clear Carry
1
Clear direct bit
2
Set Carry
1
Set direct bit
2
Complement Carry
1
Complement direct bit
2
AND direct bit to CARRY
2
AND complement of direct bit to Carry
2
OR direct bit to Carry
OR complement of direct bit to Carry
Move direct bit to Carry
2
Move Carry to direct bit
2
Jump if Carry is set
2
Jump if Carry not set
2
Jump if direct Bit is set
3
Jump if direct Bit is Not set
3
Jump if direct Bit is set & clear bit
3
Oscillator
Period
12
12
12
12
12
12
24
24
2
24
2
24
12
24
24
24
24
24
24
UNDERSTANDING LCD
Pin out
8 data pins D7:D0
Bi-directional data/command pins.
Alphanumeric characters are sent in ASCII format.
RS: Register Select
RS = 0 -> Command Register is selected
RS = 1 -> Data Register is selected
In the above memory map, the area shaded in black is the visible display (For 16x2 display) .
For first line addresses for first 15 characters is from 00h to 0Fh. But for second line address
of first character is 40h and so on up to 4Fh for the 16th character.
So if you want to display the text at specific positions of LCD , we require to manipulate
address and then to set cursor position accordingly .
Character Generator RAM (CGRAM)-User defined character RAM
In the character generator RAM, we can define our own character patterns by program. CG
RAM is 64 bytes, allowing for eight 5*8 pixel, character patterns to be defined. However
how to define this and use it is out of scope of this tutorial. So I will not talk any more about
CGRAM
Registers
The HD44780 has two 8-bit registers, an instruction register (IR) and a data register (DR).
The IR stores instruction codes. The DR temporarily stores data to be written into DDRAM
or CGRAM and temporarily stores data to be read from DDRAM or CGRAM. Data written
into the DR is automatically written into DDRAM or CGRAM by an internal operation. .
These two registers can be selected by the register selector (RS) signal. See the table below:
:
Register Selection
RS R/W
Operation
0 0 IR write as an internal operation (display clear, etc.)
0
1
1
Busy Flag (BF)
When the busy flag is 1, the LCD is in the internal operation mode, and the next instruction
will not be accepted. When RS = 0 and R/W = 1 (see the table above), the busy flag is output
to DB7 (MSB of LCD data bus). The next instruction must be written after ensuring that the
busy flag is 0.
LCD Commands
The LCDs internal controller accept several commands and modify the display accordingly.
These commands would be things like:
Clear screen
Return home
Shift display right/left
Instruction
Decimal
HEX
Function set (8-bit interface, 2 lines, 5*7 Pixels)
56
38
Function set (8-bit interface, 1 line, 5*7 Pixels)
48
30
Function set (4-bit interface, 2 lines, 5*7 Pixels)
40
28
Function set (4-bit interface, 1 line, 5*7 Pixels)
32
20
Entry mode set
See Below See Below
Scroll display one character right (all lines)
28
1E
Scroll display one character left (all lines)
24
18
Home (move cursor to top/left character position)
2
2
Move cursor one character left
16
10
Move cursor one character right
20
14
Turn on visible underline cursor
14
0E
Turn on visible blinking-block cursor
15
0F
Make cursor invisible
12
0C
Blank the display (without clearing)
8
08
Restore the display (with cursor hidden)
12
0C
Clear Screen
1
01
Set cursor position (DDRAM address)
128 + addr
80+ addr
Set pointer in character-generator RAM (CG RAM address)
64 + addr
40+ addr
Entry mode set
This command sets cursor move direction and display shift ON/OFF. There are 4 possible
function set commands; 04, 05, 06, and 07. This command changes the direction the cursor
moves by setting the address counter to increment or decrement. This command is very
important. If you do not understand it you may not see anything or what you actually wanted
to see on LCD screen. I have created 4 animated gifs to demonstrate what the function set
command is all about.
Set cursor position (DDRAM address)
As said earlier if we want to display the text at specific positions of LCD, we require to
manipulate address and then to set cursor position accordingly.
I want to display "MAHESH" in message "Hi MAHESH" at the right corner of first line then
I should start from 10th character.
So referring to table 80h+0Ah= 8Ah.
lcall ready
ret
Initialization
initialization:
mov A, #38H ; Initialize, 2-lines, 5X7
matrix.
lcall Command
mov A, #0EH ; LCD on, cursor on
lcall Command
mov A, #01H ; Clear LCD Screen
lcall Command
mov A, #06H ; Shift cursor right
lcall Command
lcall ready
ret
Display clear
clear:
setb p3.7 ;enable EN
clr 3.6 ;RS=0 for cmd.
mov DATA,#01h
clr p3.7 ;disable EN
lcall ready
RET
Displaying "HI"
lcall initialization
lcall clear
mov A,#'H'
acall data
mov A,#'I'
lcall data
mov a,#'H'
lcall data
mov a,#'E'
lcall data
mov a,#'S'
lcall data
mov a,#'H'
lcall data
Interfacing 8279 with 8031/8051 microcontroller:
The 8279 can be interfaced to 8031/8051 controller to provide the keyboard and 7segment LED display.
A simple schematic for interfacing 8279 with 8031/8051 microcontroller is shown.
The of 8279 is mapped as data memory, because the 8031/8051 controller supports
only memory mapping of I/O device, and read and write operation is possible only with
data memory.
The data lines D7- D0 of 8031/8051 are connected to DB7 DB0 lines of 8279.
The address line A0 of 8031/8051 is connected to A0 of 8279 to provide the internal
address.
The address lines A13, A14 and A15 are decoded to generate eight chip select signals,
and in this CS2 (low) are used as chip select for 8279.
The signals RD (Low) and WR (Low) are logically ANDed and used as logic low
enable for decoder and the signal PSEN (Low) is used as logic high enable for decoder.
The clock frequency at X2 pin of 8031/8051 can be divided using any clock divider
circuit to generate 3 MHz clock for 8279.
A RC circuit can be employed to generate the reset signal for 8031/8051 as well as for
8279.
The addresses allotted to 8279 are listed in table.
The circuit has 6 numbers of 7-segment LEDs and so the 8279 has to be programmed in
encoded scan. (Because in decoded scan, only 4 numbers of 7-segment LEDs can be
interfaced):
In encoded scan the output of scan lines will be binary count. Therefore an external,
3-to-8 decoder is used to decode the scan lines SL0, SL1 and SL2 of 8279 to produce eight
scan lines S0 to S7.
The decoded scan lines S0 and S1 are common for keyboard and display.
The decoded scan lines S2 to S5 are used only for display and the decoded scan lines
S6 and S7 are not used in the system.
Anode and Cathode drivers are provided to take care of the current requirement of
LEDs.
The anode drivers are called segment drivers and cathode drivers are called digit
drivers.
The 8279 output the display code for one digit through its output lines (OUT A0 to
OUT A3 and OUT B0 to OUT B3) and send a scan code through, SL0- SL3.
The display code is inverted by segment drivers and sent to segment bus.
The scan code is decoded by the decoder and turns ON the corresponding digit driver.
Now one digit of the display character is displayed. After a small interval (10 millisecond, typical), the display is turned OFF (i.e., display is blanked) and the above process
is repeated for next digit. Thus multiplexed display is performed by 8279.
The keyboard matrix is- formed using the return lines, RL 0 to RL3 of 8279 as columns
and decoded scan lines S0 and S1 as rows.
A hexa key is placed at the crossing point of each row and column. A key press will
short the row and column. Normally the column and row line will be high.
During scanning the 8279 will output binary count on SL0 to SL3, which is decoded
by decoder to make a row as zero. When a row is zero the 8279 reads the columns. If
there is a key press then the corresponding column will be zero.
If 8279 detects a key press then it waits for debounce time and again read the columns
to generate key code.
In encoded scan keyboard mode, the 8279 stores an 8-bit code for each valid key
press. The key code consist of the binary value of the column and row in which the key is
found and the status of shift and control key.
After a scan time, the next row is made zero and the above process is repeated and so on.
Thus 8279 continuously scan the keyboard.