In this lab you will explore digital input and output and timing loops
using the PIC18F452 microcontroller
and the QuikFlash board. You will also look at PIC indirect addressing.
Part 1.
Using MPLAB create an assembly language program for the QuikFlash board
that will turn on LED D6
any time switch S3 is pressed and turn it off whenever S3 is released.
The LED should remain on as long
as the switch is pressed and remain off as long as it is released.
Your program should perform the following
tasks:
Set up Port A for digital I/O (set/clear appropriate ADCON1 bits).
Set up the bit of the port attached to LED D6 for digital output (set/clear appropriate TRISx bits).
Set up the bit of the port attached to SW3 for digital input (set/clear appropriate TRISx bit).
Enter into a polling loop that determines the state of S3 and turns
D6 on or off according to the state of the
switch.
Note, the bits that need to be set up can be determined from the diagram
of the QuikFlash board shown in
Figure 4-2 of the Peatman textbook. When the program has been developed
and built, download the hex file
to the QuikFlash and show the lab instructor that it does what it is
supposed to do.
Part 2.
Create a program that will blink LED D2 in such a way that it is on
for exactly five seconds and off for the
same amount of time. You should NOT use the technique of timers employed
in program P1 from your
textbook. Instead you should use a delay loop (or perhaps nested delay
loops) that have numbers of iterations
that you determine using the fact that the QuikFlash is clocked at
10 MHz -- and that this is divided by four
because of the 4 Q-states per instruction cycle. For this computation
you also will need to refer to the
microcontroller's spec sheet to get the number of instruction cycles
used by the various instructions in your
delay loop. Set up your delay code as a subroutine. You should be able
to show the lab instructor that the
program turns the LED on and off 12 times in 60 seconds.
Part 3.
Write a program that will continually count in binary from 0 to 7 and
display the current count on LEDs D4, D5,
and D6. In other words the LEDs should be lit according to the count
as follows:
Count D4 D5 D6
0 off off off
1 off off on
2 off on off
3 off on on
4 on off off
5 on off on
6 on on off
7 on on on
The counting should take place a rate of two counts per second.
Part 4.
Modify the program from Part 3 so that it responds any time switch SW3
is pressed by turning on LED D2 if the
value of the count at the moment the switch press occurred was odd
or by turning it off if the count was even.
After D2 is turned on or off in response to the switch press, the counting
should continue.
For all parts of this lab, you should show the lab instructor the program
running on the QuikFlash board and
submit listings of the .LST and .HEX files.