📄 main.c
字号:
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
//16-bit PWM,use 2MHz~0.5us
//Bus clock:24MHz; Prescale:12;
//Output : Channels 1
void PMW_Initial(void)
{
PWME = PWME & 0xFC;
PWMPOL = PWMPOL | 0x02; // Polarity:High
PWMCTL = PWMCTL | 0x10; //0 。1联级,16_bit PWM
PWMCLK = PWMCLK | 0x02; //PTP1 use SA
PWMPRCLK = 0; //Clock A=Bus Clock
PWMSCLA = 0x06; //SA = Bus/(2*PWMSCLA),SA = 24M/12=2M
PWMPER0 = 0x9c; //40000,20ms
PWMPER1 = 0x40;
PWMDTY0 = 0x4e; //20000 10ms duty
PWMDTY1 = 0x20;
PWME = PWME | 0x02; //start
/* duty 为2816时,舵机处于中间*/
}
void PLL_Init(void)
{
REFDV=0x01;
SYNR=0x02; //Set the system clock 48MHz
}
void Start_PLL(void) {
asm{
BRCLR CRGFLG,#$08,*
BSET CLKSEL,#$80
}
}
void main(void) {
/* put your own code here */
PLL_Init();
Start_PLL();
PMW_Initial(); //Period:20ms;Duty:1.5ms;
EnableInterrupts;
for(;;) {} /* wait forever */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -