Helps on P18f2520(PWM)

Status
Not open for further replies.

Questions

New Member
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.
 
So what does it do? If the answer is nothing then try flashing an LED on a different pin to make sure the code is running.

Mike.
 
The buzzer does not give off sound of different frequencies. Thank dude.I never thought of running PWM on LED.

Assuming PORTBbits.RB5 is an LED. what i need is to add the followings:

TRISB=0xff;
.
..
...
PORTBbits.RB5=CCPR1L;
...
..
.


Greatly appreciated.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…