0% found this document useful (0 votes)
46 views11 pages

PIC18F452 Assembly Projects

The document is an assignment submission for a course on microcontrollers. It contains 4 questions regarding writing and demonstrating assembly language programs for a PIC18F452 microcontroller. The questions involve generating a square wave, stepping through a nested loop program, toggling LEDs on a port with a 1-second delay, and turning an LED on and off based on a switch state. For each question, the submission provides steps to write the assembly code, simulate the program in Proteus, and in some cases replicate the functionality on hardware.

Uploaded by

SHAHZEB AFRIDI
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)
46 views11 pages

PIC18F452 Assembly Projects

The document is an assignment submission for a course on microcontrollers. It contains 4 questions regarding writing and demonstrating assembly language programs for a PIC18F452 microcontroller. The questions involve generating a square wave, stepping through a nested loop program, toggling LEDs on a port with a 1-second delay, and turning an LED on and off based on a switch state. For each question, the submission provides steps to write the assembly code, simulate the program in Proteus, and in some cases replicate the functionality on hardware.

Uploaded by

SHAHZEB AFRIDI
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

COMSATS UNIVERSITY ISLAMABAD,

ABBOTTABAD CAMPUS.

[Link] 5

SUBJECT

• MSI

Submitted To:
• Sir Usman Khalid

Submitted by

• Bilal Iftikhar(FA21-EEE-001)

1
Q1:Write assembly language program to generate a square wave with a precise
50% duty cycle on RD6 using a PIC18F452 microcontroller. Present the waveform
using MPLAB (Logic Analyzer) and subsequently in Proteus simulation
(oscilloscope).

ANS:

Setting up the timer and configuring the necessary registers is necessary to create
an assembly language program that uses a PIC18F452 microcontroller to produce
a square wave on RD6 with a 50% duty cycle.

Step 1: Set up MPLAB X IDE

1: Starting the MPLAB X IDE.

2. Develop a brand-new PIC18F452 microcontroller project.

3: Include a new assembly code (ASM) file in the project.

Step 2: Configure the PIC18F452 Microcontroller

You must set the RD6 pin as an output and the oscillator of the microcontroller in
your assembly code. Here is a sample of code that accomplishes this.

Step 3: Build and Program the Microcontroller

2
Step 4: Set Up Logic Analyzer in MPLAB

3
Step 5: Simulate in Proteus

You may now see the square wave in Proteus by simulating your circuit. Build a
circuit using a PIC18F452 microcontroller, then attach pin RD6 of the
oscilloscope.

4
Step 6: Run the Simulation

When you run the Proteus simulation, RB5 should display a square wave with a
50% duty cycle. The same waveform should also be caught in MPLAB's Logic
Analyzer.

Q2: Write assembly language and demonstrate its execution step-by-step using
single-step mode in MPLAB. Explain the changes in the loop counters and the
expected behavior of the nested loop during each iteration.

5
ANS: Let's build a basic program with nested loops to show how to execute
assembly language code in MPLAB step-by-step using single-step mode. We will
describe how the loop numbers vary and what should happen at each iteration.A
PIC microcontroller (such as the PIC18F452) will be utilized to regulate an LED
that is linked to a GPIO pin. In order to show how nested loops are executed, the
software will cause the LED to blink in a certain manner. For this example, we'll
be using the MPLAB X IDE.

Step 1: Configure the Microcontroller and Open MPLAB X IDE

Start the MPLAB X IDE.

2. Construct a brand-new PIC18F452 microcontroller project.

3: Include a fresh ASM file for your assembly code in the project.

4: Set up the GPIO pins and oscillator settings on the PIC18F452.

Write the assembly code in step two.

6
Here is the nested loop's basic assembly code.

7
value change in file register

Q3:Toggle all eight LEDs connected to the PORTD of a PIC18F452


microcontroller, turning them on and off sequentially with a 1-second delay
between each transition. First, simulate this behavior in Proteus. Next, replicate
the same functionality on hardware by interfacing am PIC18F452 microcontroller
with the LEDs on a physical circuit. Observe the LED patterns in both Proteus
simulation and the hardware setup, ensuring that the LEDs toggle on and off with
the specified delay. Compare and analyze any differences observed in the
simulation and hardware execution.

8
ANS:
Step 1: Write the Assembly Code

• Use the proper assembler to compile the assembly code.

• In the Proteus simulation, load the compiled code into the PIC18F452
microcontroller.

*After running the simulation, you ought to see the LEDs alternate in a sequential
manner, with a 1-second gap between each change.

9
Q4: Establish a circuit in Proteus involving a PIC18F452 microcontroller, where
a LEDs are connected to RC0, and a switch is connected to RB0. Program the
microcontroller such that when the switch (connected to RB0) is turned on, it turn
on the LED on RC0, and when the switch is turned off, it turn off the LED on RC0.
Test and demonstrate this logic in the Proteus simulation to verify its functionality.

ANS:

Step 1: Write the Assembly Code in MPLAB

Step 2: Simulate the Circuit in Proteus

10
1. Launch the Proteus model.

2. To mimic pushing the switch, click on it (RB0). When the switch is pressed, the
LED on RC0 should turn on, and when it is released, it should turn off.

11

You might also like