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;
while(1)
{
int i;