版主能详细说一下吗?我的程序如下,好像没用到中断啊? #include <hidef.h> /* common defines and macros */ #include <mc9s12dg128.h> /* derivative information */ #include "PLL.h" #pragma LINK_INFO DERIVATIVE "mc9s12dg128b" void PWM_Init(void); void main(void) { unsigned int i; unsigned long j=10000; /* put your own code here */ DisableInterrupts; PLL_Init(); Start_PLL(); PWM_Init(); //PWME=0xff; //运行PWM所有通道输出 PWMDTY5=50; //占空比为30% PWME=0X0; //使能PWM PWME=0X20; for (i=0;i<10;i++) { PWME=0X20; //使能PWM //PWMCNT5 } //for(i=0;i<0x64;i++) //{ ////while (j--); ////j=1000; ////while(j--); ////j=10000; //PWMDTY5=i; //PWMDTYx:PWM占空比寄存器 设置占空比 //PWME=0X20; //使能PWM //} /* wait forever */ /* please make sure that you never leave this function */ } // 使用PWM5进行控制 void PWM_Init(void) { PWME=0x00; //Close PWM PWMPOL =0X20; //PWMPOL;PWM极性寄存器 0X20 先输出高电平,占空比计数器计数完毕后变为低电平 PWMCLK =0X20; // PWMCLK:PWM时钟选择寄存器 0X20使用SA时钟 PWMPRCLK=0X07; //PWMPRCLK:PWM预分频时钟选择寄存器 时钟A为总线128分频 PWMCAE=0X00; //PWMCAE:PWM剧中对齐允许寄存器 左对齐输出模式 PWMCTL=0X00; //PWMCTL:PWM控制寄存器 非级联方式 单独使用通道5 PWMSCLA=0X05; //PWMSCLA:PWM比例因子寄存器A CLOCKSA=CLOCKA/(2*PWMSCLA)为3kHz PWMPER5=0x64; // PWMPERx:PWM通道周期寄存器 设定周期
//PWMSCLA = 60; //PWMPRCLK_PCKB=3; // Clock B= Bus Clock/8 //PWMCTL |=PWMCTL_CON23_MASK; // PWMPER0 = 100; //0.5ms // PWMPER1 = 100; // PWMDTY0=25; // PWMDTY1=30; // PWMPER23=60000; // PWMDTY23=4500; } |