0% found this document useful (0 votes)
16 views

Unit 6 MM

Uploaded by

sahilpatilarts77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Unit 6 MM

Uploaded by

sahilpatilarts77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

UNIT 6

Programming of 8051
Addressing modes-

1. In 8051 there are 1-byte, 2-byte instructions and very few 3-byte
instructions are present.
2. The opcodes are 8-bit long.
3. As the opcodes are 8-bit data, there are 256 possibilities.
4. Among 256, 255 opcodes are implemented.
5. In 8051 There are six types of addressing modes.

 Immediate AddressingMode
 Register AddressingMode
 Direct AddressingMode
 Register IndirectAddressing Mode
 Indexed AddressingMode
 Implied AddressingMode

Immediate addressing mode


1. In this Immediate Addressing Mode, the data is provided in the instruction itself.
2. The data is provided immediately after the opcode.
3. These are some examples of Immediate Addressing Mode.

MOVA, #0AFH;
MOVR3, #45H;
MOVDPTR, #FE00H;

4. In these instructions, the # symbol is used for immediate data.

5. In the first instruction, the immediate data is AFH, but one 0 is added at the beginning.

6. So when the data is starting with A to F, the data should be preceded by 0.

Register addressing mode

1. In the register addressing mode the source or destination data should be


present in a register (R0 to R7).

These are some examples of Register Addressing Mode.


MOVA, R5;
MOVR2, #45H;
MOVR0, A;

2. In 8051, there is no instruction like MOVR5, R7.


3. But we can get the same result by using this instruction MOV R5, 07H, or by
using MOV 05H, R7.
4. But this two instruction will work when the selected register bank is RB0.

Direct Addressing Mode

1. In the Direct Addressing Mode, the source or destination address is specified by using
8-bit data in the instruction.
2. Only the internal data memory can be used in this mode.
3. Here some of the examples of direct Addressing Mode.

MOV80H, R6;
MOVR2, 45H;
MOVR0, 05H;

4. The first instruction will send the content of register R6 to port P0 (Address of Port 0
is 80H).
5. The second one is forgetting content from 45H to R2.
6. The third one is used to get data from Register R5 (When register bank RB0 is
selected) to register R5.

Register indirect addressing Mode

1. In this mode, the source or destination address is given in the register.


2. By using register indirect addressing mode, the internal or external addresses can be
accessed.
3. The R0 and R1 are used for 8-bit addresses, and DPTR is used for 16-bit addresses,
no other registers can be used for addressing purposes.
4. Let us see some examples of this mode.

MOV0E5H, @R0;
MOV@R1, 80H

5. In the instructions, the @ symbol is used for register indirect addressing.


6. In the first instruction, it is showing that theR0 register is used.
Indexed addressing mode

1. In the indexed addressing mode, the source memory can only be accessed from
program memory only.
2. The destination operand is always the register A.
3. These are some examples of Indexed addressing mode.

MOVCA, @A+PC;
MOVCA, @A+DPTR;

The C in MOVC instruction refers to code byte. For the first instruction, let us consider A
holds 30H. And the PC value is1125H. The contents of program memory location (30H +
1125H) are moved to register A.

Implied Addressing Mode

1. In the implied addressing mode, there will be a single operand.


2. These types of instruction can work on specific registers only.
3. These types of instructions are also known as register specific instruction.
4. Here are some examples of Implied Addressing Mode.

RLA;
SWAPA;

5. These are 1- byte instruction.


6. The first one is used to rotate the A register content to the Left.
7. The second one is used to swap the nibbles in A.

LCD AND KEYBOARD INTERFACING with 8051


LCD (LIQUID CRYSTAL DISPLAY) interface with 8051-

1. The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines.
2. The number on data lines depends on the mode of operation.
3. If operated in 8-bit mode then 8 data lines + 3 control lines i.e. total 11 lines are required.
4. And if operated in 4-bit mode then 4 data lines + 3 control lines i.e. 7 lines are required.
Pin Symbol Function
1 GND Ground
2 Vss Supply Voltage
3 Vo Contrast Setting
4 RS Register Select
5 R/W Read/Write Select
6 En Chip Enable Signal
7-14 DB0-DB7 Data Lines
15 A/Vee Gnd for the backlight
16 K Vcc for backlight
5. When RS is low (0), the data is to be treated as a command.
6. When RS is high (1), the data being sent is considered as text data which should be displayed on the s
7. When R/W is low (0), the information on the data bus is being written to the LCD.
8. When RW is high (1), the program is effectively reading from the LCD.
9. Most of the times there is no need to read from the LCD so this line can directly be connected to
saving one controller line.
10. The ENABLE pin is used to latch the data present on the data pins.
11. A HIGH - LOW signal is required to latch the data.
12. The LCD interprets and executes our command at the instant the EN line is brought low.
13. If you never bring EN low, your instruction will never be executed.

KEYBOARD -
1. Figure 5.4.31 shows a 4 x4 matrix connected to two ports.
2. The rows are connected to an output port(Port 1) and the columns are connected to an input
port. (Port 2) .
3. If no key has been pressed, reading the input port will yield 1s for all columns since they are
all connected to high (Vcc).
4. If all the rows are grounded and a key is pressed, one of the columns will have 0 since the key
pressed provides the path to ground.
5. It is the function of the microcontroller to scan the keyboard continuously to detect and
identify the key pressed.
6. Figure 5.4.3 Matrix Keyboard Connections to Ports

7. To find out the key pressed , the controller grounds a row by sending a ‘0’ on the
corresponding line of the output port.
8. It then reads the data at the columns using the input port.
9. If data from columns is D3-D0=1111, then no key is pressed.
10. If any bit of the column is ‘0’, it indicates that a key is pressed in that column.
11. In this example, the column is identified by the following values: 1110 – key pressed
in column 0 1101 – key pressed in column 1 1011 – key pressed in column 2 0111 –
key pressed in column 3 .

INSTRUCTION SET-
1. 8051 Microcontroller have set of instruction to perform different operations.
2. There are five group of instruction which are listed below.
 Arithmetic Instructions
 Logic Instructions
 Data Transfer Instructions
 Branch Instructions
 Bit-oriented Instructions

1.ARITHMETIC INSTRUCTION:
Arithmetic instructions perform several basic operations such as addition,
subtraction, division, multiplication etc. After execution, the result is stored in the first
operand.
1) ADD A,Rn; Adds the register Rn to the accumulator Description:
Instruction adds the register Rn (R0-R7) to the accumulator.
After addition: the result is stored in the accumulator
Before execution: A=2Eh R4=12h After execution: A=40h R4=12h
2) INC A - Increments the accumulator by1 Description:
This instruction increments the value in the accumulator by 1.
If the accumulator includes the number 255, the result of the operation
will be 0.
Before execution: A=E4h
After execution: A=E5h 6.
3) DEC A - Decrements the accumulator by1 Description:
Instruction decrements the value in the accumulator by 1.
If there is a 0 in the accumulator, the result of the operation is FFh.
(255 dec.) Syntax: DEC A; Byte: 1 (instruction code); STATUS
register flags: No flags are affected;
Before execution: A=E4h
After execution: A=E3h

2.LOGICAL INSTRUCTION OF 8051 MICRO-CONTROLLER-


Logic instructions perform logic operations upon corresponding bits of two registers. After
execution, the result is stored in the first operand,
1) ANL A,Rn –AND register to the accumulator
A: accumulator Rn: any R register(R0- R7) Instruction performs logic AND operation
between the accumulator and Rn register.
The result is stored in the accumulator.
Syntax: ANL A,Rn
Before execution: A= C3h (11000011 Bin.) R5= 55h (01010101 Bin.)
After execution: A= 41h (01000001 Bin.)
2) ORL A,Rn - OR register to the accumulator
Rn: any R register (R0-R7) Instruction performs logic OR operation between the
accumulator and Rn register.
The result is stored in the accumulator.
Syntax: ORLA,Rn
Before execution: A= C3h (11000011 Bin.) R5= 55h (01010101 Bin.)
After execution: A= D7h (11010111 Bin.)

3. DATA TRANSFER INSTRUCTION OF 8051- These instructions are used


to copy the content of source operand to Destination operand
1) MOV A,Rn - Moves the Rn register to the accumulator The instruction moves the
Rn register to the accumulator.
The Rn register is not affected.
Syntax MOV A,Rn
Before execution: R3=58h
After execution: R3=58h A=58h
MOV A,#data - Moves the immediate data to the accumulator Instruction moves the
immediate data to the accumulator.
Syntax: MOV A, #28
After execution: A=28h

4. BIT-ORIENTED INSTRUCTIONS- Similar to logic instructions, bit-


oriented instructions perform logic operations.
The difference is that these are performed upon single bits.
1) ANL C,bit - AND direct bit to the carry flag
C: Carry flag Bit: any bit of RAM, Instruction performs logic AND operation between
the direct bit and the carry flag.
Syntax: ANL C,bit
Before execution: ACC= 43h (01000011 Bin.)C=1
After execution: ACC= 43h(01000011 Bin.) C=0
2) CLR C - clears the carry flag
C: Carry flag, Instruction clears the carry flag.
After execution: C=0
3) CLR bit - clears the direct bit Bit: any bit of RAM, Instruction clears the specified
bit.
Syntax: CLR P0.3
Before execution: P0.3=1 (input pin)
After execution: P0.3=0 (output pin)

5. BRANCH INSTRUCTION OF 8051 CONTROLLER- There are two


kinds of branch instructions:
Unconditional jump instructions: upon their execution a jump to a new location
from where the program continues execution is executed.
Conditional jump instructions: a jump to a new program location is executed only
if a specified condition is met.
Otherwise, the program normally proceeds with the next instruction.

Introduction to 8051 Programming in Assembly Language


1. The assembly language is a low-level programming language used to
write program code in terms of mnemonics.
2. assembly programming language is popularly used in many
applications.It can be used for direct hardware manipulations
3. . It is also used to write the 8051 programming code efficiently with less
number of clock cycles by consuming less memory compared to the other
high-level languages.

4. The assembly language is a fully hardware related programming


language.
5. The embedded designers must have sufficient knowledge on hardware of
particular processor or controllers before writing the program.
6. The assembly language is developed by mnemonics; therefore, users
cannot understand it easily to modify the program.

7. Microcontrollers or processors can understand only binary language in


the form of ‘0s or 1s’; An assembler converts the assembly language to
binary language, and then stores it in the microcontroller memory to
perform the specific task.
Rules of Assembly Language

 The assembly code must be written in upper case letters


 The labels must be followed by a colon (label:)
 All symbols and labels must begin with a letter
 All comments are typed in lower case
 The last line of the program must be the END directive
The assembly language mnemonics are in the form of op-code, such as MOV,
ADD, JMP, and so on, which are used to perform the operations.

Op-code: The op-code is a single instruction that can be executed by the CPU.
Here the op-code is a MOV instruction.
Operands: The operands are a single piece of data that can be operated by the
op-code. Example, multiplication operation is performed by the operands that
are multiplied by the operand.

You might also like