You are on page 1of 2

Pulse Width Modulation Using CCP Module of PIC877A Microcontroller

Write a program to produce a waveform of 50% duty cycle.

Code:

#include <16f877A.h>
#fuses XT,NOWDT
#use delay(clock=4000000)

#byte portc=0x7
#byte portd=0x8
#byte TRISC=0x87
#byte TRISD=0x88
#byte TMR2=0x11
#byte PR2=0x92
#byte T2CON=0x12
#byte CCPR1L=0x15
#byte CCPR1H=0x16
#byte CCP1CON=0x17
#byte status=0x3
#bit RP0=0x03.5
#bit CCP1X=0x17.5
#bit CCP1Y=0x17.4
void main()
{
RP0=1;
PR2=249;
RP0=0;
CCPR1L=0b01111101;
CCP1X=0;
CCP1Y=0;
RP0=1;
TRISC=TRISC & 0b11111011;
RP0=0;
CCP1CON=CCP1CON & 0b00110000;
CCP1CON=CCP1CON | 0b00001111;
T2CON=0b00000101;
}