波占空比,通过滤波,输出直流模拟量。
//
CMOD=0x02;//Setup PCA timer
CL=0x00;
CH=0x00;
CCAP0L=p_on;//Set the initial value same as CCAP0H
CCAPM0=0x42;//0100,0010 Setup PCA module 0 in PWM mode
CCAP1L=p_on;//Set the initial value same as CCAP0H
CCAP1H=p_on;//25% Duty Cycle
//CCAPMn.1
CCAPM1=0x42;//0100,0010 Setup PCA module 0 in PWM mode
CCAP2L=p_on;//Set the initial value same as CCAP0H
CCAP2H=p_on;//25% Duty Cycle
//CCAPMn.1
CCAPM2=0x42;//0100,0010 Setup PCA module 0 in PWM mode
CCAP3L=p_on;//Set the initial value same as CCAP0H
CCAP3H=p_on;//25% Duty Cycle
//CCAPMn.1
CCAPM3=0x42;//0100,0010 Setup PCA module 0 in PWM mode
int i;
for(i=0;i<a;i++);
unsigned char i=0;
init_pwm();
CR=1;//Start PCA Timer
while(1)
{
while(++i)
{
pulse_0(i+50);
pulse_1(i+100);
pulse_2(i+150);
pulse_3(i+200);
delay(1000);
}
while(--i)
{
pulse_0(i+50);
pulse_1(i+100);
pulse_2(i+150);
pulse_3(i+200);
delay(1000);
}
}