You are on page 1of 11

LAB 1: Intel 8051 CPU PROGRAMMING

DATA TRANSFER INSTRUCTIONS


OBJECTIVES
At the end of the laboratory works, you should be able to write simple assembly language
programs for the Intel 8051 CPU using data transfer instructions and execute the programs on
the Intel 8051 trainer board.
INTRODUCTION
The Intel 8051 Central Processing Unit has 8-bit data bus and a 16-bit address bus which is
capable of accessing a linear address space of 64K Byte. The Intel 8051
microcontroller/microprocessor consists of two types of internal memory; 4K ROM and 128
RAM. The Intel 8051 Trainer Board consists of 256K External ROM and 256K External RAM.
The start address for ROM is 0000H and starting address for RAM is 2000H. User programs
are written into the External ROM. This memory starts at address 0000H up to 1FFFH.
Therefore, user programs should be started at address 0000H.
In order to write assembly language programs for the Intel 8051 CPU, it is important to
understand the programming model of the CPU, or also known as the register set.

0
A
B
R0

R1

0
PSW

R2

SP

R3
R4

15

R5

8 7
DPL

DPH

R6

0
DPTR

PC

R7

Figure 1 68000 Programming model


The Intel 8051 CPU have Accumulator A and B, 8 data registers, R0 to R7, Program Status Word
(PSW), status register (SR), Program Counter and Data Pointer as shown in Figure 1. All registers
are 8 bit except for the Program Counter and Data Pointer are 16 bit in length. The data registers
are used to store information (data) within the Intel 8051 CPU itself. Accumulator A is used for

all Arithmetic and logic instructions.

ECE521/SEPT2013/8051/Pg 1

There are three types of data transfer instructions provided by Intel 8051 microprocessor:
a) MOV, MOVC, MOVX
c) XCH and XCHD
b) PUSH and POP
Data transfer instructions involve instructions such as MOV, MOVC, MOVX to copy or move
data between the various locations.
EQUIPMENTS
1. A Personal computer installed with the MCU 8051 IDE Editor/Assembler/Simulator
2. Intel 8051 Trainer Board.
PROCEDURE
All the programs in the exercises have to be written and assembled using the MCU8051IDE
Assemble/simulator. To observe the results, the programs have to be compiled and executed in
the Simulator. The contents of the affected registers and memory locations have to be
examined through single stepping or breakpoints setting.
EXERCISES
1. Write a program that will store 30H into Accumulator A, 48H into R0 and D8H into R1.
Execute the program and explain the differences in the results.
2. Write a program that will store 2004H in DPTR. Execute the program and comment on the
results.
3. Write and execute a program that will store data 21H into external memory location
2050H. Explain the results.
4. Write a program that will send logic 11010011B to R5. Execute the program and comment
on the results.
5. Write a program that will exchange data between R0 and ACC A. Execute the program and
comment on the results.

ECE521/SEPT2013/8051/Pg 2

LAB 2: Intel 8051 CPU PROGRAMMING


DATA MANIPULATION INSTRUCTIONS
OBJECTIVES
At the end of the laboratory works, you should be able to write simple assembly language
programs for the Intel 8051 CPU using data manipulation instructions.
INTRODUCTION
The capability of a CPU depends on its data manipulation instructions which include the
arithmetic, logical, rotate, and bit manipulation. Some of the arithmetic instructions are ADD,
ADDC, SUBB, INC, DEC, MUL, DIV. The logical instructions are ANL, ORL, XRL.
Some of the rotate instructions are RL, RLC, RR, RRC, and SWAP. Bit manipulation deals
with bit operations, and the instructions are SETB, CLR bit, and MOV bit.
EQUIPMENTS
1. A Personal computer installed with the MCU 8051 IDE Editor/Assembler/Simulator
2. Intel 8051 Trainer Board
PROCEDURE
All the programs in the exercises have to be written and assembled using the MCU8051IDE
Assemble/simulator. To observe the results, the programs have to be compiled and executed in
the Simulator. The contents of the affected registers and memory locations have to be
examined through single stepping or breakpoints setting.
EXERCISES
1. Write and execute a program that adds data in R1 and R2. The result must be stored in
R5. Comment on your results.

2. Write and execute a program that adds the four 8-bit numbers 10H, 5FH, B9H and CFH
The result must be stored in external memory location 1500H. Comment on your results.
3. Write and execute a program that will subtract 15H from F0H. Store the result in memory
location 2000H and explain the results
4. Write and execute a program that multiply 22H by 04H using MUL. Explain on the result
obtained.
5. Write and execute a program that divides 02H by 50H using DIV. Explain on the result
obtained.

ECE521/SEPT2013/8051/Pg 3

6. Write and execute a program that logically AND the data in R4 with 55H. Put any data in
R4 and explain on the result obtained.
7. Modify Part 6 to perform a logical OR for the same data. Execute the program and explain
on the results obtained.
8. Load any data into R5. Rotate the data to the right twice. Execute the program and explain on
the results obtained

ECE521/SEPT2013/8051/Pg 4

LAB 3: Intel 8051 CPU PROGRAMMING


PROGRAM LOOPS AND SUBROUTINES
OBJECTIVES
At the end of the laboratory work, you should be able to write the Intel 8051 assembly
language program using looping technique and subroutines.
INTRODUCTION
The programs considered in the previous laboratory exercises so far are all the straight line,
sequential variety. In practice, programs almost invariably involve the repetition of sections of
the routine in order to achieve a solution or complete a control process. Such repetitions are
known as loops and it is in these that the real power of microprocessor lies. The flowchart of
generalized loop procedure is shown.
The loop normally requires setting up initial values for use by the process
and also by the loop, for continuing and terminating the loop. The number
of loops executed is stored in the loop counter.
The process is the compound instructions that will be executed
repeatedly when the loop repeats itself. Extra care must be exercised to
formulate these instructions.
The instruction used to test for terminating the loop is called conditional
instructions, and is of the form Jcc, where J stands for Jump and cc is the
condition. Some commonly used conditional instructions are JZ, JNZ, JC,
JNC, JB, JNB, CJNE and DJNZ.
Subroutine is a technique of writing programs so that it gives the
advantages of using less memory space for programs and the modular
program structure which leads to easier debugging.

EQUIPMENTS
1. A Personal computer installed with the MCU 8051 IDE Editor/Assembler/Simulator.
2. Intel 8051 Trainer Board
PROCEDURE
All the programs in the exercises have to be written and assembled using the MCU 8051 IDE
assembler/simulator. To observe the results, the programs have to be compiled and simulate.
The contents of the affected registers and memory locations have to be examined through
single stepping or breakpoints setting.

ECE521/SEPT2013/8051/Pg 5

EXERCISES
1. Write and execute a program that copy twelve bytes of data starting from memory locations
1000H to memory locations starting 100BH.
2. Write and execute a program that place the larger of the contents of memory locations
1200H and 1250H into memory location 1300H.
3. Three hexadecimal numbers are stored in memory locations 1010H, 1011H and 1012H.
Sort these numbers into ascending order with the smallest number in memory location
1013H.
4. Write a program, which inspect the contents of memory location 1008H and, if the contents
are greater than 0AH, subtract the value with 05H and store the result in memory location
200AH. Otherwise, add it with 10H and store the result in location 200BH.
5. Twelve 8-bit numbers are stored in memory locations starting with 1250H. Add the content
of these memory locations using indirect addressing mode and looping technique.
Execute the program and explain on the result obtained.
6. Write and execute a program that compute the area of two rectangular whose width and
length are stored in memory locations 2100H and 2101H, and save the area of these
rectangular in memory locations 2200H and 2300H. The calculation process of the area
must be done in a subroutine.

ECE521/SEPT2013/8051/Pg 6

LAB 4: Intel 8051 CPU PROGRAMMING


INPUT/OUTPUT PROGRAMMING
OBJECTIVES
At the end of the laboratory work, you should be able to write the Intel 8051 input/output
assembly language programs for the 82C55 Programmable Peripheral Interface (PPI) device.
INTRODUCTION
The Intel 8051 CPU uses the Programmable Peripheral Interface chip 82C55 to communicate with
the external devices. The PPI consist of 3 ports, PortA, PortB and PortC. Each Port can be
programmed as input or output individually. Before input/output operations can be carried out, the
PPI must first be initialized.

The Base address for PPI can be determined from memory decoder circuit. The address for
PortA, PortB and PortC are then set based on PPI Base address according to the following
table.
A1

A0

I/O ASSIGNMENT

PORT A

PORT B

PORT C

CONTROL REGISTER

Table 1: PPI Ports and conrol register address Setting

ECE521/SEPT2013/8051/Pg 7

BASE ADDRESS

PORTA

PORTB

PORTC

CR

$4000

$4000

$4001

$4002

$4003

$8000

$8000

$8001

$8002

$8003

Table 2: Example of Port and Control Register Addresses for different Base address.
Once the address for each port have been determined, the PPI must be
initiallize/programmed according to your input/output requirement. Each port can be set as
input or output by setting individual bit in Control Register as shown in firgue below. Only
Mode 0 is allowed for this Lab Session. Mode set Flag must be set to 1 to enable the PPI.

PORTA

PORTB

PORTC
Upper

PORTC
Lower

CR

Input

Input

Input

Input

9BH

Output

Output

Output

Output

80H

Output

Input

Output

Input

83H

Table 3 : Example of Control Register byte for various setting of Ports.


ECE521/SEPT2013/8051/Pg 8

EQUIPMENTS
1.
2.
3.
4.

A Personal computer installed with the MCU 8051 IDE Editor/Assembler/Simulator.


Intel 8051 Trainer Board
Intel 8051 Application Board
Leaper48 Universal IC writer.

EQUIPMENTS
The assembly language programs can be written, assembled and executed using MCU8051IDE
assembler/simulator. The Intel 8051 Trainer Board comes complete with 8051 Application Board
which enables all the programs to be tested with the appropriate Setting. Table 1 shows the actual
Setting of various devices on the Application Board and their connections to 82C55 Programmable
Peripheral Interface (PPI) device.

Table 1: The connections of the input and output devices on Intel 8051
Application Board to the 82C55 Programmable Peripheral Interface (PPI) device.

No
1

Device

Address

Port

7-Segment 1 82C55A0

6000H

PortA.0-PortA.3

7-Segment 2 82C55A0

6000H

PortA.4-PortA.7

82C55A0

6001H

Data 8 Bit Port B

82C55A0

6002H

Control RS PortC.5

82C55A0

6002H

Control E PortC.4

82C55A1

8001H

Control En PortB.0

82C55A1

8001H

Control In1 PortB.1

82C55A1

8001H

Control In2 PortB.1

82C55A2

A002H

Row - PortC

82C55A2

A000H

Col - PortA

LCD

DC Motor

Dot Matrix

PPI

Buzzer

82C55A1

8001H

PortB.7

LED

82C55A1

8002H

PortC

Switch

82C55A3

E001H

PortB

Ext Con2

82C55A1

8000H

PortA

Ext Con3

82C55A2

A001H

PortB

10

Ext Con4

82C55A3

E000H

PortA

Servo Motor 82C55A1

8001H

PortB.5

11
12

KeyPad

82C55A3

E002H

Row PortC.4-PortC.7

KeyPad

82C55A3

E002H

Col PortC.0-PortC.3

ECE521/SEPT2013/8051/Pg 9

PROCEDURE
All the programs in the exercises have to be written and assembled using the MCU8051IDE
simulator. To observe the results, the programs have to be downloaded and executed on the
Intel 8051 CPU Trainer Board. The application board has to be connected to the CPU Trainer
Board before executing the program. The contents of the affected registers and memory
locations have to be examined through single stepping and breakpoints setting if necessary.
EXERCISES
1. Write and execute a program that turns on LED one by one as Running Light.
2. Write and execute a program that reads the condition of 8 switches and send the logic signal
to the LED.
3. Write and execute a program that display number on both 7 segment counting up from 00 to
99.
4. Write and execute a program that can turn the DC motor Clock-wise for 5 second and then
stop. After 3 second rest, the motor repeat the same step again and the loop repeated all
over again
5. Write and execute a program that read the keypad button and display the number on 7Segment.

ECE521/SEPT2013/8051/Pg 10

You might also like