//------------------------------------------------------------------------------
#define SetBit(VAR,Place) ( VAR |= (1<< Place) )
#define ClrBit(VAR,Place) ( VAR &= ((1<< Place)^0xffffFFFF) )
#define ChgBit(VAR,Place) ( VAR ^= (1<< Place) ) //取反
#define AffBit(VAR,Place,Value) ((Value) ? \
(VAR |= (1<< Place)) : \
(VAR &= ((1<< Place)^0xffffFFFF)))
#define MskBit(Dest,Msk,Src) ( Dest = (Msk & Src) | ((~Msk) & Dest) )
#define ValBit(VAR,Place) ((VAR>> Place) & 1 )
#define ClrBits(Var,Lstart,n) {unsigned char i=n,Place=Lstart;while(i--){ClrBit(Var,Place); Place++;}}
#define LoadBits(Var,Lstart,n,val) {unsigned long j=((unsigned long)1<<n)-1;j&=val;j<<=Lstart;ClrBits(Var,Lstart,n);Var|=j;}
#define GetBits(Var,Lstart,n) ( (Var>>Lstart)& (((unsigned long)1<<n)-1) )
//----------------------------------------------------------------------------------------------------------------------------
void PwmInit( void )
{
LoadBits( CLK->APBCLK, 20, 3, 7); // pwm clock
LoadBits( CLK->CLKSEL1,28, 2, 2 ); // pwm 01
LoadBits( CLK->CLKSEL1,30, 2, 2 ); // pwm 23
LoadBits( CLK->CLKSEL2, 4, 2, 2 ); // pwm 45
//--------io--------------------------------------------
LoadBits( GCR-> P2_MFP,12 ,3, 7 ); // 2.4, 2.5, 2.6
LoadBits( GCR-> P2_MFP,4 ,3, 0 ); // 0
LoadBits( GCR-> P0_MFP,12 ,1, 1 ); // 0.4
LoadBits( GCR-> P0_MFP,4 ,1, 1 ); // 0
PWM-> POE =0x3C; // EN OUT 2 3 4 5
//-------------------------------------------------------
PWM->CSR = 0x333333; // 时钟选择寄存器(CSR) /16
PWM-> PPR = 91 |((u32)91<<8)|((u32)91<<16); //15K
PWM->CNR2 = 10;
PWM->CMR2 = 8;
PWM->CNR3 = 10;
PWM->CMR3 = 8;
PWM->CNR4 = 10;
PWM->CMR4 = 8;
PWM->CNR5 = 10;
PWM->CMR5 = 8;
PWM-> PCR = 0x888888;
PWM-> PCR |=0x111111;
}
想得到 四路PWM 输出,PWM2 PWM3 PWM4 PWM5 ,但现在引脚上没有反应,一直是高电平。 请高手看看,哪儿没有设置好?
// 以上的 位操作: 置位,复位,置多个位等 ,是OK的 没有问题,问题 可能是还有哪个寄存器没有设置。
|
|