//
// PWM Example
// By PEK '2005
//
// MCU: 16F877
// Clock: 10 MHz
//
// To be used with the CCS compiler
//
// This program is using the CCP1 output pin and sends pulses with a frequency
// of 10 kHz and a duty of 50%.
//
// Time of period: T = 1/f*4*t2div*(value + 1)
// High pulse time: t_duty = 1/f*t2div*value
//

#include <16F877.h>
#use delay(clock=10000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP

void main()
{
   setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
   setup_timer_2(T2_DIV_BY_1, 249, 1);  // 1/10000000*4*1*250 = 100us => 10 kHz
   set_pwm1_duty(500);  // 1/10000000*1*500 = 50us => 50%

   while(1);
}

