TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
Asst. Prof. Selvin Furtado [101]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
Asst. Prof. Selvin Furtado [102]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
Asst. Prof. Selvin Furtado [103]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
Asst. Prof. Selvin Furtado [104]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
Asst. Prof. Selvin Furtado [105]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
2.11Addressing Modes
Data is stored at a source address and moved (actually, the data is copied) to a destination address.
The way by which these addresses are specified are called the addressing modes. The 8051 mnemonics
are written with the destination address named first, followed by the source address.
The following four addressing modes are used to access data (ref: Figure 17):
1. Immediate addressing mode
2. Register addressing mode
3. Direct addressing mode
4. Indirect addressing mode
The following five types of opcodes are used to move data:
1. MOV
2. MOVX
3. MOVC
4. PUSH and POP
5. XCH
2.11.1 Immediate Addressing Mode
2.11.2 Register Addressing Mode
Asst. Prof. Selvin Furtado [106]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
Figure 17- Addressing Modes [107]
Top↑
Asst. Prof. Selvin Furtado
Dept. Electronic & Telecommunication Engg.
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
NOTE:
Asst. Prof. Selvin Furtado [108]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
2.11.3 Direct Addressing Mode
Asst. Prof. Selvin Furtado [109]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
Asst. Prof. Selvin Furtado [110]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
2.11.4 Indirect Addressing Mode
For all the addressing modes covered to this point, the source or destination of the data is an
absolute number or a name. Inspection of the opcode reveals exactly what are the addresses of the
destination and source. For example, the opcode MOV A, R7 says that the A register will get a copy
of whatever data is in register R7; MOV 33h, #32h moves the hex number 32 to hex RAM address 33.
The indirect addressing mode uses a register to hold the actual address that will finally be used in
the data move; the register itself is not the address, but rather the number in the register. Indirect
addressing for MOV opcodes uses register R0 or R1, often called "data pointers." to hold the address
of one of the data locations, which could be a RAM or an SFR address. The number that is in the
pointing register (Rp) cannot be known unless the history of the register is known. The mnemonic
symbol used for indirect addressing is the “at” sign, which is printed as @.
The moves made possible using immediate, direct, register and indirect addressing modes are as
follows:
Mnemonic Operation
MOV @Rp, #n Copy the immediate byte n lo the address in Rp
MOV @Rp, add Copy the contents of add lo the address in Rp
MOV @Rp,A Copy the data in A lo the address in Rp
MOV add, @Rp Copy the contents of the address in Rp to add
MOV A, @Rp Copy the contents of the address in Rp to A
Asst. Prof. Selvin Furtado [111]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
The following table shows examples of MOV opcodes, using immediate, register, direct and indirect
modes
Mnemonic Operation
MOV A, @R0 Copy the contents of the address in R0 to the A register
MOV @R1, #35h Copy the number 35h to the address in R1
MOV add, @R0 Copy the contents of the address in R0 to add
MOV @R1, A Copy the contents of A to the address in R1
MOV @R0, 80h Copy the contents of the port 0 pins to the address in R0
2.12Development Tools
8051 Assemblers
Keil (www.keil.com), Franklin Software (www.fsinc.com), Dunfield Development System
(www.dunfield.com) are a few companies which provide 8051 assemblers. Some of these provide
shareware versions of their products, which can be downloaded from their websites. However, the
size of code for these shareware versions is limited to 1K (or 2K).
8051 Trainers
www.MicroDigilalEd.com, RSR Electronics (www.elexp.com), Axiom Manufacturing
(www.axman.com), Rigel Corp. (http://rigelcorp.com) are a few companies that produce and market
8051 Trainers.
2.13Assembler Directives
DB (define byte)
The DB directive is the most widely used data directive in the assembler. It is used to define the 8-bit
data. When DB is used to define data, the numbers can be in decimal, binary, hex, or ASCII formats.
For decimal, the "D" after the decimal number is optional, but using “B “(binary) and “H" (hexadecimal)
for the others is required. Regardless of which is used, the assembler will convert the numbers into
hex. To indicate ASCII, simply place the characters in quotation marks (‘like this’). The assembler will
assign the ASCII code for the numbers or characters automatically. The DB directive is the only
directive that can be used to define ASCII strings larger than two characters; therefore, it should be
used for all ASCII data definitions. Following are some DB examples:
Asst. Prof. Selvin Furtado [112]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
Asst. Prof. Selvin Furtado [113]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
2.14Rules for labels in Assembly language
Asst. Prof. Selvin Furtado [114]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
2.15Programs for PORT
1. WAP for 8051 to read data from Port 1 at regular intervals and store the data in R7, R6, R5.
Asst. Prof. Selvin Furtado [115]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
2.15.1.1 Single Bit Instructions [116]
Top↑
Asst. Prof. Selvin Furtado
Dept. Electronic & Telecommunication Engg.
TE-IT: MEP Module 2 - The Microcontroller Architecture and Programming of 8051
Asst. Prof. Selvin Furtado [117]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
3 Module 3 - Interfacing with 8051 Microcontroller
3.1 Interfacing with ADC
Bubbles indicate
Active Low Signal
Asst. Prof. Selvin Furtado [118]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [119]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [120]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [121]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [122]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Circuit Connections:
Program:
Asst. Prof. Selvin Furtado [123]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Figure 18- ADC 0808/0809 [124]
Top↑
Asst. Prof. Selvin Furtado
Dept. Electronic & Telecommunication Engg.
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [125]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
3.2 Interfacing with DAC
Asst. Prof. Selvin Furtado [126]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Example:
Circuit Connections:
Figure 19- Interface of DAC 0808 with 8051
Asst. Prof. Selvin Furtado [127]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [128]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
3.3 Programs of 8051:
1. WAP for 8051 to generate a stair-step ramp using DAC0808,
give circuit connections for the same.
Solution:
Ref. fig 1 for circuit connection.
Students are expected to write a delay program on their own,
assuming necessary data. (Refer class notes)
2. Generating Sine Wave
Asst. Prof. Selvin Furtado [129]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Example: [130]
Top↑
Note:
Asst. Prof. Selvin Furtado
Dept. Electronic & Telecommunication Engg.
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [131]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Program:
Students are expected to write a delay program on their own,
assuming necessary data. (Refer class notes)
3 Write an assembly language program to generate triangular wave using DAC interfacing with 8051
microcontrollers.
Asst. Prof. Selvin Furtado [132]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
ORG 0000H
MOV A, #00
UP: MOV P1,A ; send value to DAC
INC A
CJNE A, #255, UP
DOWN: MOV P1, A ; send value to DAC
DEC A
CJNE A, #00, DOWN
SJMP UP ; infinite loop
Asst. Prof. Selvin Furtado [133]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
3.4 Interfacing with Stepper Motor
Asst. Prof. Selvin Furtado [134]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Note: [135]
Top↑
Asst. Prof. Selvin Furtado
Dept. Electronic & Telecommunication Engg.
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Program:
Describe the 8051 connections to stepper motor of Figure and code a
program to rotate it continuously.
Solution:
Circuit Connections:
Asst. Prof. Selvin Furtado [136]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Program: [137]
Top↑
Asst. Prof. Selvin Furtado
Dept. Electronic & Telecommunication Engg.
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Note:
Example:
Asst. Prof. Selvin Furtado [138]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
3.5 Interfacing the keypad to 8051
Asst. Prof. Selvin Furtado [139]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [140]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [141]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [142]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [143]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [144]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [145]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [146]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
3.6 Interfacing LCD to 8051
Asst. Prof. Selvin Furtado [147]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [148]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [149]
Dept. Electronic & Telecommunication Engg. Top↑
TE-IT: MEP Module 3 - Interfacing with 8051 Microcontroller
Asst. Prof. Selvin Furtado [150]
Dept. Electronic & Telecommunication Engg. Top↑