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.
The setup requirement for this project is as given below:
Learn firmware development theory, applications, get practical skills from online tests, projects and earn certificate for software jobs
The required hardware and software for this project is as below:
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:
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 channel||PORT output Pins||Control Register||Duty Cycle Register||Period Register|
|PWM1||PORTC PIN 2||CCP1CON||CCPR1L||PR2|
|PWM2||PORTC PIN 1||CCP2CON||CCPR2L||PR2|