void InitMain() {
PORTB = 0; // set PORTB to 0
TRISB = 0xF0; // designate PORTB pins as output
PORTC = 0; // set PORTC to 0
TRISC = 0xFF; // designate PORTC pins as output
Pwm1_Init(5000); // Initialize PWM1 module at 5KHz
PWM2_Init(5000); // Initialize PWM2 module at 5KHz
}
void main(){
InitMain();
PWM2_start();
while (1) { // endless loop
// 100% duty cycle: duty ratio can be calculated as (Percent*255)/100.
PWM2_Set_Duty(255); // Change the duty cycle
delay_ms(3000); //3 seconds delay
// 80% duty cycle
PWM2_Set_Duty(204); // Change the duty cycle
delay_ms(3000); //3 seconds delay
// 50% duty cycle
PWM2_Set_Duty(127); // Change the duty cycle
delay_ms(3000); //3 seconds delay
// 30% duty cycle
PWM2_Set_Duty(76); // Change the duty cycle
delay_ms(3000); //3 seconds delay
// 10% duty cycle
PWM2_Set_Duty(25); // Change the duty cycle
delay_ms(3000); //3 seconds delay
}
}