Created
May 14, 2016 07:54
-
-
Save SaheblalBagwan/2d9ab8cbf840407b7248fef40fc56e21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<pic16f877a.h> | |
void delay(int cnt) { | |
while (cnt--); | |
} | |
int main() { | |
char dutyCycle = 0; | |
TRISC = 0x00; // Configure PORTC as output(RC2-PWM1, RC1-PWM2) | |
CCP1CON = 0x0F; // Select the PWM mode. | |
PR2 = 100; // Set the Cycle time to 100 for varying the duty cycle from 0-100 | |
CCPR1L = 50; // By default set the dutyCycle to 50 | |
TMR2ON = 1; //Start the Timer for PWM generation | |
while (1) { | |
for (dutyCycle = 0; dutyCycle < 100; dutyCycle++) // Keep increasing the dutyCyle to increase the brightness of LED | |
{ | |
CCPR1L = dutyCycle; | |
delay(10000); | |
} | |
for (dutyCycle = 100; dutyCycle > 0; dutyCycle--) // Keep reducing the dutyCyle to decrease the brightness of LED | |
{ | |
CCPR1L = dutyCycle; | |
delay(10000); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment