Friday, June 12, 2020

Microprocessor and its Applications



  Introduction to Microcomputer

Microcomputer Structure and Operation

A microcomputer is a small, low cost digital computer, which usually consist of a microprocessor, a storage unit, an input channel and an output channel, all of which may be one chip inserted into one of several PC boards

               

      Von Neumann model of computer architecture

The major parts of this model are the Central Processing Unit (CPU), memory,and the lnput

and output circuitry or I/O. Connecting these parts are three sets of parallel lines called buses. The three buses are the Address Bus, the Data Bus, and the Control Bus.

Memory:

The memory section usually consists of a mixture of RAM (Random Access Memory) and ROM (Read Only Memory). It may also have magnetic floppy disks, magnetic hard disks, or optical disks (CDs, DVDs).Memory has two purposes. The first purpose is to store the binary codes for the sequences of instructions you want the computer to carry out. When we write a computer program, what we are really doing is writing a sequential list of instructions for the computer. The second purpose of the memory is to store the binary-coded data with which the computer is going to be working

Input/Output:

The Input/output or I/O sections allow the computer to take in data from the outside world or send data to the outside world. Peripherals such as keyboards, video display terminals, printers, and modems are connected to the I/O section. These allow the user and the computer to communicate with each other. The actual physical devices used to interface the computer buses to external systems are often called ports

Ports in a computer function just as shipping ports do for a count An input port allows data from a keyboard, an A/D converter, or some other source to be read into the computer under control of the CPU. An output port is used to send data from the computer to some peripheral, such as a video display terminal, a printer, or a D/A converter

Data Bus:

The data bus consists of 8, 16, or 32 parallel signal lines. As indicated by the double-ended arrows on the data bus line. The data bus lines are bidirectional This means that the CPU can read data in from memory or from a port on these lines, or it can send data out to memory or to a port on these lines

Many devices in a system will have their outputs connected to the data bus but only one device at a time will have its outputs enabled. Any device connected on the data bus must have three-state outputs so that its outputs can be disabled when it is not being used to put data on the bus.

Address Bus:

The address bus consists of 16, 20, 24 or 32 parallel signal lines. On these lines the CPU sends out the address of the memory location that is to be written to or read from. The number of memory locations that the CPU can address is determined by the number of address lines.

If the CPU has N address lines. then it can directly address 2N memory locations. For example, a CPU with 16 address lines can address 216 or 65.536 memory locations, a CPU with 20 address lines can address 220 or 1.048.576 locations, and a CPU with 24 address lines can address 224 or 16,777216 locations. When the CPU reads data from or writes data to a port, it sends the port address out on the address bus.

Control Bus:

The control bus consists of 4 to 10 parallel signal lines. The CPU sends out signals on the control bus to enable the outputs of addressed memory devices or port devices. Typical control bus signals are Memory Read,Memory Write, I/O Read, and I/O Write. To read a byte of data from a memory location.

For example, the CPU sends out the memory address of the desired byte on the address bus and then sends out a Memory Read signal on the control bus. The Memory Read signal enables the addressed memory device to output a data word onto the data bus. The data word from memory travels along the data bus to the CPU.

Central Processing Unit (CPU):

The Central Processing Unit or CPU controls the operation of the computer. In a computer the CPU is a microprocessor. The CPU fetches binary-coded instructions from memory, decodes the instructions into a series of simple actions, and carries out these actions in a sequence of steps.

The CPU also contains an address counter or instruction pointer register which holds the address of the next instruction or data item to be fetched from memory; general-purpose registers, which are used for temporary storage of binary data: and circuitry, which generates the control bus signals

Hardware, Software, and Firmware:

When working around computers, we hear the term hardware, software, and firmware almost constantly. Hardware is the name given to the physical devices and circuitry of the computer. Software refers to the programs written for the computer. Firmware is the term given to programs stored in ROMs or in other devices which permanently keep their stored information.

           Introduction to Microprocessor

Microprocessor is a clock driven semiconductor device. It can be manufactured by using either a large scale integration (LSI) or very large scale integration (VLSI) technique. The microprocessor is similar to CPU, but it includes all the logic circuitry, including the control unit. The micro processor contains three segments namely arithmetic logic unit (ALU),register array and control unit.

The microprocessor is capable of performing various computing functions and making decisions to change the sequence of program execution.

Working Principle of a Microprocessor:

It is the central processing unit which coordinates all the functions of computer. It generates timing Signals, sends and receives data to and from every peripheral used inside or outside the computer.

The commands required to do this are fed into the device in the form of current variations which are converted into meaningful instructions by the use of a Boolean Logic System. It divides its functions in two categories, logical functions and processing functions.

The arithmetic and logical unit and the control unit handle these functions respectively. The information is communicated through a bunch of wires called buses. The address bus carries the 'address' of the location with which communication is desired while the data bus carries the data that is being exchanged.

 

 ALU:

In this area various computing functions are performed on data. ALU unit performs such Arithmetic operations as addition, subtraction and such logic operations as AND,OR,Exclusive OR.

Register array:

          Microprocessor consists of various registers identified by letters such as B,C,D,E,H and L. It is used to store the data temporarily during execution of program.

Control unit:

          It provides necessary timings and control signals to all the operations in the micro computer. It controls the flow of data between the microprocessor and memory and pheripherals.

Applications of Microprocessor:

Microprocessor is a multi-use device which finds applications in almost all the fields. Here is some sample applications given in variety of fields.

Electronics: Digital clocks & Watches, Mobile phones, Measuring Meters.

 Mechanical: Automobiles, Lathes, All remote machines.

 Electrical: Motors Lighting controls, Power stations.

 Medical: Patient monitoring, Most of the Medical equipments, Data loggers.

Computer: All computer accessories, Laptops & Modems, Scanners and Printers.

 Domestic: Microwave Ovens, Television/CD/DVD players,Washing Machines.

                   Architecture of 8085

 8O85 microprocessor consists of various functional blocks as listed below

(i) Register

·        General Purpose Register

·        Temporary Register

·        Special Purpose Register

--Accumulator

--Flag Register

--Instruction Register

--Memory pointer register

(ii) Arithmetic Logic Unit(ALU)

(iii) Instruction Decoder and Machine Cycle Encoder

(iv) Address Buffer

(v) Data/Address Buffer

(vi) Incrementer/Decrementer Address Latch

(Vii) Interrupt Control

(Viii) Serial 1/O Control

(ix)Timing and Control Unit

 

 Registers of 8085:

Register is a group of binary cells. In 8085 the registers are divided into three categories

·        General Purpose register

·        Temporary Register

·        Special Purpose Register

General Purpose Register

·        The 8085 have six general purpose register to store s-bit data during program execution.

·        These registers are identified as B,C,D,E, H and L.

·        They can be combined as register pairs BC,DE and HL to perform some 16-bit operations.

Temporary Register

                It is an 8-bit register. It is used to hold the data during the arithmetic and logical operations. The various temporary registers in 8085 are W and Z register. It is used for temporary storage of data during the execution of an instruction.

Special Purpose Register:

Accumulator (A)

·        The accumulator is an 8-bit register that is part of the arithmetic logic unit (ALU).

·        This register is used to store 8-bit data and to perform arithmetic and logical operations.

·        The result of an operation is stored in the accumulator.

Flag Register

The ALU includes five flip-flops that are set or reset according to the result of an operation. The flags are affected by the arithmetic and logical operations in the ALU .The microprocessor uses the flags for testing the data conditions. The various flag register in 8085 are as follows:

·        Sign flag (S)

·        Zero flag(z)

·        Auxiliary Carry flag (AC)

·        Parity flag (P)

·        Carry flag (CY)

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

Z

 

AC

 

P

 

CY

S-Sign Flag

After execution of any arithmetic and logical operation, if D7 of the result is 1, the sign flag is set. Otherwise it is reset.

D7 is reserved for indicating the sign ;the remaining is the magnitude of

Number.

if D7 is 1,the number will be viewed as negative number. If D7 is 0, the

number will be viewed as positive number.

Z-Zero Flag

If the result of arithmetic and logical operation is zero, then zero flag is set otherwise it is reset.

AC - Auxiliary Carry Flag

In an arithmetic operation, when a carry is generated by digit D3, and passed onto digit D4, the AC flag is set, otherwise it is reset.

P- Parity Flag

If the result of arithmetic and logical operation contains even number of 1's then this flag will be set and if it is odd number of 1's it will be reset.

C-Carry Flag

If any arithmetic and logical operation result any carry then carry flag is set otherwise it is reset.

Instruction Register

When an instruction is fetched from the memory, it is loaded in the instruction register.

Memory Pointer Register:

Program Counter (PC)

·        This 16-bit register sequencing the execution of instructions.

·        It is a memory pointer. Memory locations have 16-bit addresses.

·        The function of the program counter is to point to the memory address of the next instruction to be executed.

·        When an opcode is being fetched, the program counter is incremented by one to point to the next memory location.

Stack Pointer (SP)

The stack pointer is also a 16-bit register used as a memory pointer.

·        It points to a memory location in R/W memory, called the stack.

·        The beginning of the stack is defined by loading a 16-bit address in the stack pointer (register).

Arithmetic and Logic Unit (ALU)

·        It is used to perform the arithmetic operations like addition,subtraction, multiplication, division, increment and decrement and logical operations like AND, OR and EX-OR.

·        It receives the data from accumulator and registers.

·        According to the result it set or reset the flags.

Instruction Decoder:

It gets the instruction from the instruction register and decodes the instruction It identifies the instruction to be performed.

Machine Cycle Encoder:

The 8085 microprocessor executes different types of machine cycles. It

gives the information about which machine cycle is currently executing in the encoded form on the S0,S1and IO/M lines.

Address Buffer:

·        The address bus is a group of 16 lines generally identified as A0 to A15.

·        The address bus is unidirectional: bits flow in one direction from the MPU to peripheral devices.

Data Buffer:

·        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 eight data lines enable the MPU to manipulate 8-bit data ranging from 00 to FF (28 = 256 numbers).

Incrementer/Decrementer Address Latch:

This 16-bit register is used to increment or decrement the contents of program counter and stack pointer.

Interrupt Control:

Interrupts are signals coming from external devices to call the attention

of the microprocessor. The 8085 has five interrupt signals. They are TRAP, RST7.5, RST 6.5, RST 5.5 and INTR.

Serial 1/0 Control:

The 8085 microprocessor provides two serial 1/0 controls.

(i) SID (Serial Input Data) - This line is used to receive data bit by bit(serially).

(ii)SOD(Serial Output Data) - This line is used to send data bit by bit (serially).

Timing and Control Unit:

This unit synchronizes all the microprocessor operations with the system clock.It also generates the control signals necessary for communicating in between the microprocessor and peripherals.

                        PIN Configurations Of 8085

8085 is a 40 pin IC. DIP package. All the signals can be classified into five groups.

1. Power supply and clock signals

2. Address bus

3. Data bus

4. Control and status signals

5. Interrupts and externally initiated signals

  


Power supply and Clock frequency signals:

Vcc: +5 volt power supply

Vss: Ground terminal

XI, X2: Crystal or R/C network or LC network connections to set the frequency of internal clock generator. The frequency is internally divided by two. Since the basic operating timing frequency is 3MHz ,a 6 MHz crystal is connected externally.

CLK -Clock Output is used as the system clock for peripheral and devices interfaced with the microprocessor.

Address Bus:

A8- A15

·        It carries the most significant 8 bits of the memory address or the 8 bits of the I/O address.

Multiplexed Address / Data Bus:

AD0 - AD7

·        These multiplexed set of lines used to carry the lower order 8 bit address as well as data bus.

·        During the opcode fetch operation, in the first clock cycle, the lines deliver the lower order address A0-A7.

·        In the subsequent I/O memory, read/write clock cycle the lines are used as data bus.

·        The CPU may read or write out data through these lines.

Control and Status signals:

ALE -Address Latch Enable

·        This signal helps to capture the lower order address presented on the multiplexed address/data bus.

RD (Read)- Read memory or IO device:

·        This indicates that the selected memory location or l/O device is to be read and that the data bus is ready for accepting data from the memory or I/O device.

WR (Write) - Write memory or IO device:

·        This indicates that the data on the data bus is to be written into the selected memory location or I/O device

IO/M (InputOutput/Memory) - Select memory or an 10 device.

·        This status signal indicates that the read/write operation relates to whether the memory or I/O device

·        It goes high to indicate an I/O operation.

·        It goes low for memory operations.

S0 and S1 - These are status signals, similar to IO/M. These signals can be used to identify various machine cycle operations.

Interrupts and Externally initiated operations

They are the signals initiated by an external device to request the microprocessor to do a particular task or work. There are five hardware interrupts called

TRAP

RST 7.5

RST 6.5

RST 5.5

INTR

INTA ( active low output)

On receipt of an interrupt, the microprocessor acknowledges the interrupt by the active low INTA (Interrupt Acknowledge) signal.

Reset In:

·        This signal is used to reset the microprocessor.

·        The program counter inside the microprocessor is set to zero.

·        The buses are tri-stated.

Reset Out:

·        It indicates CPU is being reset.

·        Used to reset all the connected devices when the microprocessor is reset.

READY:

·        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.

Single Bit Serial I/O ports:

SID - Serial input data line

SOD -Serial output data line

These signals are used for serial communication.


       Instruction classifications of 8085 microprocessor

An instruction is a binary pattern designed inside a microprocessor to perform a specific function. The entire group of instructions, called the instruction set.

These instructions can be classified into the following five functional categories:

1. Data transfer (copy) operations

2. Arithmetic operations

3. Logical operations

4. Branching operations

S. Machine-control operations

Data Transfer (Copy) Operations:

This group of instructions copy data from a location called a source to another location called a destination, without modifying the contents of the source.

After data transfer the contents of the source could not be varied. Data transfer instructions moves or copies data between registers, between memory and registers and specific data byte to a register or a memory location.

Arithmetic Operations:

These instructions perform arithmetic operations such as addition, subtraction, increment, and decrement.

Addition Any 8-bit number, or the contents of a register or the contents of a memory location can be added to the contents of the accumulator and the sum is stored in the accumulator. No two other 8-bit registers can be added directly. For Example, the contents of register B cannot be added directly to the contents of the register C.

Subtraction - Any 8-bit number, or the contents of a register, or the contents of a memory location can be subtracted from the contents of the accumulator and the results stored in the accumulator. The subtraction is performed in 2’s complement, and the results if negative, are expressed in 2’s compliment. No two other registers can be subtracted directly.

Increment/Decrement - The 8-bit contents of a register or a location can be incremented or decrement by 1. Similarly, the 16-bit content of a register pair such as (BC,DE,HL) can be incremented or decremented by 1. These Increment and  decrement operations differ from addition and subtraction in an important way: i.e. they can be performed in any one of the register or in  memory location.


Logical Operations:These instructions perform various logical operations with the content of the accumulator.

·        AND, OR Exclusive-OR-  Any 8-bit number, or the contents of register, or of a memory location can be logically ANDed, ORed, Exclusive-ORed with the contents of the accumulator. The results are stored in the accumulator.

·        Rotate- Each bit in the accumulator can be shifted either left or right to the next position.

·        Compare- Any 8-bit number, or the contents of a register, or a memory location can be compared for equality, greater than, or less than, with the contents of the accumulator.

·        Complement - The contents of the accumulator can be complemented

All 0’s are replaced by 1’s and all 1’s are replaced by 0’s.


Branching Operations:This group of instructions alters the sequence of program execution either conditionally or unconditionally.
  • Jump Conditional jumps are an important aspect of the decision making process in the programming .These instructions test for a certain conditions (eg. Zero or Cary flag) and alter the program sequence when the condition is met. In addition, the instruction set includes an instruction called unconditional jump.
  • Call, Return, and Restart- These instructions change the sequence of a program either by calling a subroutine or returning from a  subroutine. The conditional Call and Return instructions also can test condition flags.
Machine Control Operations: These instructions control machine functions such as Halt, Interrupt or no operation. The microprocessor operations related to data manipulations can be summarized in four functions:

1. Copying data

2. Performing arithmetic operations

3. Performing logical operations

4. Testing for a given condition and altering the program sequence.


             Programming techniques such as Looping, Counting and Indexing And Addressing Modes

The programming techniques used to instruct the microprocessor to repeat tasks is called looping. A loop is set up by instructing the microprocessor  to change the sequence of execution and perform the task again. Looping is accomplished by using jump instructions.

Loops can be classified into two groups

1. Continuous loop

2. Conditional loop

Continuous loop

A continuous loop is set up by using the unconditional jump instruction.This loop repeats a task continuously. A program with a continuous loop does not stop repeating the tasks until the system is reset.

Example Continuous monitor system.


 


 Conditional loop

A conditional loop is set up by the conditional jump instructions. These instructions checks zero, carry ,flags etc and repeat the specified tasks if the Conditions are satisfied. These loops usually include counting and indexing.

                        

Counting

Counting is a programming techniques used to count the number of execution of a loop for this job a counter will be used. Counting is always associated with looping. A counter is a typical application of the conditional loop.

For Example: If the microprocessor  wants to repeat a task for five times, the microprocessor needs a counter, and when counting is completed, it needs a flag for

checking the counter state.

Indexing

Indexing means pointing or referencing objects with sequential numbers. For example: In a library books are arranged according to numbers, and they are referred to or sorted by numbers. This is called indexing.

Similarly, data bytes are stored in memory locations, and those data bytes are referred to by their memory locations.

                        Addressing modes

The program and data are stored in main memory. Each instruction of the program specifies the operation to be performed on same data which may in the registers (or) in memory or in the instruction itself. The way the operands (the data) are chosen during execution is depended on the addressing modes.

Different techniques are adopted to specify the data. These techniques are called "addressing modes"

In the 8085, there are five addressing modes are used:

1. Direct addressing

2. Register addressing.

3. Register indirect addressing.

4. Immediate addressing.

5. Implicit/implied addressing.

Direct addressing

In this mode, the address of the operand is explicitly specified within the instruction itself. All such instructions are 3 bytes long LDA and STA are two of the several instructions using direct addressing.

For Example :LDA 4500H

Register addressing

In this mode, the data is in any one of the general purpose registers and the register name is specified in the instruction. This addressing mode is fast.

For Example: ADD C

Register Indirect Addressing

In register indirect addressing mode, the instruction specifies the name of the register in which the address of the data is available. Here the data will be in memory and the address will be in the register pair.

Example: MOV M,A -  Stores the contents of accumulator into the memory location pointed by HL register pair.

Immediate Addressing

Here the Instruction contains neither address of the data nor register name that contains the data (or) Here the data is given in the instructor itself. The 8-bit (or) 16-bit data follows the instructor immediately. Immediate instruction is commonly used to provide constant data type or for initializing the register.

(i)MVI A,10 (ii)ADI 10 (iii)LXI H,5000 (iv)CPI 05

Implicit / Implied Addressing

There are some instructions that operate only on one operand. Such instruction assume that the operand is in the Accumulator and therefore require no address specification.

Example RLC, RRC and CMA

                   Assembly Language

The mnemonic (each manufacturer of a microprocessor has devised a symbolic code for each instruction) for a particular instruction consists of letters that represent the operation to be performed by that instruction. Hence the computer manufactures have devised English-like words represent the binary instructions of a machine, called Assembly Language.

The mnemonics that can be written by hand on paper and translated manually in hexadecimal code is called hand assembly. Similarly, the mnemonics that can be written electronically on a computer using a program and translated into binary code by using the program is called assembler. Hence an assembler converts the program is assembly language into machine language

Advantages/merits of Assembly Language

·        Assembly language programs are easy to understand than machine language.

·        Faster translation time.

·        Reduced Errors.

·        Change could be made easier and faster.

·        Small volume of data are to be processed.

·        For industrial applications.

Disadvantages/Demerits of Assembly Language

·        Assembly Language is different for different machine (machine dependent)

·        It requires a translator to translate assembly language to machine language

·        Many instructions are required to achieve small tasks.

Assembly Language Programming (ALP)

A program is a set of instructions arranged in the specific sequence to do the specific code. The process of writing the set of instructions which tells the microprocessor what to do is called Programming." Assembly language operation codes (opcodes) are easily remembered (MOV for move instructions, JMP for jump).

Assembly Language Statement Format

Assembly Language Programs are usually written in standard form. A typical assembly language programming statement is divided into four parts called fields They are

1.  Label

2. Operation code (Opcode)

3. Operand

4 Comments

The fields are separated by delimiters. The assembly language format of a particular is shown below.

     Label         Opcode Operand          Comment

    LOOP:                 LXI                         H,2500 : Initiate the HL register pair

 

1.  Label ---  This filed has a symbol or group of symbols used to represent the address of other instructions. It is mainly used in branching instructions. The assembler will assign memory address to the labels in the label field. The length of the label should be written six characters.

2. Opcode --- The operation code field usually contains the mnemonics instruction code. This field can never be empty. The assembler will translate these opcode into its corresponding binary code.

3. Operand --- This field contains the name of registers, data or address of the memory location on which the operation is to be performed.

4. Comment ---This filed is used to explain the function of the instruction.

 

                     Assembler Directives

The assembler directives are the instructions to the assembler concerning the program to be assembled. They are also called pseudo instructions. These instructions are neither translated into machine code nor assigned any memory locations in the object file. Some of the assembler directives are shown below.

ORG(Origin) --This instructions specifies the address of following instructions to be stored. For example, ORG 2500, instruct the assembler to store the program from memory location 2500H.

END --This instruction indicates the end of assembly language program.

EQU (Equate) -- This instruction allow the user to assign numerical value to a symbolic name

DB (Define Byte) -- This instruction instruct the assemble for reserving the successive memory location.

DW (Define Word) -- This instruction instructs the assembler for reserving two successive memory locations.

DS (Deſine Storage) -- This instruction instructs the assembler for reserving a block of memory locations for data storage.

 

                        Instruction Format

An instruction is a binary pattern entered through an input device to command the microprocessor to perform that specific function. The 8085 instruction consists of one, two, and three byte instructions,

One byte Instruction:

A one byte instruction includes the Opcode and operand in the same byte

General Format: Opcode

Example: MOV D, A

This instruction copy the contents of the accumulator into register.

Two Byte Instructions:

In a two byte instruction, the first byte specifies the operation code(Opcode) and the second byte specifies the operand.

General Format: Opcode (Operand)

Example: MVI D,O5H

This instruction load on 8-bit data (05H) in to the D register.

Three Byte Instructions:

In a three byte instruction, the first byte specifies the Opcode and the second and third byte specifies the operand.

General Format: Opcode operand1 operand2

Example: LDA 2050H

This instruction load the accumulator with the content of memory  location 2050H

 

Writing assembly level programs

To write a program, one needs to draw up a plan of logical thoughts. A given task should be broken down into small units that can be built independently. This is called the modular design approach.

Writing a program is equivalent to giving specific commands to the microprocessor in a sequence to perform a task.

The programming process the following:

Step 1 : Read the problem carefully.

Step 2 : Break it down into small steps.

Step 3 : Represent these small steps in a possible sequence with a flow chart.

Step 4 : Translate each block of the flow chart into appropriate mnemonic instruction.

Step 5: Translate mnemonics into machine code.

Step 6: Enter the machine code in memory and execute.

Step 7: In case of any error debug the program.

Instruction set of 8085

          An instruction is a binary pattern entered through an input device to command the microprocessor to perform that specific function. The various instruction in 8085 are as follows:

·        Data transfer Instructions.

·        Arithmetic Instructions.

·        Branch Instructions.

·        Logical Instructions.

·        Machine Control Instructions.

 Data-transfer instructions with their meanings.

Opcode

Operand

Meaning

Explanation

MOV

Rd, Sc
M, Sc
Dt, M

Copy from the source (Sc) to the destination (Dt)

This instruction copies the contents of the source register into the destination register without any alteration.
Example  − MOV H, L

MVI

Rd, data
M, data

Move immediate 8-bit

The 8-bit data is stored in the destination register or memory.
Example  − MVI B, 55H

LDA

16-bit address

Load the Accumulator

The contents of a memory location, specified by a 16-bit address in the operand, are copied to the Accumulator.
Example  − LDA 2034H

LDAX

B/D Reg. pair

Load the Accumulator indirect

The contents of the designated register pair point to a memory location. This instruction copies the contents of that memory location into the Accumulator.
Example  − LDAX B

LXI

Reg. pair, 16-bit data

Load the register pair immediate

The instruction loads 16-bit data in the register pair designated in the register or the memory.
Example  − LXI B, 3225H

LHLD

16-bit address

Load H and L registers direct

The instruction copies the contents of the memory location pointed out by the address into register L and copies the contents of the next memory location into register H.
Example  − LHLD 3225H

STA

16-bit address

16-bit address

The contents of the Accumulator are copied into the memory location specified by the operand.
This is a 3-Byte instruction, the second Byte specifies the low-order address and the third Byte specifies the high-order address.
Example  − STA AB00H

STAX

16-bit address

Store the Accumulator indirect

The contents of the Accumulator are copied into the memory location specified by the contents of the operand.
Example  − STAX 4050H

SHLD

16-bit address

Store H and L registers direct

The contents of register L are stored in the memory location specified by the 16-bit address in the operand and the contents of H register are stored into the next memory location by incrementing the operand.
This is a 3-Byte instruction, the second Byte specifies the low-order address and the third Byte specifies the high-order address.
Example  − SHLD 3225H

XCHG

None

Exchange H and L with D and E

The contents of register H are exchanged with the contents of register D, and the contents of register L are exchanged with the contents of register E.
Example  − XCHG

SPHL

None

Copy H and L registers to the stack pointer

The instruction loads the contents of the H and L registers into the stack pointer register.
The contents of the H register provide the high-order address and the contents of the L register provide the low-order address.
Example  − SPHL

XTHL

None

Exchange H and L with top of stack

The contents of the L register are exchanged with the stack location pointed out by the contents of the stack pointer register.
The contents of the H register are exchanged with the next stack location (SP+1).
Example  − XTHL

PUSH

Reg. pair

Push the register pair onto the stack

The contents of the register pair designated in the operand are copied onto the stack in the following sequence.
The stack pointer register is decremented and the contents of the high order register (B, D, H, A) are copied into that location.
The stack pointer register is decremented again and the contents of the low-order register (C, E, L, flags) are copied to that location.
Example  − PUSH B

POP

Reg. pair

Pop off stack to the register pair

The contents of the memory location pointed out by the stack pointer register are copied to the low-order register (C, E, L, status flags) of the operand.
The stack pointer is incremented by 1 and the contents of that memory location are copied to the high-order register (B, D, H, A) of the operand.
The stack pointer register is again incremented by 1.
Example  − POP B

OUT

8-bit port address

Output the data from the Accumulator to a port with 8 bit address

The contents of the Accumulator are copied into the I/O port specified by the operand.
Example  − OUT 01H

IN

8-bit port address

Input data to Accumulator from a port with 8-bit address

The contents of the input port designated in the operand are read and loaded into the Accumulator.
Example − IN 04H

 

Arithmetic instructions with their meanings.

Opcode

Operand

Meaning

Explanation

ADD

R
M

Add register or memory, to the Accumulator

The contents of the register or memory are added to the contents of the Accumulator and the result is stored in the Accumulator.
Example  − ADD B.

ADC

R
M

Add register to the Accumulator with carry

The contents of the register or memory & M the Carry flag are added to the contents of the Accumulator and the result is stored in the Accumulator.
Example − ADC B

ADI

8-bit data

Add the immediate to the Accumulator

The 8-bit data is added to the contents of the Accumulator and the result is stored in the Accumulator.
Example − ADI 55H

ACI

8-bit data

Add the immediate to the Accumulator with carry

The 8-bit data and the Carry flag are added to the contents of the Accumulator and the result is stored in the Accumulator.
Example  −ACI 55H

LXI

Reg. pair, 16bit data

Load the register pair immediate

The instruction stores 16-bit data into the register pair designated in the operand.
Example  − LXI H, ABCDH

DAD

Reg. pair

Add the register pair to H and L registers

The 16-bit data of the specified register pair are added to the contents of the HL register.
Example  − DAD B

SUB

R
M

Subtract the register or the memory from the Accumulator

The contents of the register or the memory are subtracted from the contents of the Accumulator, and the result is stored in the Accumulator.
Example  − SUB B

SBB

R
M

Subtract the source and borrow from the Accumulator

The contents of the register or the memory & M the Borrow flag are subtracted from the contents of the Accumulator and the result is placed in the Accumulator.
Example  − SBB B

SUI

8-bit data

Subtract the immediate from the Accumulator

The 8-bit data is subtracted from the contents of the Accumulator & the result is stored in the Accumulator.
Example  −SUI 55H

SBI

8-bit data

Subtract the immediate from the Accumulator with borrow

The 8-bit data is subtracted to the contents of the Accumulator and the result is stored in the Accumulator.
Example  −SBI 55H

INR

R
M

Increment the register or the memory by 1

The contents of the designated register or the memory are incremented by 1 and their result is stored at the same place.
Example  − INR B

INX

R

Increment register pair by 1

The contents of the designated register pair are incremented by 1 and their result is stored at the same place.
Example  − INX B

DCR

R
M

Decrement the register or the memory by 1

The contents of the designated register or memory are decremented by 1 and their result is stored at the same place.
Example  − DCR B

DCX

R

Decrement the register pair by 1

The contents of the designated register pair are decremented by 1 and their result is stored at the same place.
Example  − DCX B

DAA

None

Decimal adjust Accumulator

The contents of the Accumulator are changed from a binary value to two 4-bit BCD digits.
If the value of the low-order 4-bits in the Accumulator is greater than 9 or if AC flag is set, the instruction adds 6 to the low-order four bits.
If the value of the high-order 4-bits in the Accumulator is greater than 9 or if the Carry flag is set, the instruction adds 6 to the high-order four bits.
Example  − DAA

 

Branching instructions with their meanings.

 

Opcode

Operand

Meaning

Explanation

JMP

16-bit address

Jump unconditionally

The program sequence is transferred to the

memory address given in the operand.

Opcode

Description

Flag Status

JC

Jump on Carry

CY=1

JNC

Jump on no Carry

CY=0

JP

Jump on positive

S=0

JM

Jump on minus

S=1

JZ

Jump on zero

Z=1

JNZ

Jump on no zero

Z=0

JPE

Jump on parity even

P=1

JPO

Jump on parity odd

P=0

16-bit address

Jump conditionally

The program sequence is transferred to the

memory address given in the operand based

 on the specified flag of the PSW.

Opcode

Description

Flag Status

CC

Call on Carry

CY=1

CNC

Call on no Carry

CY=0

CP

Call on positive

S=0

CM

Call on minus

S=1

CZ

Call on zero

Z=1

CNZ

Call on no zero

Z=0

CPE

Call on parity even

P=1

CPO

Call on parity odd

P=0

16-bit address

Unconditional subroutine call

The program sequence is transferred to the

memory address given in the operand.

Before transferring, the address of the next

instruction after CALL is pushed onto the stack.

RET

None

Return from subroutine unconditionally

The program sequence is transferred from the subroutine to the calling program.

Opcode

Description

Flag Status

RC

Return on Carry

CY=1

RNC

Return on no Carry

CY=0

RP

Return on positive

S=0

RM

Return on minus

S=1

RZ

Return on zero

Z=1

RNZ

Return on no zero

Z=0

RPE

Return on parity even

P=1

RPO

Return on parity odd

P=0

None

Return from subroutine conditionally

The program sequence is transferred from the subroutine to the calling program based on the specified flag of the PSW and the program

 execution begins at the new address.

PCHL

None

Load the program counter with HL contents

The contents of registers H & L are copied

 into the program counter. The contents of

 H are placed as the high-order Byte and the

contents of L as the low-order Byte.

RST

0-7

Restart

The RST instruction is used as software

instructions in a program to transfer the

program execution to one of the following

eight locations.

Instruction

Restart Address

RST 0

0000H

RST 1

0008H

RST 2

0010H

RST 3

0018H

RST 4

0020H

RST 5

0028H

RST 6

0030H

RST 7

0038H

The 8085 has additionally 4 interrupts, which can generate RST instructions internally and

doesn’t require any external hardware. Following are those instructions and their Restart addresses

Interrupt

Restart Address

TRAP

0024H

RST 5.5

002CH

RST 6.5

0034H

RST 7.5

003CH

 

Logical instructions with their meanings.

Opcode

Operand

Meaning

Explanation

CMP

R
M

Compare the register or memory with the Accumulator

The contents of the operand (register or memory) are M compared with the contents of the Accumulator.

CPI

8-bit data

Compare immediate with the Accumulator

The second Byte data is compared with the contents of the Accumulator.

ANA

R
M

Logical AND register or memory with the Accumulator

The contents of the Accumulator are logically AND with M the contents of the register or memory, and the result is placed in the Accumulator.

ANI

8-bit data

Logical AND immediate with the Accumulator

The contents of the Accumulator are logically AND with the 8-bit data and the result is placed in the Accumulator.

XRA

R
M

Exclusive OR register or memory with the Accumulator

The contents of the Accumulator are Exclusive OR with M the contents of the register or memory, and the result is placed in the Accumulator.

XRI

8-bit data

Exclusive OR immediate with the Accumulator

The contents of the Accumulator are Exclusive OR with the 8-bit data and the result is placed in the Accumulator.

ORA

R
M

Logical OR register or memory with the Accumulator

The contents of the Accumulator are logically OR with M the contents of the register or memory, and result is placed in the Accumulator.

ORI

8-bit data

Logical OR immediate with the Accumulator

The contents of the Accumulator are logically OR with the 8-bit data and the result is placed in the Accumulator.

RLC

None

Rotate the Accumulator left

Each binary bit of the Accumulator is rotated left by one position. Bit D7 is placed in the position of D0 as well as in the Carry flag. CY is modified according to bit D7.

RRC

None

Rotate the Accumulator right

Each binary bit of the Accumulator is rotated right by one position. Bit D0 is placed in the position of D7 as well as in the Carry flag. CY is modified according to bit D0.

RAL

None

Rotate the Accumulator left through carry

Each binary bit of the Accumulator is rotated left by one position through the Carry flag. Bit D7 is placed in the Carry flag, and the Carry flag is placed in the least significant position D0. CY is modified according to bit D7.

RAR

None

Rotate the Accumulator right through carry

Each binary bit of the Accumulator is rotated right by one position through the Carry flag. Bit D0 is placed in the Carry flag, and the Carry flag is placed in the most significant position D7. CY is modified according to bit D0.

CMA

None

Complement Accumulator

The contents of the Accumulator are complemented. No flags are affected.

CMC

None

Complement carry

The Carry flag is complemented. No other flags are affected.

STC

None

Set Carry

Set Carry

 

Machine Control instructions with their meanings.

Opcode

Operand

Meaning

Explanation

NOP

None

No operation

No operation is performed, i.e., the instruction is fetched and decoded only.

HLT

None

Halt and enter wait state

The CPU finishes executing the current instruction and stops further execution. An interrupt or reset is necessary to exit from the halt state.

DI

None

Disable interrupts

The interrupt enable flip-flop is reset and all the interrupts are disabled except TRAP.

EI

None

Enable interrupts

The interrupt enable flip-flop is set and all the interrupts are enabled.

RIM

None

Read interrupt mask

This instruction is used to read the status of interrupts 7.5, 6.5, 5.5 and read serial data input bit.

SIM

None

Set interrupt mask

This instruction is used to implement the interrupts 7.5, 6.5, 5.5 and serial data output.

 

RIM (READ Interrupt Mask)

 


SIM (SET Interrupt Mask)

 

Dynamic Debugging

The term Debugging means eliminating or removing errors from the programs. The debugging process can be divided into two parts :Static debugging and Dynamic Debugging .Static debugging is just a visual inspection and done by checking the flowchart and machine code. After the static debugging, if the program still does not produce the expected output, one can attempt to debug the program by observing the execution of instructions. This is called Dynamic Debugging,

Tools for Dynamic Debugging

In a single-board micro computer, techniques and tools commonly used  in dynamic debugging are:

1. Single-step

2 Register Examine

3. Breakpoint

Single-Step:

The single-step key on a keyboard allows to execute one instruction at time, and to observe the results following each instruction with the single Step by step technique and the following errors can be found out

·        Incorrect addresses

·        Incorrect jump locations for loops

·        Incorrect data or missing codes.

Register Examine:

The Register Examine key allows to examine the contents of the microprocessor register. After executing a block of instructions, one can examine the register contents and compare these contents with the expected outputs.

Breakpoint:

In the single-board computer, the breakpoint facility is generally, a  software routine that allows to execute a program in sections. The breakpoint can be set in your program by using RST instructions. The program will be executed until the breakpoint. If the segment of the program is found correct, a second breakpoint can be set at a subsequent memory address to debug the next segment of the program. Using this technique the segment with errors can be isolated and debugged with single-step facility. This technique can be used to check out the timing loop, I/0 section and interrupts.

Counters

Counters are sequential circuits which count the number of clock pulses. Counters are used to count number of clock pulses, frequency division and mathematical manipulation. Counters are made up of a set of Flip-flops. Designing a counter is a frequent programming application. A counter is designed simply by loading an appropriate number into one of the registers and using the INR (Increment by 1) or the DCR (Decrement by 1)instructions.

A loop is established to update the count and cach count is checked to determine whether it has reached the final number, if not, the loop is repeated Counters are used primarily to keep track of events.

         

 Time Delay

 

·        Time delay is the timing between two events.

·        A time delay is designed by loading a register with a delay count and setting   up a loop to decrement the count until zero.

·        The delay is determined by the clock period of the system and the time required to execute the instructions in the loop.

·        A register is loaded, with a number, depending on the time delay required, and then the register is decremented until it reaches Zero by setting up a loop with a conditional Jump Instruction.

·        The loop causes the delay. depending upon the clock period of the system.

·        Counter and time delays are important techniques.

·        They are commonly used in applications such as traffic signals, digital clocks. process control, and serial data transfer.

·        The process of designing, counters and time delays using software instructors is more flexible and less time consuming than the design process using hardware

·        Time delays are important in setting up reasonably accurate timing between two events.

The Time Delay is divided into three types: They are:

1. Time Delay using one register

2 .Time Delay using register pair

3 .Time Delay using looping technique

 

Time Delay using one register

              MVI C,FF    ;To execute this instruction the 8085 Mp requires

                                     7-T states(clock periods)

LOOP:  DCR C          ;Decrement C  Here 4-T states

             JNZ LOOP    ;Jump back to decrement C Here  10 or 7 states

Flow Diagram:

                  

Calculation:

 

TL=( T*Loop T states * N10)         The time delay   in the loop TL with   2 MHz clock frequency is calculated as follows:

                        

Where TL= Time delay in loop

T = System Clock period

N10 = equivalent decimal  number of the hex number loaded in delay register

Clock period T = 1/f =1/2 *10 -6 = 0.5 μs ( f=clock frequency = 2MHZ)

 

   N10 = (FF)16 = (225)10 , loop T- states = 4+10=14

     TL=( T*Loop T states * N10)

         =(0.5 *10 -6 *14*255)

         = 1785 μs = 1.8 ms

  TLA = TL-(3T –States *T)

         =1785 μs -1.5 μs =1783.5 μs

To calculate total delay as follows:

Total delay = Time to execute outside loop instruction

                                             + Time to execute loop instruction

TD = TO + TLA

        = (7 *0.5 μs ) +1783.5 μs

      = 1787 μs

         

Time Delay using a register pair

          The time delay is increased  by setting a loop and using register pair with a 16-bit number.The DCX instruction is used to decrement the register by 1.

   Label                 Opcode           Operand               Comments                    T states

                               LXI               B,2384            Load BC with 16-bit count      10

 LOOP:                  DCX              B                     Decrement BC by 1                  6

                               MOV            A,C                  Place contents of C in A           4

                               ORA             B                      OR B with C to set Zero flag   4

                               JNZ              LOOP                  if result not equal to 0 ,         10/7

                                                                             jump back to loop

·        The first instruction loads the BC register pair with given data i.e B=23,C=84.

·        DCX decrements BC content by 1 i.e 2383.

·        DCX does not set the 0 flag and without the test flags jump instruction cannot check the instruction.

·        So the next 2 instructions are used to set zero flag.

·        OR instruction sets Zero flag only when the contents of B and C are simultaneously zero.

·        Therefore the loop is repeated 2384 times.

Calculations:

Here,

        N10 = 9092(i.e (2384)16 = (9092)10)

        T – states = 24(DCX-6,MOV-4,ORA -4,JNZ-10= 6+4+4+10 = 24)

        T= 0.5 (because 2MHZ system)

        TL= (0.5*24*9092) [TL=(T*T-states *N10)]

             = 109ms

Time Delay using Looping technique:

        A time delay similar to that of a register pair can also be achieved by using two loops; one loop inside other loop.

                    Mnemonics          T states

                    MVI B, 38              7T

LOOP2:       MVI C, FF              7T

LOOP1:       DCR C                   4T

                     JNZ LOOP1          10/7 T

                     DCR B                   4T

                     JNZ LOOP2         10/7T

Calculations:

    TL= TL1+TL2   (TL = Inner loop + Outer loop)

     TL1= 1783.5 [Already discussed in time delay using one register]

     TL2 = (T*T-state * TL1)*N10

      T = 0.5 ; T-States =21 ;   TL1= 1783.5; N10=56

      TL2= (0.5 *21 + 1783.5)*56

            = (10.5+1783.5) *56

            = 100.46ms

The total delay should include execution time of first instruction (MVI B,38)

     TD= TL1+TL2 +TLA

         = 1783.5+100.46+7

         = 1890.96ms

Stack

  •        The stack is a group of memory locations in R/W memory that is used for temporary storage of data during the execution of a program.
  •         Data has to be stored in the stack on a last-in-first-out (LIFO) basis.
  •         Only two operations can be used on the stack, the PUSH and POP operations.
  •         When the data is saved in the stack it is called "PUSH on to stack”.
  •         When the data is read from the stack it is called "POP from stack".
  •         The stack always has a unique location known as the stack top.
  •         A special 16-bit register in the up known as Stack Pointer (SP) used to hold the address of the stack top location.
  •         Any area of memory can be used as a stack. The Microprocessor does not put only restriction on the location of the stack in the memory.
  •         The maximum size of the stack depends on the amount of memory available in the microcomputer.
  •         Most Microprocessor provides a stack pointer for the maintenance of a stack in the memory Such a stack is also known as an External Stack.
  •         Some up contains a few registers that are used as stack. Such stacks are also known as internal stack

 

Programming with Stack

  •         The beginning of a stack is defined in the program by using the instruction LXI SP,16-bit address which loads a 16-bit address in the stack pointer register.
  •         Once the stack location is defined, storing of data begins at the memory address that is one less than the address in the stack pointer.
  •         For e.g IF Sp loaded with 4099, than the storing of data begins at 4098 and continues in descending order (i.e 4098,4097,4096,…)
  •         Data bytes in the register pairs of the up can be stored on the stack  (two at a time) in reverse order by using the instruction PUSH.
  •         Data bytes can be transferred from the stack to respective registers by using the instructions POP.
  •         When the data is stored / pushed into the stack the stack pointer  decremented by two.
  •         When the data is retrieved /popped from the stack the stack point gets incremented by two.
  •         Because push and pop operations will insert/delete two data types at a time.
  •         The address of the stack pointer indicates the next two memory locations can be used for storage.

Example

       POP PSW: (content of stack pointer & flag register)

Contents of stacks are copied into Acc & flag register.

-Higher order bit firstà Flag

-Lower order bit second àAcc

-Stack pointer decrement by two

       SPHL (load stack pointer with HL)

.

-The contents of HL reg pair is loaded in the stack pointer.

Example

               LXI SP, 6000    ; Here stack pointer is loaded with 6000

               LXI H, 1234      ;This indicates that the memory space for stack is

                                            reserved from 6000

               PUSH H            ;The starting location top first location is 6000 and

                                          can move upwards that is descending

MVI, OF              ;The data can be stored from 5999, 5998…..

Loop: DCR H                 ;The contents of HL (1234) is push into stack.

          JNZ Loop             ; A delay routine is performed at last

          POP H                  ;HL values are popped from the stack

          HLT                      ;Stop

 

Subroutine:

  •         A subroutine is a group of instructions written separately from the main program a function that occurs repeatedly in the main program.
  •         For example, if a time delay is required between three successive events, three delays can be written in the main program.
  •         To avoid repetition of the same delay instructions, the subroutine technique is used
  •         Delay instructions are written once, separately from the main program and are called by the main program when needed.
  •         8085 up has two instructions to implement subroutines
             CALL
             RET
  •         CALL is used to call a subroutine from the main program.
  •         RET is used at the end of the subroutine to return to the main program.
  •         When a subroutine is called, the content of the program counter (which is the address of the instructions, following the CALL instruction that is next to 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 address and the sequence of execution is resumed in the main program.

Example

conversion of ASCII to HEX

example for CALL and RET instructions.

 

  MVI  A, 35      ;Aß35

  CALL HEX     ;CALL the subroutine HEX

  STA 8000        ;After return store Acc at 8000

  HLT                 ;STOP

 HEX:  SUI 30             ;subroutine HEX: Aß A-30

            CPI OA            ;compare Acc with 10

           RC                 ;Return to main program if cy=1

           SUI  07          ;if cy=0 AßA-07

           RET               ;return to calling program.

 

Debugging Counter and Time Delay Program:

 

   Debugging Counter and Time-Delay Programs

·        The Static and Dynamic debugging techniques can be used to check errors in a counter program

·        The following is a list of common errors in programs.

·        Errors in counting T-States in a delay loop.

  •         Errors in recognizing how many times a loop is repeated.
  •         Failure to convert a delay count from Decimal to hexadecimal equivalent
  •         Specify a wrong jump location.
  •         Failure to set a flag.
  •         Using a wrong jump instruction.
  •         Failure to display either the first or last count.
  •         Failure to provide a delay between the last and last-but-one count.

Example

MVI  A, 64

DSPLAY:    OUT PORTI

LOOP2 :      MVI B, 10

LOOP1:       LXI D. DELAY

DCX D

NOP

NOP

MOV A, D

ORA E

JNZ LOOP1

DCR B

JZ LOOP2

DCR A

CPI 00

JNZ  DISPLAY

·        The above program is designed to count from 100 to 0 Hex continuously, with a l-second delay belween each count.

• The delay is setup by using two loops-a loop within a loop.

• The inner loop is used to provide 100 ms delay.

• The outer loop is used to repeat inner loop for 10 times to provide second total delay

• The clock period of the system is 330 ns.

Debugging the given program

The given program consists of several errors:

1. The label Loop is not at the correct location So alter Loopl in a correct place.

2. Calculate the delay count accurately and move to DE.

3. The 8th instruction MOV A. D is wrong and it will spoil the program because the count 64 will be over write by the value of D if the instruction is executed.

4. The location of Loop2 is not correct and the 12th instruction JZ Loop2 is not a correct condition.

5. The 14th instruction CPI is not necessary. There is no need for this instruction.

6. The given Delay calculations are wrong and calculate the new Delay calculations for the new program.

After Debugging                            T-States

                      MVI H, 64                                        7

DISPLAY:    OUT PORTI                                    10

                      MVI B, OA                                      7

Loop2:          LXI D, DELAY                               10

Loopl:           DCX D                                             6

                      NOP                                                 4

                      NOP                                                 4

                      MOV A, E                                       4

                     ORA D                                             4

                     JNZ Loop1                                      10/7

                     DCR B                                              4

                     JNZ Loop2                                     10/7

                     DCR H                                              4

                     JNZ DISPLAY                               10/7

 

DELAY CALCULATIONS:

  

 Conditional Call and Return Instructions

CALL (Unconditional Call)

CALL address (unconditional call/subroutines)

•     Before call instruction is executed the address of the next to CALL,

     instruction is loaded in the stack and execution continues.

·        When a return instruction is executed the address which was saved in stack is passed and execution starts from that address.

·        CALL instruction is a three byte instruction. The first byte specifies the Opcode, the second and third gives the 16-bit starting address of the instruction

Conditional Call

Instruction           Flags checked

CC address           Cy=1

CNC address        Cy=0

CZ address           Z=1

CNZ address        Z=0

CP address           S=0

CM address                   S=1

CPE address         P=1

CPO address        P=0

Unconditional Return

This instruction pops the return address from the stack and loads Program counter with this return address. Return to the calling program after completing the subroutine.

General Format: RET

Example :RET

Conditional Return

Instruction           Flags Checked

RC address           Cy=1

RNC dress            Cy=0

RZ address           Z=1

RNZ address        Z=0

RP address           S=0

RM address          S=1

RPE address                  P=1

RPO address        P=0

 

Restart Instruction (RST:0,1,2,3,4,5,6,7)

The restart instruction is an unconditional call instruction. This instruction generally used in interrupts and software instructions in a program.

Instruction            Effect            Branching     Binary code       Opcode

RST 0         CALL 0000        0000            1100 0111            C7

RST 1          CALL 0008        0008            1100 1111            CF

RST 2          CALL 0010        0010            1101 0111            D7

RST 3          CALL 0018        0018            1101 1111            DF

RST 4          CALL 0020        0020            1110 0111            E7

RST 5          CALL 0028        0028            1110 1111            EF

RST 6          CALL 0030        0030            1111 0111            F7

RST 7          CALL 0038        0038            1111 1111            FF

 

         The 8085 has 8 restart instructions RST 0,RST 1, RST 2, RST 3,RST 4,
RST 5,  RST 6, RST 7
         These instructions represent efficient ways to call frequently used subroutine.
         A restart (RST) has the same effect as CALL.
         On the execution of RST 0. the program branches to 0000 and the instructions are executed from there till it reaches the RET statement.
         A RST is special kind of CALL because it branches to a predetermined address.
         The RST Instruction is 1-byte long whereas the CALL Instruction 3-byte long.
         Therefore a RST instruction is an efficient way to call frequently used subroutines
         RST 0 to RST 7, are called software Interrupts because they are instructions.
         The 8085 has hardware interrupts namely TRAP, RST 7.5, RST 6.5,
RST 5.5,INT.

Hexadecimal Counter:

         ·A counter which counts continuously in hexadecimal form with appropriate time delay between each count is called "Hexa decimal counter"

         Let us design a Hexadecimal counter, which can count continuously in hexadecimal from FF to 00 in a system with a 0.5 μs clock period.

         We will use 'C' register to set up a l millisecond (ms) delay between each count and display numbers at one of the output port.

Problem Analysis

To design a Hexadecimal counter we have to do two things:

1. To set up a continuous down counter.

2. To design a given delay between two counts.

Setup Counter

         The Hexadecimal counter is set up by loading a register with an appropriate starting no. and decrementing it until it becomes zero.

         After zero count, register goes back to FF because decrementing zero results in a (-1) which is FF in 2's complement.

(0)16                                 = 0000 0000

                     2's complement                 =1111 1111

                                                                 1111 1111

     (F)    (F)

      FLOW DIAGRAM                       

            

 

Program: 

                   Mnemonics          Comments

 

                   MVI B, 00              B is a counter

NEXT:      DCR B                     Decrement B

        MVI C, 8CH           Cß Delay count

DELAY:   DCR C                     Decrement Delay count

                  JNZ DELAY           Jump to Delay

                  MOV A, B                if #0

                 OUT PORT#            move B to A and display the value through Port X

                 JMP NEXT               Go To Next

Modulo Ten Counter

         The Modulus of a counter refers to how many counts it will go through before it repeats.

         The modulus of a counter is the number of output states it has.

         If counters go through ten different states (0 to 9) then it is called as MOD 10 counter.

         Let us Design a MOD - 10 counter which can count from 0 to 9 with a second delay between each count.

         At the count of 9,the counter should reset itself to 0 and repeat the sequence continuously.

         Use HL register pair to set up the delay, and display each count at one of the output ports.

         Assume clock frequency of micro computer is 1 MHz.

FLOW CHART:

                  

 

Program:

                                  Mnemonics

START:            MVI B, 00 H

                         MOV A, B

DSPLAY:       OUT PORT #

                      LXI H, 16-bit

                      LOOP: DCX H

                       MOV A, L

                       ORA H

                       JNZ LOOP

                       INR B

                       MOV A, B

                      CPI 0A H

                      JNZ DSPLAY

                      JZ START

Program description:
         The counter is setup by loading the register with the appropriate numbers and incrementing it until reaches the digit 9.
         When counter reaches the find count, it is reset to zero.
         The 1-second delay between the each count is set up by using a register pair.
         In the program, the instructions ORA is used to set the zero fag.
         This ORA instructions is used to check whether HC has reached Zero.
         The CPI OA checks and compares the content of B register in every cycle.
         When register B reaches the number OA, the program sequence is redirected to reset the counter without displaying the contents.

 

Pulse timings for flashing lights

Let us write a program to generate a continuous square wave with the period of 500 μs. Assume the system clock period is 325 ns and use bit D0 to output the square wave.

         For the above program, period of square wave is 500 μs, therefore the pulse should be on (logic 1) for 250 μs and off( logic 0) for 250 μs

         Alternate pattern of 0/1 bits can be provided by loading the accumulator with AA(1010 1010) and rotating the pattern once through each delay loop

         Bit D0 of the output port is used to provide logic 0 & 1

         All other bits can be marked by AND the Acc with the byte 01.

 

Program Description:

         Register D is loaded with AA (bit pattern)

         D is moved to Acc  and rotated left and again stored in D (i.e)

1010 1010 à 0101 0101(RLC)

         ANI ANDs Accumulator with 01 to mask all bits expect D0.

              Acc  = 0101 0101

01     = 0000 0001

(AND) = 0000 0001 à Accumulator

         D0=1 provides high pulse during the first 250 μs because of the delay.

         In the next cycle of the loop, D0=0 because of RLC and the output pulse stays low for the next 250 μs.

PROGRAM:


 

1 comment: