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

8051 Expts

The document describes experiments conducted using an 8051 microcontroller kit. It provides details on the 8051 architecture and the specifications of the STS 8051 kit. It also describes procedures to program and execute code on the kit. Two experiments are outlined: 1) Performing a block data transfer between memory locations using registers and 2) Finding the largest number in an array by iterative comparison of elements. Pseudocode and assembly code are provided for the algorithms.

Uploaded by

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

8051 Expts

The document describes experiments conducted using an 8051 microcontroller kit. It provides details on the 8051 architecture and the specifications of the STS 8051 kit. It also describes procedures to program and execute code on the kit. Two experiments are outlined: 1) Performing a block data transfer between memory locations using registers and 2) Finding the largest number in an array by iterative comparison of elements. Pseudocode and assembly code are provided for the algorithms.

Uploaded by

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

EEL331:

MICROPROCESSORS AND
MICROCONTROLLERS LAB
(2019 Scheme)

8051 Microcontroller Experiments


EXPERIMENT-9
STUDY OF 8051 MICROCONTROLLER TRAINER KIT

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:

• Internal ROM and RAM

• I/O ports with programmable pins

• Timers and Counters

• Serial data communication.

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.

SPECIFICATIONS OF STS 8051 KIT

1) CPU : 8-bit Microcontroller 8051

2) Memory : 32 KB program memory and 32 KB data memory

3) Memory Mapping

Program Memory

ROM : 0000-7FFF H
RAM : 8000 – FFFF H

Data Memory : 8000 – FFFF H (same location of RAM program memory)

4) Timer : 16-bit programmable timer/ counter using 8253 and internal

Timer T0 and T1 from CPU

5) I/O : 48 I/O lines using 8255 PPI chip

6) Interrupts : Two external interrupts INT0 and INT1

7) Keyboard : PS/2 compatible keyboard

8) Display : 16*2 LCD Display / 20*2 LCD Display

9) BUS : All data, address and control signals available on FRC connector

10) Interface : One serial UART interface provided by CPU

One serial port through 8251

11) Battery Back-up : Battery back-up for the RAM

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 fill RAM area with a specified data, press ‘F’.

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.

To execute the program, press ‘G’. The display will show:

EXECUTE
ENTER STARTING ADDR…

Now give the starting address of the program and press ‘ENTER’ again.

The display will show:


EXECUTING…

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

DATA TRANSFER AND SORTING USING 8051

AIM
To write and execute the following assembly language programs using 8051
microcontroller kit.

1. Block data transfer


2. Finding the largest (smallest) number in an array
3. Sorting the elements of an array in ascending (descending) order

1. Block transfer of data

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.

Program 1: Block transfer of data


Memory Label Mnemonics Comments
Address
8000 MOV R1,#05 Load counter as 05 in Register R1

Set source address


8002 MOV DPTR, #8100
8005 LOOP: MOVX A,@DPTR Content of the memory location pointed
by DPTR (i.e., content of 8100H) is
moved to the accumulator, A
8006 MOV DPH,#82H* Move immediate value 82H to DPH. i.e.,
DPTR =8200H
8008 MOVX @DPTR,A Content of A is moved to 8200H. The first
data byte is transferred
8009 MOV DPH,#81H* Load DPH with 81H. Now, DPTR=
8100H
800B INC DPTR Increment DPTR. Now, DPTR=8101H

800C DJNZ R1,LOOP Decrement R1. If not equal to zero, jump


to LOOP
800E HERE: SJMP HERE Terminate the program

Note: *- Replace DPH with its Internal RAM address (i.e., 83) while entering the mnemonics
on the kit.

2. Finding the largest number in an array

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

MOV R2,#09 Store the count (i.e., N-1) in register R2


8003
8005 MOVX A,@DPTR Move first number to the accumulator

8006 MOV 30, A Move the number to 30H

8008 NEXT: INC DPTR Increment DPTR to get the next number

8009 MOVX A,@DPTR Move the number to the accumulator

800A CJNE A,30,DOWN Compare the contents of A and 30H. Jump to


DOWN if not equal
800D SJMP AHEAD Jump to AHEAD if equal

800F DOWN: JC AHEAD Jump to AHEAD if there is a carry

8011 MOV 30, A Else, move the content of A to 30H (larger


number)
8013 AHEAD: DJNZ R2, NEXT Decrement R2 and Jump to NEXT if non-
zero
8015 MOV DPTR,#9100 Set the location of the result

8018 MOV A, 30 Move the largest number to the accumulator

801A MOVX @DPTR, A Store the result

801B HERE: SJMP HERE Terminate here

Note: To find the smallest number in an array, replace the instruction JC AHEAD corresponding
to the address 800F with JNC AHEAD.

3. Sorting elements of an array in ascending order.

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:

1. Initialize cycle counter, comparison counter and address pointer.

2. Get the first data in the accumulator.

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.

Program 3: Sorting in ascending order


Memory Label Mnemonics Comments
Address
8000 MOV R0, #04 Load the cycle counter as 04H (N-1)

8002 REPEAT: MOV R1, #04 Load the comparison counter

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

8008 MOV R2, A Move the number to register R2

8009 INC DPTR Increment DPTR to access the second


number
800A MOVX A,@DPTR Move the second number to register A

800B CLR C Clear carry

800C SUBB A, R2 Subtract with borrow (i.e., A- R2) with the


result in accumulator
800D JNC AHEAD Jump to AHEAD if there is no carry. Now,
the numbers are in the correct order.
Otherwise, they must be swapped.
800F MOVX A,@DPTR Move the second number to A

8010 DEC DPL Decrement DPL by one; DPTR=8200H

8012 MOVX @DPTR, A Move the number in A to 8200H

8013 MOV A,R2 Move the value in R2 to A i.e. first number

8014 INC DPTR Increment DPTR

8015 MOVX @DPTR, A Store the first number in 8201H

8016 AHEAD: DJNZ R1, BACK Decrement comparison counter

8018 DJNZ R0, REPEAT Decrement cycle counter

801A HERE: SJMP HERE Terminate

Note: Replace DPL with its address 82H.

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

ARITHMETIC OPERATIONS USING 8051

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

1. Addition of two 8-bit numbers


Theory:
The numbers are stored in locations 8100 and 8101 respectively. The result is stored in 8102 and
carry 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. Add both the numbers and store the result and carry in specified memory locations.

Program 1: Addition of two 8-bit numbers


Memory Label Mnemonics Comments
Address
8000 MOV DPTR,#8100 Set source address

MOVX A,@DPTR Get first byte


8003
8004 MOV R0, A Store first byte temporarily

8005 INC DPTR Increment pointer to get the next byte

8006 MOVX A,@DPTR Get the next byte

8007 ADD A, R0 Add first and second byte


8008 INC DPTR Increment pointer to store result

8009 MOVX @DPTR,A Store LSB of the result

800A MOV A,#00 Clear accumulator

800C ADDC A,#00 Add to get carry

800E INC DPTR Increment pointer to store MSB of the result

800F MOVX @DPTR,A Store MSB of the result

8010 HERE: SJMP HERE Terminate

2. Subtraction of two 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.

Program 2: Subtraction of two 8-bit numbers


Memory Label Mnemonics Comments
Address
8000 MOV DPTR,#8100 Set the source address

MOVX A,@DPTR Get the first byte


8003
8004 MOV R0, A Store first byte temporarily
8005 INC DPTR Increment pointer to get the next byte

8006 MOVX A,@DPTR Get the next byte

8007 INC DPTR Increment pointer to store the result

8008 CLR C Clear carry before subtraction

8009 SUBB A,R0 Subtract

800A MOVX @DPTR,A Store LSB of the result

800B INC DPTR Increment pointer to store MSB of the result

800C MOV A,#00 Clear accumulator

800E ADDC A,#00 Add to get borrow

800F MOVX @DPTR,A Store borrow of the result

8010 HERE: SJMP HERE Terminate

3. Multiplication of two 8-bit numbers

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

MOVX A,@DPTR Get the first byte


8003
8004 MOV B, A Store first byte temporarily

8006 INC DPTR Increment pointer to get the next byte

8007 MOVX A,@DPTR Get the next byte

8008 MUL AB Multiply both the bytes

8009 INC DPTR Increment pointer to store LSB of the


result
800A MOVX @DPTR,A Store LSB of the result

800B MOV A,B Move MSB of the result from register


B to the accumulator
800D INC DPTR Increment pointer to store MSB of the
result
800E MOVX @DPTR,A Store MSB of the result

800F HERE: SJMP HERE Wait here

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.

4. Division of two 8-bit numbers

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.

Program 4: Division of two 8-bit numbers


Memory Label Mnemonics Comments
Address
8000 MOV DPTR, #8100 Set the source address

MOVX A,@DPTR Get the first byte


8003
8004 MOV B,A* Store first byte temporarily

8006 INC DPTR Increment pointer to get the next byte

8007 MOVX A,@DPTR Get the next byte

8008 DIV AB Divide first byte by the second byte

8009 INC DPTR Increment pointer to store the quotient

800A MOVX @DPTR,A Store the quotient

800B MOV A,B* Move the content of B (the


remainder) to the accumulator
800D INC DPTR Increment pointer to store the
remainder of the result
800E MOVX @DPTR,A Store the remainder of the result

800F HERE: SJMP HERE Wait here

Note: Replace B with F0.

5. Sum of an array of 8-bit numbers


Theory:
The 8-bit numbers are stored in locations 8101H onwards. The count (N-1) is stored in register R1.
Register R2 is initialized to store MSB of the sum temporarily. The LSB of the result is stored in
8200H and MSB in 8201H.

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.

Program 5: Sum of an array of 8-bit numbers


Memory Label Mnemonics Comments
Address
8000 MOV R2,#00 Initialize register R2 to store MSB of
the sum
MOV DPTR,#8100 Load DPTR with the count value in
8002 8100H
8005 MOVX A,@DPTR Move the count to the accumulator

8006 MOV R1,A Store the count in register R1

8007 INC DPTR Increment DPTR to access the first


number of the array
8008 MOVX A,@DPTR Move the first number to the
accumulator
8009 MOV R0,A Store the first number temporarily in
register R0
800A LOOP: INC DPTR Increment DPTR to access the second
number
800B MOVX A,@DPTR Move the second number to the
accumulator
800C ADD A, R0 Add first and second number

800D MOV R0,A Store the sum temporarily in register


R0
800E JNC AHEAD If there is no carry, jump to AHEAD

8010 INC R2 If there is a carry, increment R2


8011 AHEAD: DJNZ R1, LOOP Decrement count and jump to LOOP
if non-zero
8013 MOV DPTR, #8200 Set address to store the result

8016 MOVX @DPTR,A Move LSB of the sum to the address


pointed by DPTR (i.e., 8200H)
8017 INC DPTR Increment DPTR to store MSB of the
sum
8018 MOV A, R2 Move MSB of the sum to the
accumulator
8019 MOVX @DPTR, A Move MSB of the sum to the address
pointed by DPTR (i.e., 8201H)
801A HERE: SJMP HERE Terminate

PROCEDURE

Addition, subtraction, multiplication and division of two data bytes

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.

Sum of an array of 8-bit numbers

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

FACTORIAL OF A NUMBER USING 8051

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

MOVX A, @DPTR Move the number to the accumulator


8003

8004 Move the number in A to register R5


MOV R5, A
8005 MOV A, #01 Move 01H to the accumulator

8007 LOOP: MOV B, R5 Move the number in R5 to register B

8009 MUL AB Multiply the contents of A and B

800A DJNZ R5, LOOP Decrement R5 and jump to LOOP if R5 is


non-zero

800C INC DPTR Increment DPTR

800D MOVX @DPTR, A Store the lower byte

800E INC DPTR Increment DPTR


8010 MOV A, B Move the higher byte to A

8011 MOVX @DPTR, A Store the higher byte

8012 HERE: SJMP HERE Terminate

Note: Replace B with F0 in the mnemonics corresponding to locations 8007and 8010.

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.

You might also like