main.c

来自「freescale 9s12dp256单片机pwm原代码」· C语言 代码 · 共 42 行

C
42
字号
#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 + =
减小字号Ctrl + -
显示快捷键?