Unit 6 MM
Unit 6 MM
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
MOVA, #0AFH;
MOVR3, #45H;
MOVDPTR, #FE00H;
5. In the first instruction, the immediate data is AFH, but one 0 is added at the beginning.
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.
MOV0E5H, @R0;
MOV@R1, 80H
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.
RLA;
SWAPA;
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
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.