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

📄 pwm.txt

📁 自己写的一个PWM的程序,给初学的人看看吧,也许会有些用,关于电机控制的
💻 TXT
字号:
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

/*
*********************************************************
*pwm初始化函数 by demon 2007-5-12
*********************************************************/
void pwm_initial()//pwm初始化函数
{ 
PWME=0x22;//通道01,45使能  
PWMPOL=0x22;//通道01,45输出波形开始极性为1 
PWMCTL=0x50;//通道01,45级联   
PWMCLK=0x02;//通道01选择SA为时钟源   
PWMSCLA=0X04;//通道01时钟SA为3MHz(24/(2*4))
PWMPER01=60000;//设定通道01输出频率(50Hz)
PWMPER45=12000;//设定通道45输出频率(2KHz)
}


/*
*********************************************************
*pwm输出函数 by demon 2007-5-12
*程序描述;由输入参数向舵机和电机输出相应pwm
*参数:舵机方向:3300-5700 速度:0-12000
*********************************************************/
void pwm(int speed,int direction)//pwm
{
pwm_initial();
if(direction<3300) direction=3300;  
if(direction>5700) direction=5700;  
PWMDTY01=direction;
if(speed>12000) speed=12000;
PWMDTY45=speed; 
} 

⌨️ 快捷键说明

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