static unsigned char FFW[] =
{
0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x09
};
static unsigned char REV[] =
{
0x09, 0x08, 0x0c, 0x04, 0x06, 0x02, 0x03, 0x01
};
void SETP_MOTOR_FFW( unsigned char n )//正转n圈
{
unsigned char i, j;
for ( i = 0; i < 5 * n; i++ )
{
for ( j = 0; j < 8; j++ )
{
PORTD = FFW[j];
__delay_ms( 25 );
}
}
}
void SETP_MOTOR_REV( unsigned char n )//反转n圈
{
unsigned char i, j;
for ( i = 0; i < 5 * n; i++ )
{
for ( j = 0; j < 8; j++ )
{
PORTD = REV[j];
__delay_ms( 25 );
}
}
}
使用例子:
TRISD=0X00;
SETP_MOTOR_FFW( 3 );