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

Lab Embedded

Uploaded by

Shaheer Ahmed
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)
16 views

Lab Embedded

Uploaded by

Shaheer Ahmed
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/ 5

Microcontrollers

&
Embedded Systems
(MTS -331)
DE-44 Mechatronics
Syndicate – C
Lab Report
Week # 7

Names of Members:

1. GC Ahmed Hassan
Reg # 431990

2. GC Ahmed Mujtaba Kayani

Reg # 431979

Submitted to: LD Muhammad Qasim

1
Abstract:
This lab aimed to introduce basic coding techniques using Keil software, integrated
with the 8051 microcontroller in Proteus, to provide hands-on experience with
assembly coding and debugging tools. The objective was to gain foundational
knowledge of embedded systems operations.

Introduction:
The lab focused on key microcontroller functions within the Keil µVision
environment for the 8051. We performed delay calculations and explored the concepts
of machine cycles and clock cycles.

Tools:
The software used includes:

● Keil µVision

Procedure:

Part 1: Assembly Subroutines (Functions)

Task 1: Compare Bytes in RAM Memory

1. Objective: Create a subroutine to count matching bytes between two memory


blocks: 10h-1Fh and 20h-2Fh.
2. Instructions:
○ MOV DPTR, #TABLE1: Load the base address of TABLE1 into DPTR.
○ MOV R1, #TABLE2: Load the base address of TABLE2 into R1.
○ MOV R0, #0x10: Set R0 to 16, the number of bytes to compare.
○ MOV B, #0: Initialize the match counter B to zero.
3. Loop (LOOP):
○ MOVC A, @A+DPTR: Load the current byte from TABLE1 into A.
○ MOV R2, A: Temporarily store this byte in R2.
○ MOV DPTR, #TABLE2: Point DPTR to TABLE2.
○ MOVC A, @A+DPTR: Load the corresponding byte from TABLE2.
○ CJNE A, R2, SKIP: Compare bytes from TABLE1 and TABLE2; skip if
not equal.
○ INC B: If they match, increment the counter B.
○ SKIP: If bytes do not match, proceed without incrementing B.
○ Update pointers with INC DPTR and INC R1 to progress through
memory.
○ DJNZ R0, LOOP: Decrement R0 and repeat until all bytes are
compared.

2
Figure 1 : TASK 1

Task 2: PWM Signal Generation

1. Initialization:
○ TMOD = 01H: Set Timer 0 to 16-bit mode.
○ Set P1.1 high to initiate the PWM cycle.
2. PWM Loop:
○ High Time: Load TH0 and TL0 with FFH and 014H for a 228 µs delay,
then wait for TF0 overflow before setting P1.1 low.

Figure 2 :TASK2

○ Low Time: Set TH0 and TL0 to FFH and 039H for a 57 µs delay, then
wait for TF0 overflow and set P1.1 high to continue the cycle.

3
Figure 3: TASK 2

Part 2: Programming in C

Task 1: Toggle Port 1 Pins with Loops

● Toggled pins 3 and 4 of Port 1 using a for loop in C.


● Steps:
○ #include <reg51.h> includes the 8051 function library.
○ sbit sets bits 3 and 4 as P1^3 and P1^4 to easily access them within the
loop.
○ A loop iterates 2000 times, toggling the pins each time.

Figure 2 Using loops for toggling pins

Task 2: Sensor-Based Buzzer Control on Port 1

● Controlled toggling of pin 7 based on the state of pin 1.


● Steps:
○ Assign SENSOR to bit 1 (P1.1) and BUZZER to bit 7 (P1.7) using sbit.
○ In the run() function, check if SENSOR is active; if yes, set BUZZER
high, otherwise set it low.
4
Figure 3 Buzzer and Sensor

Task 3: LCD Display Control Using Ports 1 and 2

● Controlled an LCD to display the text “I love Pakistan.”


● Steps:
○ #include <reg51.h> imports 8051 registers, defining EN as bit 0 of Port
2 (P2.0).
○ A character array stores the text.
○ while(1) creates a continuous loop, while for iterates through each
character for display.
○ Delay() uses nested loops to create a timed delay.

Figure 4 LCD Display

Conclusion:
This lab provided practical experience in coding and debugging for the 8051
microcontroller, reinforcing key concepts in embedded systems and preparing us for
more advanced projects.

You might also like