I have setup PWM on a pic18F2550 and here is some code for a pic16F877A (I don't remember if I tested the PIC16 code):
// PWM token...
// buffer[2] == Prescalar (0 = Turn Off PWM Mode)
// buffer[3] == PR2
// buffer[4] == CCPR1L (Duty Cycle)
case FT_PWM:
T2CON=buffer[2]; // Timer2 Control Reg
if (buffer[2]==0) {
CCP1CON=0; // PWM Off
TRISCbits.TRISC2=1; // Pin as Input
} else {
PR2=buffer[3]; // PWM Period
CCPR1L=buffer[4]; // Duty Cycle MSBs
CCP1CON=0x0c; // PWM On & Duty Cycle LSBs
TRISCbits.TRISC2=0; // Pin as Output
}
break;
I noticed in your code your TRIS direction code is wrong.
You are mixing PortB and PortC.
TRISC.B2 = 0; // make port pin on C as output
Should be:
TRISCbits.TRISC2=0; // Pin as Output