Lab Reprt 3 Micro

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Microcontroller and Embedded Systems (MTS - 311) LAB REPORT

Microcontroller & Embedded


Systems
(MTS-311)

DE-43 Mechatronics
Syndicate – B

LAB REPORT
Week#3 AT89C51 Controller and Keil µVision

Names of Group Members:


 NS Saad Irfan CMS ID #388842
 NS Muhammad Rohail Abid CMS ID #365743

Submitted to: LD Qasim

Page 1 of 8
Microcontroller and Embedded Systems (MTS - 311) LAB REPORT

Introduction:

In this lab, we wrote code on Keil µVision software to add numbers, debug and export
the code to the 89C51 controller, and show the output on one of the ports of the controller. We
also were able to understand the address control, symbol definitions, and memory initialization
on Keil µVision software. Lastly, we wrote a code-based assembly directive and tested the
code on Keil µVision software.

Objective:

 Learn how to add numbers on Keil µVision, debug and test that code, and export that
code in the form of a hex file to be usable in Proteus.
 Understand the use of SET and EQU directive.
 Use the CLR and SETB commands to access the bits of the 89C51 controller.
 Write a code that makes use of assembly directives and, show the output.

Lab Task 1: Add two numbers on Keil µVision software.

To add two numbers in assembly coding format we have to use the command add A,
then by moving one of the numbers to A, we would add the second number into A itself.

Code:

ORG
MOV A, #33H ; moving the first number to A.
ADD A, #46H ; adding the second number to A.
MOV R7, A ; moving the added numbers present in A to R7.

Page 2 of 8
Microcontroller and Embedded Systems (MTS - 311) LAB REPORT

Figure 1 Adding two numbers on Keil µVision software.

LAB TASK 2: Add two numbers by taking the input from the 89C51 controller and
showing the output on one of the ports of the controller.

Procedure:

1. Open Keil µVison and create a new project for the AT89C51 controller.
2. Write code as instructed below.
3. Debug the code by running the debugger.
4. Create a Hex file in the Target Options menu.
4. Import the Hex file in Proteus.
5. Run the Proteus circuit.

Code:

ORG
MOV A, p1 ; move the input value of p1 to A.
Add A, P2 ; Add the pin value of p2 to A.
MOV A, P3 ; Move the added value to p3
END

Page 3 of 8
Microcontroller and Embedded Systems (MTS - 311) LAB REPORT

Figure 2 code to add two values using the 89C51 controller.

Proteus Simulation:

Figure 3 output of task 2 shown on proteus.

LAB TASK 3: Add three numbers by taking the input from the 89C51 controller and
showing the output on one of the ports of the controller.

Procedure:

1. Open Keil µVison and create a new project for the AT89C51 controller.
2. Write code as instructed below.
3. Debug the code by running the debugger.
4. Create a Hex file in the Target Options menu.
4. Import the Hex file in Proteus.
5. Run the Proteus circuit.

Page 4 of 8
Microcontroller and Embedded Systems (MTS - 311) LAB REPORT

Code:

MOV A, p1 ; move the input value of p1 to A.


ADD A, p2 ; Add the pin value of p2 to A.
ADD A,P3 ; Add the pin value of p3 to A.
MOV PO, A ; move the value of A to p0

Figure 4 code for task 3.

Figure 5 creating hex file.

Page 5 of 8
Microcontroller and Embedded Systems (MTS - 311) LAB REPORT

Proteus simulation:

Figure 6 proteus simulation of task 3.

LAB TASK 4: Accessing the bit of the 89C51 controller using a code written on Keil
µVision software.

In the following task, we make use of the SETB and CLR commands, the SETB assigns
the value of 1 to the addressed bit and the CLR command assigns the value of 0 to the addressed
bit.

Figure 7 code for task 4.

Page 6 of 8
Microcontroller and Embedded Systems (MTS - 311) LAB REPORT

Figure 8 Output of task 4.

LAB TASK 5: To understand the use of EQU and set directives and write and debug
the code based on assembly directives.

1. EQU and SET directives: Both these directives are used to name a constant number,
use arithmetic operations, and provide user defied names to constants or the ports of the
controller. These directives are used to make the programming language easy to understand for
the user as well as the coder. The only difference between SET and EQU is the ability to rewrite
as the SET command lets the user redefine whereas the EQU directive does not.

Figure 9 an example of the SET and EQU directive.

2. In the second part of this lab we used the SET and EQU directives to assign values
to bit addressable data of the controller and viewed the changes made to the bits.

Page 7 of 8
Microcontroller and Embedded Systems (MTS - 311) LAB REPORT

Figure 10 code to use SET and EQU directives to access the bit addressable data.

Explanation:

The following code assigns the of 10H to the limit and the value of 20H to the symbol
then by using the “x bit 0” the bit x is assigned the value of 0, and by using “y data 30H” the y
byte has been assigned the value of 30h. Then by using the ‘mov y, #limit” the value of 30H
initially stored in the Y byte is replaced by the value 10H stored in the limit, the same thing is
observed when “mov y, #symbol” is used as it replaces the 10H stored in Y to 20H assigned to
the symbol.

Figure 11 shows the value of 20H stored in 30 at the end of the code.

Conclusion:

We successfully wrote the code to add two as well as three numbers as input from the
89C51 controller and show their output on the port po of the controller. We were able to make
use of the CLR and SETB commands to assign the value of 1 or 0 to the bits of the controller.
We were able to understand the use of the SET and EQU directives and implement them in a
code.

Page 8 of 8

You might also like