0% found this document useful (0 votes)
4 views32 pages

Microprocessors Lab Record: 8051 Programs

The document outlines a series of laboratory exercises for a course on microprocessors and microcontrollers, detailing programming tasks involving addition, subtraction, multiplication, division, looping, sorting, square wave generation, timers, LED control, interrupts, LCD display, and keyboard interface using 8051 assembly code. Each lab includes specific aims, instructions, and example programs to achieve the desired outcomes. The results of each lab were successfully verified.

Uploaded by

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

Microprocessors Lab Record: 8051 Programs

The document outlines a series of laboratory exercises for a course on microprocessors and microcontrollers, detailing programming tasks involving addition, subtraction, multiplication, division, looping, sorting, square wave generation, timers, LED control, interrupts, LCD display, and keyboard interface using 8051 assembly code. Each lab includes specific aims, instructions, and example programs to achieve the desired outcomes. The results of each lab were successfully verified.

Uploaded by

Ayush maurya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SCHOOL OF COMPUTER SCIENCE

AND ENGINEERING (SCOPE)

BECE204P – MICROPROCESSORS AND


MICROCONTROLLERS
LAB RECORD

Submitted By
23BCE1657 – AYUSH KUMAR MAURYA

Submitted To
RAHUL NAMRSIMHAN SIR
Date: 18/11/2024
LAB – 01: ADDITION AND SUBTRACTION

Aim – To program addition and subtraction of 2 8-bit,16-bit


numbers.

Instructions Required –

Addition -

1. Load immediate value 45H into register A

2. Load immediate value 0EH into register A (overwriting


previous value)

3. Copy the content of register A into register R0

4. Load immediate value 02H into register A

5. Add immediate value 0FCH to register A with carry, store


result in A

6. Copy the content of register A into register R1

7. Indicate end of the program


Subtraction-

1. Set the origin address to 00H (start of the program)

2. Load immediate value 4CH into register A

3. Load immediate value 6EH into register R1

4. Subtract the value in R1 from A with borrow, store the


result in A

5. Indicate the end of the program

Program –

Addition - Subtraction –

MOV A, #45H; ORG 00H

MOV A, #0EH, MOV A, #4CH

MOV R0, A; MOV R1,#6EH

MOV A, #02H; SUBBA,R1

ADDC A, #0FCH; END

MOV R1, A;

END
OUTPUT –

Result – The outputs for the addition and subtraction were


successfully verified.
LAB – 02: Arithmetic Instructions

Aim – To program Multiplication and Division of 2 8-bit,16-bit


numbers.

Instructions Required –

Multiplication –

1. Set the origin address to 00H

2. Load immediate value 3FH into register A

3. Load immediate value 23H into register B

4. Multiply the values in A and B, result stored in A (low byte)


and B (high byte)

5. Indicate the end of the program

Division –

1. Set the origin address to 00H

2. Load immediate value 50H into register A (numerator)

3. Load immediate value 05H into register B (denominator)

4. Divide A by B, quotient stored in A, remainder stored in B

5. Indicate the end of the program


Program –

Multiplication – Division -

ORG 00H ORG 00H

MOV A, #3FH MOV A, #50H

MOV B, #23H MOV B, #05H

MUL AB DIV AB

END END

OUTPUT –

Result - Result – The outputs for the multiplication and division


were successfully verified.
LAB – 03: LOOPING AND SWAPPING

Aim – To understand loops and write program for the swapping


of data.

Instructions Required –

Sum of first 10 natural numbers -

1. Set the origin address to 00H

2. Load immediate value 0AH (decimal 10) into register R0

3. Add the value of R0 to A with carry, store the result in A

4. Decrement R0 and jump to HERE if R0 is not zero

5. Indicate the end of the program

Swapping of two data-

1. Set the origin address to 00H

2. Load the immediate value 0FH into memory location 30H

3. Load the immediate value 09H into memory location 31H

4. Load the value at memory location 31H into register A


5. Move the value from memory location 30H to 31H

6. Move the value in register A to memory location 30H

7. Indicate the end of the program

Program –

Sum of first 10 natural numbers -

ORG 00H

MOV R0, #0AH

HERE: ADDC A, R0;

DJNZ R0, HERE;

END;

Swapping of two data-

ORG 00H

MOV 30H, #0FH

MOV 31H, #09H

MOV A, 31H

MOV 31H, 30H

MOV 30H, A

END
OUTPUT –
LAB – 04: SORTING OF NUMBERS

Aim – To write a program to sort the given numbers and


verifying in software.

Instructions Required –

1. Set the origin address to 00H

2. Initialize R4 as the outer loop counter with a value of 4

3. Set R0 to the starting address 50H

4. Copy the value of R4 into B (used as a loop variable)

5. Copy B into R2 (inner loop counter)

6. Load the value of R0 into A

7. Increment A

8. Set R1 to A (next memory address)

9. Move the value at memory location pointed to by R0 into


10H
10. Load the value at memory location pointed to by R1
into A Compare A with 10H; if not equal, jump to L3

11. If equal, skip the exchange and jump too NEXT

12. If the carry flag is set, jump to EXCHANGE

13. Otherwise, skip the exchange and continue

14. Swap the value in A with the value at the address R0

15. Swap the value in 10H with the value at the address R1

16. Increment R1 to move to the next address

17. Decrement R2 (inner loop counter) and repeat L2 if not


zero

18. Increment R0 to move to the next starting address

19. Decrement R4 (outer loop counter) and repeat L1 if not


zero

20. Infinite loop to halt execution

21. Indicate the end of the program


Program –
ORG 00H;
MOV R4, #4;
MOV R0, #50H;
L1: MOV B, R4;
MOV R2, B;
MOV A, R0;
INC A;
MOV R1, A;
L2: MOV 10H, @R0;
MOV A, @R1;
CJNE A,10H, L3;
SJMP NEXT
L3: JC EXCHANGE;
SJMP NEXT;
EXCHANGE: MOV @R0, A;
MOV @R1,10H;
NEXT:INC R1;
DJNZ R2, L2;
INC R0;
DJNZ R4, L1;
HERE: SJMP HERE;
END
OUTPUT –
LAB – 05: SQUARE WAVE GENERATION

Aim – To generate square wave in keil software using the 8051-


assembly code.

Instructions Required –

1. Set the origin address to 00H

2. Set all bits of Port 1 (P1) to HIGH (LEDs ON)

3. Call the DELAY subroutine

4. Set all bits of Port 1 (P1) to LOW (LEDs OFF)

5. Call the DELAY subroutine

6. Jump back to MAIN to repeat the loop

7. Load R0 with 19H (outer loop counter)

8. Load R1 with 100H (inner loop counter)

9. Decrement R1 and jump back to INNER if not zero

[Link] R0 and jump back to OUTER if not zero

[Link] from the subroutine

[Link] the end of the program


Program –

ORG 00H

MAIN:

MOV P1, #0FFH

ACALL DELAY

MOV P1, #00H

ACALL DELAY

SJMP MAIN

DELAY:

MOV R0, #19H

OUTER:

MOV R1, #100H

INNER:

DJNZ R1, INNER

DJNZ R0, OUTER

RET

END
Output –
LAB – 06: TIMERS AND COUNTERS

Aim – To generate a delay and understanding counters by writing


8051 assembly code.

Instructions Required –
Delay Generation –
1. Set the origin address to 00H
2. Clear all bits of Port 1 (initialize P1 to 0)
3. Set bit 1 of Port 1 (turn on LED connected to P1.1)
4. Call the DELAY subroutine
5. Clear bit 1 of Port 1 (turn off LED connected to P1.1)
6. Call the DELAY subroutine
7. Jump back to back to repeat the process
8. Load R2 with 10 (outermost loop counter)
9. Load R3 with 255 (middle loop counter)
[Link] R4 with 255 (innermost loop counter)
[Link] R4 and loop back to HERE if not zero
12. Decrement R3 and loop back to AGAIN2 if not zero
[Link] R2 and loop back to AGAIN if not zero
15. Return from the subroutine
[Link] the end of the program
Program –
Delay Generation – Counters -
ORG 00H ORG 0000H
MOV P1, #00H; MOV TMOD, #06H;
BACK: SETB P1.1; MOV TH0, #00H;
ACALL DELAY MOV TL0, #00H;
CLR P1.1 MOV P1, #00H;
ACALL DELAY CLR P3.4;
SJMP BACK SETB TR0;
AGAIN:
DELAY: MOV R2, #10 CLR P3.4;
AGAIN: MOV R3, #255 MOV A, TL0;
AGAIN2: MOV R4, #255 MOV P1, A;
HERE: DJNZ R4, HERE JB TF0, HERE;
DJNZ R3, AGAIN2 SJMP AGAIN;
DJNZ R2, AGAIN HERE: CLR TF0;
RET SJMP AGAIN;
END END
Output –
LAB – 07: I/O HARDWARE – LED

Aim- To write a program and light the LED using the 8051-
assembly code.

Instructions Required –

1. Set the starting address of the program

2. Reset vector address and jump to MAIN (main program


execution)

3. External interrupt 0 vector (INT0)

 Interrupt vector for INT0

 Complement (toggle) bit P1.2

 Return from interrupt

4. Interrupt vector for Timer 0 overflow and set bit P1.1 (make
it high).Return from interrupt

5. Start of main program

Clear bit P1.1 (make it low) Clear bit P1.2 (make it


low)Configure Timer 0 in Mode 1 (16-bit timer)

6. Enable interrupts:

EA = 1 (Global interrupt enable)


EX0 = 1 (Enable INT0 interrupt)

ET0 = 1 (Enable Timer 0 interrupt)

7. Continuously clear bit P1.1 in the main loop

8. End of program

Program –

ORG 0000h

LJMP MAIN

ORG 0003H

CPL P1.2

RETI

ORG 0013H

SETB P1.1

RETI

ORG 0050H

MAIN: CLR P1.1;

CLR P1.2

MOV TCON,#02H

MOV IE,#85H
HERE:CLR P1.1

SJMP HERE

END

Output –
LAB – 08: 8051 INTERRUPT HARDWARE
LAB – 09: 8051 LCD

Aim – To write a program and display the word on LCD using


the 8051-assembly code and the hardware kit.

Instructions required –

1. Initialization: LJMP MAIN sets the program to start at the


main routine.

2. Interrupt Setup: ORG 0003H handles an interrupt by


writing "MPMC" to an LCD using COMNWRT (command
write) and DATAWRT (data write) subroutines.

3. Main Routine: Configures interrupts (IE) and starts Timer


0 (TCON).

4. LCD Initialization: Commands (38H, 0EH, 01H, 06H, 84H)


set LCD mode and cursor.

5. Data Writing: Displays "AYUSH" and "MPMC" by


writing each character with delays.
6. Subroutines:

 COMNWRT sends commands to the LCD.

 DATAWRT writes data to the LCD.

 DELAY provides timing between operations.

7. Infinite Loop: AGAIN, holds the program execution.

Program –

ORG 0000h Mov A, #06h

LJMP MAIN ACALL COMNWRT

ORG 0003H ACALL DELAY

Mov A, #38h Mov A, #84h

ACALL COMNWRT ACALL COMNWRT

ACALL DELAY ACALL DELAY

Mov A, #0Eh Mov A, #'M'

ACALL COMNWRT ACALL DATAWRT

ACALL DELAY ACALL DELAY

Mov A, #01h Mov A, #'P'

ACALL COMNWRT ACALL DATAWRT

ACALL DELAY ACALL DELAY


Mov A, #'M' ACALL DELAY

ACALL DATAWRT Mov A, #06h

ACALL DELAY ACALL COMNWRT

Mov A, #'C' ACALL DELAY

ACALL DATAWRT Mov A, #84h

ACALL DELAY ACALL COMNWRT

RETI ACALL DELAY

ORG 0050H Mov A, #'A'

MAIN:MOV IE, #10000001B; ACALL DATAWRT

MOV TCON, #01H; ACALL DELAY

Mov A, #38h Mov A, #'Y'

ACALL COMNWRT ACALL DATAWRT

ACALL DELAY ACALL DELAY

Mov A, #0Eh Mov A, #'U'

ACALL COMNWRT ACALL DATAWRT

ACALL DELAY ACALL DELAY

Mov A, #01h Mov A, #'S'

ACALL COMNWRT ACALL DATAWRT


ACALL DELAY CLR P3.5

Mov A, #'H' RET

ACALL DATAWRT DELAY:

AGAIN: SJMP AGAIN MOV R3, #50

COMNWRT: HERE2:MOV R4, #255

MOV P2, A; HERE: DJNZ R4, HERE

CLR P3.7; DJNZ R3, HERE2

CLR P3.6 RET

SETB P3.5 END

ACALL DELAY

CLR P3.5

RET

DATAWRT:

MOV P2, A;

SETB P3.7;

CLR P3.6

SETB P3.5

ACALL DELAY
Output –
LAB – 10: KEYBOARD INTERFACE

Aim –

Instructions Required-

You might also like