Cortex-M3 (NXP LPC1788)之PWM
时间:11-19
来源:互联网
点击:
- R&(0x1<1))
- {
- rFIO1PIN&=~(1<18);
- rPWM0IR|=0x1<1;//MR1中断复位
- }
- }
- voidSystemInit()
- {
- rSCS&=~(0x1<4);//频率12M
- rSCS|=(0x1<5);//使能主振荡器
- while(0==(rSCS&(0x1<6)));//等待主振荡器稳定
- rCLKSRCSEL=0x1;
- rPLL0CFG=0x9;//配置CCLK=120M
- rPLL0CON=0x01;
- rPLL0FEED=0xAA;
- rPLL0FEED=0x55;
- while(0==(rPLL0STAT&(0x1<10)));
- rCCLKSEL=(0x1|(0x1<8));
- rPCLKSEL=0x2;//配置PCLK=60M
- rCLKOUTCFG=0x0|(0xb<4)|(0x1<8);
- }
- voidPWMInit()
- {
- rIOCON_P1_02&=~0x7;
- rIOCON_P1_02|=0x3;//P1.02配置成PWM0[1]
- rPCONP|=0x1<5;//使能PWM0外设
- rPWM0IR=0x73F;//初始化PWM相关控制寄存器
- rPWM0TCR=0;
- rPWM0CTCR=0;
- rPWM0MCR=0;
- rPWM0CCR=0;
- rPWM0PCR=0;
- rPWM0LER=0;
- rPWM0PR=0x1<20;//每0x1<20+1个PLCK上升沿,TC递增
- rPWM0TCR|=0x1<1;//复位TC和PC
- rPWM0TCR&=~(0x1<1);
- rPWM0MR0=100;
- rPWM0LER|=0x1;
- rPWM0MCR|=0x1<1|0x1;//MR0和TC匹配时复位TC和PC.并且产生中断
- rPWM0MR1=duty;
- rPWM0LER|=0x1<1;
- rPWM0MCR|=0x1<3;//MR1和TC匹配时产生中断
- }
- intmain()
- {
- PWMInit();
- rFIO1DIR|=(0x1<18);
- rISER1|=0x1<7;//PWM0中断使能
- rPWM0TCR|=0x1<1;//复位TC和PC
- rPWM0TCR&=~(0x1<1);
- rPWM0TCR|=0x1;//PC和TC计数使能
- rPWM0TCR|=0x1<3;//PWM模式使能
- while(1)
- {
- if(match_cnt>=1)
- {
- match_cnt=0;
- duty=duty+10;
- if(duty>=100)
- {
- duty=0;
- }
- rPWM0MR1=duty;
- rPWM0LER|=0x1<1;
- rPWM0MCR|=0x1<3;
- }
- }
- return1;
- }
LPC1788的PWM可以进行双边沿的控制。如PWM0.2可以用MR0控制PWM的周期频率,用MR1和MR2控制PWM0.2的边沿。
Cortex-M3NXPLPC1788PW 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)