char RotSense, PulseNum;
char pos=0;
char FullStepForward [4]={0x03, 0x09, 0x0C, 0x06};
char FullStepBackward[4]={0x06, 0x0C, 0x09, 0x03};
char HalfStepForward [8]={0x03, 0x01, 0x09, 0x08, 0x0C, 0x04, 0x06, 0x02};
char HalfStepBackward[8]={0x06, 0x04, 0x0C, 0x08, 0x09, 0x01, 0x03, 0x02};
void FullStepMotorCW()
{
TRISD=FullStepForward[pos];
delay_ms(50);
pos=(pos+1)%4;
}
void FullStepMotorCCW()
{
TRISD=FullStepBackward[pos];
delay_ms(1000);
pos=(pos+1)%4;
}
void HalfStepMotorCW()
{
TRISD=HalfStepForward[pos];
delay_ms(1000);
pos=(pos+1)%8;
}
void HalfStepMotorCCW()
{
TRISD=HalfStepBackward[pos];
delay_ms(1000);
pos=(pos+1)%8;
}
void Initial()
{
TRISD=0x00;
}
void main() {
char i;
Initial();
do {
PulseNum=200;
for(i=0;i<PulseNum;i++) FullStepMotorCW();
//for(i=0;i<PulseNum;i++) HalfStepMotorCW();
} while (1);
}
void interrupt()
{
}
char pos=0;
char FullStepForward [4]={0x03, 0x09, 0x0C, 0x06};
char FullStepBackward[4]={0x06, 0x0C, 0x09, 0x03};
char HalfStepForward [8]={0x03, 0x01, 0x09, 0x08, 0x0C, 0x04, 0x06, 0x02};
char HalfStepBackward[8]={0x06, 0x04, 0x0C, 0x08, 0x09, 0x01, 0x03, 0x02};
void FullStepMotorCW()
{
TRISD=FullStepForward[pos];
delay_ms(50);
pos=(pos+1)%4;
}
void FullStepMotorCCW()
{
TRISD=FullStepBackward[pos];
delay_ms(1000);
pos=(pos+1)%4;
}
void HalfStepMotorCW()
{
TRISD=HalfStepForward[pos];
delay_ms(1000);
pos=(pos+1)%8;
}
void HalfStepMotorCCW()
{
TRISD=HalfStepBackward[pos];
delay_ms(1000);
pos=(pos+1)%8;
}
void Initial()
{
TRISD=0x00;
}
void main() {
char i;
Initial();
do {
PulseNum=200;
for(i=0;i<PulseNum;i++) FullStepMotorCW();
//for(i=0;i<PulseNum;i++) HalfStepMotorCW();
} while (1);
}
void interrupt()
{
}