Datasheet
PICkitâ„¢ 3 Debug Express
DS41370C-page 72 © 2009 Microchip Technology Inc.
Finally, the CCP1 module is configured for PWM operation with a duty cycle of 50% as
described previously in this lesson:
CCPR1L = 0x7D; // The 8 most significant bits of the period are 0x7D
CCP1CON = 0b01001100; // The 2 LSbs are 0b00, and CCP1Mx = 110 for PWM
At this point in the program in the module running, generating and outputting a PWM
signal on RD7/P1D with 50% duty cycle at 62.5 Hz.
To make the LED get brighter and then dimmer, we have a loop that changes the duty
cycle. The first do while loop increases the brightness over 2 seconds by increasing
the duty cycle. As the duty cycle is increased, the LED is on for a longer period of time
so it appears brighter. Note that for simplicity, the lesson program only changes the 8
MSbs of the duty cycle value in CCPR1L.
The second do while loop decreases the brightness over 2 seconds by reducing the
duty cycle. As the duty cycle is decreased, the LED is on for shorter and shorter periods
of time, making it appear dimmer.
3.12.4 Build and Run the Lesson 12 Code with PICkit 3 Debug Express
Build and program the Lesson 12 project, then Run the application in the debugger. You
will see the demo board LED 7 continuously get brighter then dimmer! If you have an
oscilloscope available, connect a probe to one of the RD7 signal points on the demo
board to see the changing the PWM waveform.