The program I wrote to control the step motor

Hello~all. Thanks for spending time to read my post at first.
I have writen a program about using msp430f149 ( this one:
http://www.kynix.com/Detail/951641/MSP430F149.html ) to control the step motor.I would like to show them here.
This is the program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <msp430x14x.h>   
typedef    unsigned int  uint;  
typedef   unsigned char uchar;   
#define   PWM   BIT2   
void int_clk()   
{   
    uchar i;   
    BCSCTL1&=~XT2OFF;  //打开XT振荡器   
    BCSCTL2|=SELM1+SELS;//MCLK 8M and SMCLK 1M     
    do   
    {   
        IFG1 &= ~OFIFG;                 //清除振荡错误标志    
        for(i = 0; i < 100; i++)   
      _NOP();           //延时等待   
        }   
    while ((IFG1 & OFIFG) != 0);    //如果标志为1继续循环等待   
    IFG1&=~OFIFG;   
}   
void int_pwm()   
{    
  P1SEL|=PWM;//选择P12作为PWM输出   
  P1DIR|=PWM;     
  TACCR0=800;//PWM信号周期10KHz   
  TACCR1=400;//占空比1:1   
  TACCTL1=OUTMOD0+OUTMOD1+OUTMOD2; //输出模式选择   
  TACTL|=TASSEL1+MC0;    
}   
void main()   
{   
  WDTCTL=WDTPW+WDTHOLD;//关看门狗   
  int_clk();  //初始化时钟   
  int_pwm();  //初始化PWM   
  while(1);//结束    

The program is base on controlling the return of step motor by using msp4300f149.The outputted port of PWM is P1.2 while the signal cycle is 10KHZ. The duty cycle is 1:1.
Do you have any suggestions about my program? Welcome to discuss it with me.
Last edited on
Topic archived. No new replies allowed.