Microcontroller Instruction Set
Microcontroller Instruction Set
•
Introduction
• An instruction is an order or command given to
a processor by a computer program. All
commands are known as instruction set and set
of instructions is known as program.
• OPCODE 8 bit
Types Of Instructions
2. Two/double byte instruction:
1. Register addressing.
2. Direct addressing.
3. Register indirect addressing.
4. Immediate addressing.
5. Index addressing.
Register Addressing Mode
• In register addressing mode; the source
and/or destination is a register.
DPTR, A
• PUSH Rx Push directly 2
addressed Rx register on stack
• ADD A, Rn A = A + Rn 1
• ADD A, Rx A = A + Rx 2
• AAD A, @ Ri A = A+ Ri 1
Arithmetic Instructions
• ADD A, # X A = A + Byte 2
• ADDC A, Rn A = A + Rn + C 1
• ADDC A , Rx A = A + Rx + C 2
Arithmetic Instructions
• ADDC A, @ Ri A = A + Ri + C 1
• ADDC A, # X A = A + Byte + C 2
• SUBB A, Rn A = A – Rn – 1 1
Arithmetic Instructions
• SUBB A, Rx A = A – Rx – 1 2
• SUBB A, @ Ri A = A – Ri – 1 1
• SUBB A, # X A = A – Byte – 1 2
Arithmetic Instructions
• INC A A=A+1 1
• INC Rn Rn = Rn + 1 1
• INC Rx Rx = Rx + 1 2
Arithmetic Instructions
• INC @ Ri Ri = Ri + 1 1
• DEC A A=A–1 1
• DEC Rn Rn = Rn – 1 1
Arithmetic Instructions
• DEC Rx Rx = Rx – 1 2
• DEC @ Ri Ri = Ri – 1 1
• DIV AB A = [A/B] 1
• DA A Decimal adjustment of 1
accumulator according to BCD code
Logical Instructions
• These instructions perform logical operations
between two register contents on bit by bit
basis.
• RL A (An + 1) (An) 1
(A0) (A7)
• RLC (An + 1) (An) 1
(A0) (C)
(C) (A7)
Logical Instructions
• RR A (An) (An + 1) 1
(A7) (A0)
• CLR C (C=0) 1
• SETB C (C=1) 1
Logical Instructions On Bits
• CPL C (1 = 0, 0 = 1) 1
• NOP No operation 1
Summary
• Instruction set.
• Addressing modes.
• Data transfer instruction.
• Arithmetic instruction.
• Logical instruction.
• Logical operation on bits.
Circuit diagram to interface external program ROM
with 8051
• Step 1: Connect EA pin to ground
• Step 2: Connect the PSEN to the CE and OE.
• Step 3: Then, Port 2 (P2.0 – P2.7) to A8 – A12 pins of ext.
ROM.
• Step 4: Connect ALE to G of 74LS373 latch to enable it.
• Step 5: Next, connect the OC of 74LS373 to GND.
• Step 6: Connect Port 0 (P0.0 – P0.7), which consists of both
address and data multiplexed into Port 0 to 1D – 8D pins of
74LS373 latch to demultiplex it and 1Q – 8Q of the latch to
A0 – A7 of ext. ROM.
• Step 7: Connect Port 0 (P0.0 – P0.7) to D0 – D7 of the ext.
ROM.
• Step 8: VPP of ext. ROM to VCC.
Diagram
• 0000H
• MOV DPTR, #4000H ; Load DPTR with the location where data is stored
• MOV R0, #40H ; Load R0 with the int RAM loc where you want to save
• the data
• rep: MOV A, #00H ; Clear accumulator
• MOVC A, @A+DPTR ; Syntax to mode data from ext. ROM to accumulator
• MOV @R0, A ; Copy the value of accumulator in location pointed by R0
• INC R0 ; Inc R0 to point to next int RAM location
• INC DPTR ; Inc DPTR to point to next ext. ROM location
• CJNE A, #00H, rep ; Repeat this process until 0 is received from the DPTR
• stay:SJMP stay ; Stay here
• END
To interface External RAM with 8051
•
Step 1: Connect RD to OE of ext. RAM.
Step 2: Connect WR to WE of ext. RAM.
Step 3: Connect active low input of NAND gate to CE of
external RAM, where the input to NAND gate are address
lines A15, A14, and A13. We’ve given 0 1 0 to these lines to
access the 8000H location of the external RAM.
Code to interface external RAM with 8051
This is an assembly language program to send 150 bytes of data or status of Port 2
to external RAM located at 6000H.
First of all, to access 6000H of the data memory, we have to send 0 1 1 to A15 A14
A13 respectively.
ORG 0000H
RAMLOC EQU 6000H ; External RAM location = 6000H
COUNT EQU 150 ; Variable count = 150d
MOV DPTR, #RAMLOC ; Mov DPTR to point to ext. RAM location
MOV R3, #COUNT ; Number of bytes of data
rep: MOV A, P1 ; Copy status of P2 into acc
MOVX @DPTR, A ; Copy the content of acc to the ext. RAM
ACALL DELAY ; call a delay before repeating the process
INC DPTR ; Inc DPTR to point to next location
DJNZ R3, rep ; Repeat this until all the bytes of data are sent
stay: SJMP stay ; Stay here forever
END
Interfacing external program ROM, data
ROM and external RAM with the 8051
• Next, let’s interface both program ROM and data RAM to 8051, Let’s say
we want to interface 16KB data RAM, 16KB program ROM, and 16KB of
data RAM, then we’ll have to follow the following steps:
• Step 1: Calculate the number of address lines required to access 16KB of
data, that is 214 = 16KB. Here, we require 14 address lines A0 – A13.
• Step 2: Decide the location of RAM and ROM, here we are going to
interface program ROM from 0000H and data RAM from 8000H.
• Step 3: Select the decoder circuit, here we’re going to select 74LS138
decoder.
• Step 4: We do not need a decoder circuit for program ROM, but we have
to connect the 74LS138 decoder to data ROM and data RAM.
• Step 5: Connect G1 to VCC, G2A, and G2B to ground.
• Step 6: Connect input A and B to P2.6 and P2.7 respectively,
and the input C to ground.
• Step 7: We connect external program and data ROM, for that
we can use an AND gate with its input being signal
from RD (to access external data space) and PSEN (to access
external program space) and output to OE of external ROM.
• Step 8: To interface the external RAM, we connect
both RD and WR to WE and OE respectively of external
RAM.