8051 Expts
8051 Expts
MICROPROCESSORS AND
MICROCONTROLLERS LAB
(2019 Scheme)
INTRODUCTION
INTEL 8051 is an 8-bit microcontroller that provides many functions (CPU, RAM, ROM,
I/O, Interrupt logic, Timer etc.) in a single package. The block diagram in Fig.1 shows all the
features unique to microcontrollers:
These are in addition to the usual CPU components: Program Counter, ALU, Working registers
and clock circuits. The most widely used registers are A, B, R0, R1, R2, R3, R4, R5, R6, R7, DPTR,
and PC. All except DPTR and PC are 8-bit registers. The A register called the accumulator is used
for all arithmetic and logic operations. The B register is used along with the A register for
multiplication and division operations. When not being used for multiplication and division, the
B register is available as a general-purpose register. Registers R0, R1 etc. are 8-bits wide; hence
their use is limited to access any information in the internal RAM. In order to access external code
or data memory, Data Pointer (DPTR) is used. It is a 16-bit register that can also be accessed as
two 8-bit registers, the high byte DPH and the low byte DPL.
3) Memory Mapping
Program Memory
ROM : 0000-7FFF H
RAM : 8000 – FFFF H
9) BUS : All data, address and control signals available on FRC connector
12) Power Supply : Built-in power supply (+5, +/- 12 and GND)
PROCEDURE
On switching the unit, after a scrolling display, the menu appears as A, B, D, G, M, R, S and T.
The menu commands are: Assemble, B- Block Move, D- Disassemble, F- Fill Data, G-Go and
Execute, M- Modify/ View Memory, R- Register View/ Edit, S- Single Step and T- View / Edit
Breakpoint.
To program the 8051 microcontroller, select line assembler by pressing the key ‘A’. The
display will appear as:
ASSEMBLER
ENTER START ADDR…
After entering the starting address (i.e., 8000), press ‘ENTER’ key on the keyboard. The system
will show a text address screen. Enter a valid assembly instruction and press ENTER. The Hex
code corresponding to the assembly instruction will be displayed as below:
8000: 01 80 00
Then press ENTER to continue assembling till the end of the program. Press ‘ESC’ to exit from
this menu and the starting menu appears. The entered program will be stored.
To view the disassembled code of the program, go to the main menu and press ‘D’. The screen
will show:
DISASSEMBLE
ENTER STARTING ADDRESS…
Now give the starting address of the code, which is to be disassembled. Press ENTER to continue
disassembling and ‘ESC’ for exiting from the menu.
To examine or simply modify the contents in a memory location, press the ‘M’ key and enter
the address, say 8000. The display will show:
MODIFY MEMORY
8000: 00
Enter the new hex value. Press ‘ENTER’ to increment/ accept the data and ‘BACKSPACE’ to
decrement/ accept the data. Press ‘ESC’ to exit from this mode.
EXECUTE
ENTER STARTING ADDR…
Now give the starting address of the program and press ‘ENTER’ again.
To exit the program from execution, press ‘RESET’ button on the kit.
CONCLUSION
The 8051 microcontroller architecture as well as the system specifications and menu commands
of STS 8051 are detailed.
EXPERIMENT-10
AIM
To write and execute the following assembly language programs using 8051
microcontroller kit.
Theory:
Five data bytes are stored in memory locations from 8100H to 8104H. This block of data is to be
transferred to memory locations from 8200H to 8204H. Register R1 is used as the counter. As the
data is available in external RAM locations, DPTR register is used to access the data one by one
and the transfer of each data from the source to the destination is via the accumulator.
Algorithm:
1. Set byte counter.
2. Get the number from the source and copy it in destination.
3. Decrement counter and repeat the above steps until the byte counter is zero.
Note: *- Replace DPH with its Internal RAM address (i.e., 83) while entering the mnemonics
on the kit.
Theory:
Ten data bytes are available in external RAM locations starting at 9000H. For an array of length
‘N’, the count is ‘N-1’, which is stored in register R2. Initially, the first and second numbers are
compared to find the larger among the two. The larger number is temporarily stored in the location
30H which is then compared with the third number of the array. The process continues until the
count in R2 becomes zero. The result (largest number) is stored in the location 9100H.
Algorithm:
1. Initialize address pointer and counter. Get the first number in the accumulator and move it
to an internal RAM location 30H.
2. Get the second number in the accumulator and compare it with the first number.
3. If accumulator content is smaller, skip. Otherwise, update the memory location with the
larger number.
4. Decrement the counter and get the next number. If counter is zero, store the result.
Otherwise, get the next data and repeat from Step 2.
Program 2: Finding the largest number
Memory Label Mnemonics Comments
Address
8000 MOV DPTR,#9000 Set the starting address of the array
8008 NEXT: INC DPTR Increment DPTR to get the next number
Note: To find the smallest number in an array, replace the instruction JC AHEAD corresponding
to the address 800F with JNC AHEAD.
Theory:
Five data bytes are available in external RAM locations starting at 8200H. This program uses the
bubble sort technique. In this type of sorting, first and second bytes are compared and the larger
is kept in the second address. Then second and third bytes are compared and the larger is kept in
the third address and so on. After one cycle (i.e., N-1 comparisons, where N is the number of data
bytes), the largest number will be in the last address. In the second cycle of bubble sort (i.e., N-2
comparisons), the second largest number will be stored in the last but one address.
If the instruction JNC is replaced by JC, the numbers will be sorted in descending order.
Algorithm:
3. If accumulator content is greater than the next data, go to step 5. Else, go to the next step.
4. Exchange data.
5. Decrement comparison counter. If comparison counter is zero, then go to the next step.
Otherwise, get the next element and go to step 3.
6. Decrement cycle counter. If cycle counter is zero, then stop. Otherwise, go to step 2.
8004 MOV DPTR, #8200 Load DPTR with the content of memory
location 8200H i.e., the first number
8007 BACK: MOVX A,@DPTR Move the number to the accumulator
PROCEDURE:
Enter the mnemonics of each program using the keyboard from memory locations 8000H
onwards. Replace the labels in the mnemonics with the corresponding memory locations while
entering in the kit. Execute each program and verify the results at the locations specified in each
program.
RESULT:
Assembly language programs for block data transfer, finding the largest (smallest) number
in an array and sorting the elements of an array in ascending (descending) order are developed
and executed using the 8051 microcontroller kit.
EXPERIMENT-11
AIM
To write and execute the following assembly language programs using 8051
microcontroller kit:
(i) Addition of two 8-bit numbers
(ii) Subtraction of two 8-bit numbers
(iii) Multiplication of two 8-bit numbers
(iv) Division of two 8-bit numbers
(v) Sum of a series of 8-bit numbers
Theory:
The numbers are stored in locations 8100 and 8101 respectively. The result is stored in 8102 and
borrow in 8103.
Algorithm:
1. Initialize address pointer and move the first number to the accumulator.
2. Store the first number in a register temporarily.
3. Increment address pointer to get the second number in the accumulator.
4. Clear Carry flag.
5. Subtract first number from the second number.
6. Store the result and borrow in specified memory locations.
Theory:
The numbers are stored in locations 8100 and 8101 respectively. The instruction MUL AB is
used to multiply two data bytes. After multiplication, the lower byte of the product is available
in register A and the higher byte in register B. The lower and higher bytes are then stored in
external RAM locations 8102 and 8103 respectively.
Algorithm:
1. Initialize address pointer and move the first number to the accumulator.
2. Store the first number in register B.
3. Increment address pointer to get the second number in the accumulator.
4. Multiply both the numbers.
5. Store LSB of the result from the accumulator in a specified memory location.
6. MSB of the result is moved from register B to register A so as to store it in the next memory
location.
Program 3: Multiplication of two 8-bit numbers
Memory Label Mnemonics Comments
Address
8000 MOV DPTR, #8100 Set the source address
Note: The internal RAM address of B register is F0 H. Replace B with F0 in the instructions
corresponding to 8004 and 800B of the above program.
Theory:
The numbers are stored in locations 8100 and 8101 respectively. The instruction DIV AB is
used to divide A by B. The quotient obtained after division is available in register A and the
remainder in register B. The quotient is stored in 8102 and the remainder in 8103.
Algorithm:
1. Initialize address pointer and move the first number to the accumulator.
2. Store the first number in register B.
3. Increment address pointer to get the second number in the accumulator.
4. Divide first number by the second number.
5. Store quotient obtained by division from the accumulator in a specified memory location.
6. The remainder obtained after division is moved from register B to register A so as to store
it in the next memory location.
Algorithm:
1. Initialize address pointers and byte counter. Clear a register to store carry.
2. Add a byte in the memory with the accumulator.
3. Increment address pointer and decrement the counter. Repeat the previous step until all the
bytes are added.
4. Store the result and carry in specified memory locations.
PROCEDURE
Enter the assembly language instructions corresponding to each program from memory locations
starting at 8000H. Enter the data at the memory locations 8100H and 8101H. Execute each
program and verify the results at 8102H and 8103H.
Enter the assembly language instructions from 8000H onwards. Specify the count (i.e. N-1) where
N is the number of data bytes in the array at 8100H. Enter the data from external RAM locations
starting at 8101H. Execute the program and verify the result at locations 8200H and 8201H.
RESULT
The assembly language programs for addition, subtraction, multiplication, and division of
data bytes were developed and executed using the 8051 microcontroller kit.
EXPERIMENT-10
AIM
To write and execute an ALP using 8051 to find the factorial of a number.
Theory:
The factorial of a number is the product of all the integers from that number to 1. For example, the
factorial of 5 is equal to 5*4*3*2*1 =120. Here, the given number is temporarily stored in a register
R5 and register A is initialized with the data 01H. The result obtained by performing multiplication
in steps is stored temporarily in registers A and B. B holds the higher byte of the result and A
holds the lower byte of the result. They are finally stored at desired external RAM locations. The
result is obtained in hexadecimal format.
Algorithm:
1. Get the number ‘n’ and store it as an intermediate result.
2. Multiply the intermediate result with ‘n-1’.
3. Repeat the above steps till ‘n-1’ becomes 1.
PROGRAM
Memory Label Mnemonics Comments
Address
8000 MOV DPTR, #8100 Set address of the number
PROCEDURE
Enter the assembly language instructions from 8000H onwards. Enter the number whose factorial
has to be determined at 8100H. Execute the program and verify the results at locations 8101H and
8102H.
RESULT
The assembly language program to find the factorial of a number was developed and executed
using the 8051 microcontroller kit.