Led brightness control using PWM in PIC16F877A microcontroller

In: Project Code: PE000006
Share

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 article before executing this project. If you are new to PIC microcontroller programming we suggest you to execute the basic led blinking project before trying this project.

The setup requirement for this project is as given below:



course thumb

Project Content


Online courses related to this project


Course description

Learn firmware development theory, applications, get practical skills from online tests, projects and earn certificate for software jobs



Course description

Learn to develop embedded systems, interfacing electronic peripherals through real time projects and get required practical skills for software jobs

Required hardware and software


The required hardware and software for this project is as below:

  • A breadboard
  • 1 x 4mmLED
  • 1 x resistor between 220 Ohm to 1 kOhm
  • Hookup cables
  • Development board hosting PIC16F877A 8-bit microcontroller
  • MPLAB IDE(v5.05) from Microchip
  • PICKIT3 Programmer, connecting cable from PICKIT3 to your computer.
  • Power supply for the development board

  • Project Connections


    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 PWM channels description


    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 channels detailed description

    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

    Prepare source code, building program source code, creating binary


    Prepare source code

    To Read Full Article

    Start any course from the following

    Share