pic16f1937 标准PWM
以下为示例程序:
#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禁驱动
PR2=0X65;
CCP4CON=0X0C; //CCP4标准PWM输出
CCPR4L=0X15; //CCP4的占空
CCPTMRS0=0X00; //CCP1&4都用TIME2
//PR4=0X65;
//CCP
CCP1CON=0X0C; //CCP1标准PWM输出
CCPR1L=0X32; //CCP1的占空
TRISC2=0; //使能CCP驱动引脚
TRISD1=0;
//TMR2IE=1;
//TMR2IF=0;
//PEIE=1;
T2CON=0X05; //预分频4
//GIE=0;
}
void main()
{
OSCCON=0X70; //8MHZ
delay(50000);
TRISC1=0;
BACK_LED=1;
Init_PWM1_2();
while(1);
}
pic16f1937标准PW 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)