You are on page 1of 9

King Abdulaziz University

Faculty of Engineering
Electrical-Computer Engineering Department

EE366 | Microprocessors and Microcontrollers


Lab Experiment #2
PIC Microcontrollers Architecture, Simulation, & Assembly

Section
EAG

Lab Time
Wednesday, 14:00–15:50

Submission Date

Wednesday, February 19th, 2020

Team Members

Haneen Alsaedi 1606278

Lana Joharji 1607588

Noura Aldakhil 1614549

Instructors
Dr Rania Elmanfalouty
Eng. Haneen
Table of Contents

Introduction ................................................................................................................................ 3

Objectives .................................................................................................................................. 3

Experiment ................................................................................................................................. 4

Schematic Diagram ................................................................................................................ 4

Source Code ........................................................................................................................... 5

Results ........................................................................................................................................ 6

Conclusion ................................................................................................................................. 9

References .................................................................................................................................. 9

2
Introduction
The PIC microcontroller was the first widely available device to use flash memory, which
made it ideal for prototyping and experimental work [1]. PIC microcontrollers (Programmable
Interface Controllers), are electronic circuits that can be programmed to carry out a vast range
of tasks. They can be programmed to be timers or to control a production line. They are found
in most electronic devices such as alarm systems, computer control systems, phones [2]. The
PIC microcontroller contains a processor, memory and input/output ports, and the program is
stored in flash ROM memory in numbered locations [3]. Many types of PIC microcontrollers
exist such as PIC18 which was used in this lab. In this lab, two exercises were made to help us
understand the Assembly Language programming and to deal with I/O port programming.
Also, to understand who to deal with the status register especially with examination of the flag
bits. Finally, to understand how to use loops in MPLAB.

Objectives

• To gain an understanding of Assembly Language programming


• To gain an understanding of I/O port programming
• To examine the flag bits of the status register
• To gain an understanding of Branch and time delay loops

3
Experiment
Schematic Diagram
In this section, the circuit schematics constructed on Proteus for each corresponding exercise
are provided, as shown in Figures 1 and 2. The run simulations of each diagram are discussed
in detail in the “Results” section. The circuit specifications were as follows:

• MCU: PIC18F4550
• Resistors: 330 Ω
• LED: LED-RED
• Power: 5V

EXERCISE 1.

Figure 1: Exercise 1 Schematic

EXERCISE 2.

Figure 2: Exercise 2 Schematic

4
Source Code
The presented source codes (.asm), corresponding to both exercises 1 and 2, shown below were
assembled using MPLAB X IDE. The generated .hex files were then uploaded onto Proteus to
run simulations of the hardware connections and installed onto the Dwengo board to run the
code on a an actual MCU.

EXERCISE 1.

include <p18f4550.inc>
org 0
Start:
CLRF TRISD ; Set all PORTD pins as output
BSF LATD,3 ; Set pin RD3 to turn on LED3
GOTO $ ; Wait here
END

EXERCISE 2.

#include <p18f4550.inc>

cblock 0x60
counterL ; Define counterL at 60H
counterH ; Define counterH at 61H
endc

org 0
Start:
CLRF TRISD ; Set all PORTD pins as output
BSF LATD, 7 ; Set pin RD7 to turn on LED7

Rotate:
RRNCF LATD, F ; Rotate LATD data
CALL Delay ; Waste time
GOTO Rotate ; Repeat

Delay:
DECFSZ counterL ; Decrement counterL skip next if zero
GOTO Delay ; Repeat
DECFSZ counterH ; Decrement counterH skip next if zero
GOTO Delay ; Repeat
Return
END

5
Results
EXERCISE 1. Write and assemble a program to turn on an LED connected to pin3 of port D, RD3.
To turn on or off an LED, we will have to send a value of 1 to the corresponding port D pin. This
can be done by setting or clearing the corresponding bit in the LATD register. Notice the port D
pins by default can only be configured as digital, and therefore, you do not have to set ADCON1
register.

Shown in Figure 3 are both TRISD and LATD registers. Since it was required to set pin 3 of Port
D (RD3) to turn on the LED, the corresponding bit of LATD was set to “1” (Bit #3). The LATD
register is 8 bits wide; therefore, by setting bit #4 to 1 the contents of said register would be “0000
1000” = 08H = 8D. Figure 3 highlights this result.

Figure 3: Registers TRISD & LATD - Exercise 1

Moving on, the generated .hex file was then uploaded to Proteus to run the simulation. As observed
in Figure 4, the LED connected to RD3 (Pin 3 of Port D) turned on meaning the simulation ran
successfully. Furthermore, the .hex file could now be installed onto the Dwengo board safely after
making it was not faulty. Figure 5 shows the output of the installed program, which validated the
simulations run on Proteus – LED 3 turned on.

Figure 5: Proteus Simulation – Exercise 1 Figure 4: Dwengo Board Output – Exercise 1

6
EXERCISE 2. Configure ports RD0 to RD7 connected to LEDs LD0 to LD7 as digital output.
Write a code that will start by turning on LD7, and shift it to LD6, and so on until it reaches LD0.
Use appropriate delay to display the result. Examine your file registers in MPLAB. Then, simulate
your hardware connection in Proteus ISIS Professional using the generated hex file. Finally, install
your hex file on the Dwengo board.

Shown in Figure 6 are both TRISD and LATD registers. Since it was required configure pins RD0
– RD7 as digital output, all the bits for TRISD were set to “0” by using the CLRF command. This
is can be seen in Figure 6 – TRISD Value: “0000 0000” = 00H. Furthermore, bit #7 was set to “1”
in the LATD register as shown below (“1000 0000”). After that the LATD pins were rotated to
accomplish required shifting of LEDs as shown in Figure 7.

Figure 6: Registers TRISD & LATD - Exercise 2

Figure 7: Register LATD after rotation

For Exercise 2, a delay was added between instructions to be able to observe the output on the
specified LEDs. This time delay was executed inside a loop by continuously decrementing two
counters until they became zero. Said counters were stored in locations 0x60 and 0x61. Figures 7
and 8 show the decrements.

Figure 8: CounterL before decrement

Figure 9: CounterL after decrement

7
Furthermore, the generated .hex file was then uploaded to Proteus to run the simulation. As
observed in Figure 10 to 13, the LEDs 1-8 connected to pins RD0-RD7 kept on shifting
continuously. In addition, the output of the program on the Dwengo board is shown in figures 14
and 15.

Figure 10: Proteus Simulation - Exercise 2 P1 Figure 11: Proteus Simulation - Exercise 2 P2

Figure 12: Proteus Simulation - Exercise 2 P3 Figure 13: Proteus Simulation - Exercise 2 P4

Figure 14: Output on Dwengo Board P1 Figure 15: Output on Dwengo Board P2

8
Conclusion
In conclusion, the two experiments were successfully simulated, and the objectives were met.
All the results were discussed and successfully done using the MPLAB software and the
Proteus ISIS Professional which simulate the hardware connections as well as the Dwengo
board to show our results. This experiment helped us to get the understanding of the branch
and time delay loops as well as using the method of toggle. Finally, a clear understanding of
the simulators was obtained.

References

[1] https://www.sciencedirect.com/topics/engineering/pic-microcontroller

[2] http://www.technologystudent.com/pics/picgen1.html

[3] https://www.sciencedirect.com/topics/engineering/pic-microcontroller

You might also like