📄 main.c
字号:
#include <hidef.h> /* common defines and macros */
#include <mc9s12dp256.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dp256b"
unsigned char periodhigh;
unsigned char periodlow;
unsigned char dutyhigh;
unsigned char dutylow;
void PWM(unsigned char periodhigh,unsigned char periodlow,unsigned char dutyhigh,unsigned char dutylow)
{
PWME=0xFF; /* PWM使能 */
PWMPOL=0xFF; /* 设置每路PWM的初始极性为1 */
PWMCLK=0; /* 选择PWM的时钟为clock A和clock B */
PWMPRCLK=0x66; /* 设置时钟为125kbps */
PWMCAE=0xFF; /* 设置输出方式为Center Aligned Outputs */
//PWMCTL=0x00; /* 分8路输出*/
PWMCTL=0x10; /*PWM6,PWM7合并输出*/
PWMPER0=periodhigh; /* 设置period=FA,周期为4ms,周期=(2/时钟频率)* PWMPER0 */
PWMPER1=periodlow;
PWMDTY0=dutyhigh;
PWMDTY1=dutylow; /* 设置duty=7D,占空比为50%,占空比=[PWMPER0/ PWMDTY0]*100%。 */
}
void main(void)
{
/* put your own code here */
periodhigh=0x7d;
periodlow=0xff;
dutyhigh=0;
dutylow=0x7d;
PWM(periodhigh,periodlow,dutyhigh,dutylow);
EnableInterrupts;
for(;;) {} /* wait forever */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -