⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwm,crg.txt

📁 飞思卡儿智能汽车竞赛主程序 包含刹车程序和pmw模块程序
💻 TXT
字号:
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

#include "main_asm.h" /* interface to the assembly module */

void crg_init(void);
void pwm_init(void);
void main(void) {

  
crg_init();
pwm_init();
while(1){
}
}
  void crg_init(void){
         SYNR=0x02;                      // mcu core clock 48MHz(bus clock 24MHz).
         REFDV=0x01;
         while((CRGFLG & 0x08)==0 ){  }  // wait for PLL clock stabilization
         CLKSEL |=0x80;                  // select PLL clock.
    }

/*------------------------------------PWM_INIT-----------------------------------------

    the function pwm_init() is used for preparing for the two motors work.   
    see port.h for details of pins connection.
 -------------------------------------------------------------------------------------*/
 
  void pwm_init(void) 
    { 
         PWMCTL=0x40;      // select PWM(4)5,PWM7 channel.                  
         DDRP=0xFF;        // for PTP1,PTP2,PTP3 output enable.
         PTP=0x04;         // for PTP1(IN1)=0,PTP2(D2)=1,PTP3(D1)=0.
         PWMPRCLK=0x33;    // A_CLK(busclk/8).B_CLK(busclk/8)
         PWMSCLB=0x26;
         PWMSCLA=0x26;
         PWMPOL=0xA2;      // PWM45 select A_CLK,PWM7 select SB_CLK.
         PWMCLK=0x80;
         PWMCNT4=0x00;
         PWMCNT5=0x00;
         PWMCNT7=0x00;
         PWMCNT1=0x00;   
         PWMPER45=0x7530;  // init_period(20ms)
         PWMPER7=0xC3;
         PWMPER1=0x4E;
         PWMCAE=0x7D;
         PWMDTY7=0x01;
         PWMDTY1=0x01;
         PWMDTY45=2070;    // init_pulse(us)         
         PWME=0xA2;        // for PWM7,PWM(4)5 output enable.
    }
      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -