|
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define zk1 PWMDTY0 //左电机前进
#define zk2 PWMDTY1 //左电机后退
#define zk3 PWMDTY2 //右电机前进
#define zk4 PWMDTY3 //右电机后退
void MotorPWM0_Init(void)
{
PWME_PWME0=0;
//PWMCTL=0x00; 不级联
PWMCAE_CAE0=0; //0通道左对齐
PWMCNT0= 0; //初始计数值为0
PWMPOL_PPOL0=1; //0通道高电平
PWMPRCLK=0x03; //A时钟8分频,0,1,4,5 A时钟
PWMSCLA=5; //一般10K,=5 , PWMSCLA=30;
PWMCLK_PCLK0= 1;//0通道SA时钟
PWMPER0=100; //0周期寄存器100
PWME_PWME0=1; //打开0通道
}
void MotorPWM1_Init(void)
{
PWME_PWME1=0;
PWMCAE_CAE1=0;
PWMCNT1= 0;
PWMPOL_PPOL1=1;
PWMPRCLK=0x03;
PWMSCLA=5; //PWMSCLA=30;
PWMCLK_PCLK1= 1;
PWMPER1=100;
PWME_PWME1=1;
}
void main(void)
{
zk1=30;
zk2=0; //正转
delay(100);
zk1=0;
zk2=30; //反转
}
希望对你有所帮助 |
|