#include
__CONFIG(1,XT) ; //晶振为外部4M
__CONFIG(2,WDTDIS) ; //看门狗封闭
__CONFIG(4,LVPDIS) ; //制止低电压编程
#define uchar unsigned char
#define uint unsigned int
uint k=0;
uchar temp=0;
void main(void)
{
ADCON1=0X06; //一切IO均为数字口,模拟量输入制止
RC2=0;
CCP1CON=0x3c; //作业在PWM形式,为了便利核算,占空比的两位都为1
CCPR1L=0; //调理初始占空比
PR2=99; //调理PWM周期
TMR2ON=1; //PWM模块要用到定时器中止2
T2CKPS1=0;
T2CKPS0=0;
while(1)
{
if(k++>400)
{
k=0;
if(temp==0)
CCPR1L++;
if(temp==1)
CCPR1L–;
if(CCPR1L>=0xFF)
temp=1;
if(CCPR1L<=0x01)
temp=0;
}
}
}