急求msp430f149单片机产生pwm波控制2个电机转动的C程序

来源:百度知道 编辑:UC知道 时间:2024/09/22 16:06:31
采用L298驱动两个直流电机(玩具模型小车内自带电机)

哈哈,你还真找对人了。看看下面的...
//pwm_timer_b.h
#ifndef __PWM_TIMER_B
#define __PWM_TIMER_B

void TimerBInit();
void SetScale(unsigned int sc);
void SetFre(unsigned int fre);
unsigned char GoPwm(unsigned char doit);

#endif

/*******************************************************************************
文件名:pwm_timer_b.c
编写者:czhang
描述:使用定时器B进行PWM输出。输出的频率和占空比由串行口发送来的指令确定。
版本: 1.0 2005-2-20
*******************************************************************************/
#include <MSP430x14x.h>
#include "pwm_timer_b.h"

#define PWM_DIR P4DIR
#define PWM_SEL P4SEL
#define PWM_OUT P4OUT
#define PWM_IN P4IN

#define PWM_IO BIT1

unsigned int iFre; //频率
unsigned int iScale; //占空比

/*****************************************************************************
初始化定时器B
********************************