Questions
Newbie level 3
Helps on P18f2520(PWM)
Hi all. I am new here.I would like to ask why my PWM program does not work. FYI, i am using MPLAB, ICD2 complier and crystal oscillator is 8Mhz. Here my code:
#include<p18f2520.h>
#include<delays.h>
void main(){
TRISC=0b11011111; // RC5 as output
T2CON=0b00000111; //prescaler=16
CCP1CON=0b00011100;
while(1){
PR2=0b01111100; //1Khz
CCPR1L=0b00111110;
Delay100TCYx(200);
Delay100TCYx(200);
Delay100TCYx(200);
PR2=0b00011000; //5Khz
CCPR1L=0b00001100;
Delay100TCYx(200);
Delay100TCYx(200);
Delay100TCYx(200);
}
}
I hope some kind souls can help me with this code.Tell me what goes wrong and where is the problem.
Thanks in advance.--- God bless you.
Hi all. I am new here.I would like to ask why my PWM program does not work. FYI, i am using MPLAB, ICD2 complier and crystal oscillator is 8Mhz. Here my code:
#include<p18f2520.h>
#include<delays.h>
void main(){
TRISC=0b11011111; // RC5 as output
T2CON=0b00000111; //prescaler=16
CCP1CON=0b00011100;
while(1){
PR2=0b01111100; //1Khz
CCPR1L=0b00111110;
Delay100TCYx(200);
Delay100TCYx(200);
Delay100TCYx(200);
PR2=0b00011000; //5Khz
CCPR1L=0b00001100;
Delay100TCYx(200);
Delay100TCYx(200);
Delay100TCYx(200);
}
}
I hope some kind souls can help me with this code.Tell me what goes wrong and where is the problem.
Thanks in advance.--- God bless you.