金牌会员
 
- 积分
- 1473

- 威望
- 745
- 贡献
- 386
- 兑换币
- 189
- 注册时间
- 2011-11-18
- 在线时间
- 171 小时
|
为什么写的这程序下载后,PWM口出不了出不了波形呢?
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
void delayms(int ms)
{
int ii,jj;
if (ms<1) ms=1;
for(ii=0;ii<ms;ii++)
for(jj=0;jj<3338;jj++); //40MHz--1ms
}
void SetBusCLK_40M(void)
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR =0xc0 | 0x04;
REFDV=0x80 | 0x01;
POSTDIV=0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=80MHz;
_asm(nop); //BUS CLOCK=40M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void SetBusCLK_48M(void)
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR =0xc0 | 0x05;
REFDV=0x80 | 0x01;
POSTDIV=0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=96MHz;
_asm(nop); //BUS CLOCK=48M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void PWM_init(void) //脉宽调制模块的初始化
{
//SB,B for ch2367
//SA,A for ch0145
PWME_PWME0=0X00;
PWMPRCLK=0X44; // 0100 0100 A=B=48M/16= 3M
PWMSCLA=150;
PWMSCLB=150; // SB=B/2/150=10K
PWMCLK_PCLK0=1; // PWM3---SB
PWMPOL_PPOL0=1; // duty = high time
PWMCAE_CAE0=0; // left-aligned
PWMCTL=0X00;
PWMPER0=100; // frequency = SB/100 = 100Hz 100ms
PWMDTY0=16; // duty cycle =
PWME_PWME0=1;
}
void main(void) {
/* put your own code here */
unsigned char LedCnt=0;
SetBusCLK_48M(); // 设定总线频率
DDRB=0xff;
DDRA=0x01;
PORTA=0XFE;
PORTB=0XFE;
PWM_init();
EnableInterrupts;
for(;;) {
LedCnt=(LedCnt>0XFE?0:++LedCnt);
delayms(500); // 修改延时以修改数据发送频率
//低电平灯亮用这句,注释掉下面那句
PORTB=~LedCnt; // 测试清华版系统板
PORTA_PA0=~PORTA_PA0; // 测试龙丘最小系统板
//PORTB_BIT7=~PORTB_BIT7;
//高电平灯亮用这句,注释掉上面那句
//PORTB=LedCnt;
} /* wait forever */
/* please make sure that you never leave this function */
}
|
|