In this project we will use pulse width modulation to control the brightness of led connected to a PIC16F877A microcontroller. If you are new to pulse width modulation technique go through PWM theory of operation article before executing this project. If you are new to PIC microcontroller programming we suggest you to execute the basic led blinking project here before trying this project. If you don't have access to your own hardware for this project, you can schedule the project on our company hardware and execute it remotely.
Led has two leads. The longer lead is +ve and shorter lead is -ve. Connect PORTC PIN 2 of the microcontroller to one end of the resistor and other end of the resistor to +ve end of the led. Connect the -ve end of the led to the ground on the development board.
PIC16F877A microcontroller has two CCP(Capture/Compare/PWM) modules, such as CCP1 and CCP2. Each Capture/Compare/PWM (CCP) module contains a 16-bit register which can operate as a:
16-bit Capture register
16-bit Compare register
PWM Master/Slave Duty Cycle register
We will be using CCP1 as PWM Master register in this project. PWM Master register is a 10-bit register and hence can have values between 0 to 1023 only. When CCP mode is configured as PWM it will use timer2 of PIC microcontroller. The 8-Msb bits are stored in CCPRxL and remaining 2-bits in CCPxCON register.
PWM channels detailed description
PORT output Pins
Duty Cycle Register
PORTC PIN 2
PORTC PIN 1
Prepare source code, building program source code, creating binary