Lab Four Lab04 Instructions
User Manual:
Open the PDF directly: View PDF
.
Page Count: 1

Spring 2018
Page 1 of 1
Lab 4 Instructions
Context Saving, Pulse Width Modulation, CCP Compare Function
This lab familiarizes the student with context saving, pulse width modulation (PWM), and the
compare feature of the CCP module of the PIC. The hardware layout is the same as in Lab 2 and
Lab 3.
1. Create a project using the lab04a.asm file from the course website. Connect a
potentiometer to ADC channel 0 so that you can adjust the input voltage between 0 and 5
volts. Connect LEDs to the PORTC pins. Run the program and turn the pot. Notice how the
LEDs get dimmer and brighter as you adjust the pot. This effect is a result of modulating the
pulse width of the PORTC PWM output voltage.
2. Create a project using the lab04b.asm file. Connect an active low switch to RB0. Lab04b
is a modification of lab04a so that when you press the RB0 switch, the LEDs toggle on and
off. Run the program. The pot still controls the intensity of the LEDs when they are on. The
RB0 interrupt is set up as a rising edge interrupt, and RB0 is active low, so the LEDs toggle
when you release the RB0 button. Lab04b.asm also illustrates how multiple interrupts are
handled.
3. Create a project using the lab04c.asm file. This program uses the CCP1 interrupt to
toggle the RC2 output, which you should connect to an LED. Run the program and notice
that the LED is blinking because of CCP1 interrupts.