新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > pic16f1937 標(biāo)準(zhǔn)PWM

pic16f1937 標(biāo)準(zhǔn)PWM

作者: 時(shí)間:2016-11-18 來(lái)源:網(wǎng)絡(luò) 收藏
用PIC16F1937的CCP1,CCP4產(chǎn)生兩路PWM,時(shí)鐘源由TIME2提供

以下為示例程序:

本文引用地址: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)論


技術(shù)專區(qū)

關(guān)閉