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

📄 main.c

📁 全国飞思卡尔智能车大赛中
💻 C
字号:
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"


void pwminitial()
{
  PWMPOL=0X01;		//通道0输出波形开始极性为1  output waveform which high first then low when the duty counter is reached
  PWMCAE=0x00;    //左对齐输出模式            output left align waveform
  PWMCLK=0X01;    //PWM时钟源为               SAClock SA is the clock source for PWM channel 0
  PWMPRCLK=0X03;  //时钟A8分频                Clock A is 8MHz/8=1MHz
  PWMSCLA=0X80;   //时钟SA为1MHz/128/2        Clock SA is 1MHz/128/2=4KHz
  
  PWMPER0=255;    //设定输出周期=通道时钟周期*256
  PWMDTY0=0;		  //占空比初始为0             Duty is 50%,and PWM waveform's frequent is 16  
  PWME=0X01;			//通道0使能                 enable pwm channel 0

}

void main()
{
  pwminitial();
  DDRB=0XFF;		

{
  int i;
  
  
  for(i=0;i<30000;i++)
	{if(PTP_PTP0==0)      //PTP0口作为输出引脚
			PORTB=0X00;
		else
			PORTB=0XFF;
	_asm "nop";
	_asm "nop";
	_asm "nop";
	} 							 

	  PWMDTY0++;
} 



  for(;;) {} /* wait forever */
  /* please make sure that you never leave this function */
}

⌨️ 快捷键说明

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