pic16f1937 標(biāo)準(zhǔn)PWM
以下為示例程序:
本文引用地址:http://butianyuan.cn/article/201611/315602.htm#include
#define uint8 unsigned char
#define uint16 unsigned int
__CONFIG(FOSC_INTOSC&WDTE_OFF&PWRTE_OFF&MCLRE_ON&CP_OFF
&BOREN_OFF&CLKOUTEN_OFF&IESO_OFF&FCMEN_OFF);
__CONFIG(WRT_OFF&VCAPEN_OFF&PLLEN_OFF&STVREN_OFF&BORV_19&LVP_OFF);
#define BACK_LED RC1
void delay(uint16 us)
{
while(us--);
}
void interrupt isr()
{
if((TMR2IE==1)&&(TMR2IF==1))
{
TMR2IF=0;
}
}
void Init_PWM1_2(void)//CCP4和CCP1
{
TRISD1=1; //CCP4禁驅(qū)動(dòng)
PR2=0X65;
CCP4CON=0X0C; //CCP4標(biāo)準(zhǔn)PWM輸出
CCPR4L=0X15; //CCP4的占空
CCPTMRS0=0X00; //CCP1&4都用TIME2
//PR4=0X65;
//CCP
CCP1CON=0X0C; //CCP1標(biāo)準(zhǔn)PWM輸出
CCPR1L=0X32; //CCP1的占空
TRISC2=0; //使能CCP驅(qū)動(dòng)引腳
TRISD1=0;
//TMR2IE=1;
//TMR2IF=0;
//PEIE=1;
T2CON=0X05; //預(yù)分頻4
//GIE=0;
}
void main()
{
OSCCON=0X70; //8MHZ
delay(50000);
TRISC1=0;
BACK_LED=1;
Init_PWM1_2();
while(1);
}
評(píng)論