#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;
while(1)
{
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++;
}
EnableInterrupts;
for(;;) {} /* wait forever */
/* please make sure that you never leave this function */
}