#include<htc.h>
void setpwm(unsigned int dutycycle);
void intpwm();
void intpwm()
{
TRISC=0x00;
PORTC=0x00;
CCP1CON=0x0C;
PR2=0xff;
T2CON=0X03;
setpwm(0);
T2CON |= 0X04;
}
void setpwm(unsigned int dutycycle)
{
CCPR1L=dutycycle>>2;
CCP1CON=0XCF;
CCP1CON |=(0X30&(dutycycle<<4));
T2CON =0x03;
//T2CON |= (1<<2)|(1<<1);
}
void main()
{
int i;
TRISC=0x00;
intpwm();
PORTC=0x00;
setpwm(0);
while(1)
{
setpwm(512);
for(i=0;i<200;i++);
}
}
void setpwm(unsigned int dutycycle);
void intpwm();
void intpwm()
{
TRISC=0x00;
PORTC=0x00;
CCP1CON=0x0C;
PR2=0xff;
T2CON=0X03;
setpwm(0);
T2CON |= 0X04;
}
void setpwm(unsigned int dutycycle)
{
CCPR1L=dutycycle>>2;
CCP1CON=0XCF;
CCP1CON |=(0X30&(dutycycle<<4));
T2CON =0x03;
//T2CON |= (1<<2)|(1<<1);
}
void main()
{
int i;
TRISC=0x00;
intpwm();
PORTC=0x00;
setpwm(0);
while(1)
{
setpwm(512);
for(i=0;i<200;i++);
}
}
No comments:
Post a Comment