標(biāo)題:
MSP430F6638步進(jìn)電機(jī)正反轉(zhuǎn)程序
[打印本頁]
作者:
51黑er
時間:
2015-11-1 21:34
標(biāo)題:
MSP430F6638步進(jìn)電機(jī)正反轉(zhuǎn)程序
#include "MSP430F6638.h"
unsigned char stp[]={0x09,0x05,0x06,0x0a};//1000 0001;0100 0001;0100 0010
unsigned char stpb[]={0x81,0x41,0x42,0x82};//1000 0010
void delay(unsigned int ms)
{
unsigned int n;
while(ms--)
for(n=0;n<100;n++);
}
int main( void )
{
unsigned char k,j;
unsigned int i,m;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR |=BIT7+BIT6+BIT1+BIT0;
P4DIR |=BIT3+BIT2+BIT1;
P2DIR |=BIT3+BIT2;
while(1)
{
//////////////////////
for(m=0;m<60;m++)//順時針轉(zhuǎn)
{
P2OUT |=BIT2;
P2OUT &=~BIT3;
for(k=0;k<10;k++)
{
for(j=4;j>0;j--)
{
P1OUT=stpb[j-1];
delay(5);
}
}
}
//////////////////////
for(m=0;m<60;m++)//逆時針轉(zhuǎn)
{
P2OUT |=BIT2;
P2OUT &=~BIT3;
for(k=0;k<10;k++)
{
for(j=0;j<4;j++)
{
P1OUT=stpb[j];
delay(5);
}
}
}
//////////////////////
for(i=0;i<500;i++)//逆時針
{
P2OUT |=BIT3;
P2OUT &=~BIT2;
P1OUT |=BIT6;
P1OUT &=~BIT7;
}
//////////////////////
for(i=0;i<1500;i++)//順時針
{
P2OUT |=BIT3;
P2OUT &=~BIT2;
P1OUT |=BIT7;
P1OUT &=~BIT6;
}
/////////////////////////
}
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1