电路如图所示:
程序
stepper.c
stepper.hex
#include c:/mc51/8051io.h
#include c:/mc51/8051reg.h
register unsigned char j,flag1,temp;
register unsigned int cw_n,ccw_n;
unsigned char step[8]={080,0c0,040,060,020,030,010,090}
#define n 400
main()
{
flag1=0;
serinit(9600);
disable();
cw_n = n;
flag1 |=001;
while(1){
{
tick_wait();
energize();
cw();
ccw();
}
}
}
cw(){
if((flag1&001)!=0)
{
cw_n--;
if (cw_n !=0)
j++;
else
{flag1&=~001;
ccw_n = n;
flag1 |=002;
}
}
}
ccw(){
if((flag1&002)!=0)
{
ccw_n--;
if (ccw_n !=0)
j--;
else
{flag1&=~002;
cw_n = n;
flag1 |=001;
}
}
}
tick_wait(){
asm" JNB TCON.5,*";
asm" CLR TCON.5";
asm" ORL TH0,#$DC";
}
energize(){
P1 = step[(j&007)];
}西玛西玛电机