#include
#include
#defineucharunsignedchar
#defineuintunsignedint
ucharnp;
//步进电机运行数据表
constucharmotortb[]={0x11,0x99,0x88,0xCC,0x44,0x66,0x22,0x33};
voiddelay_nms(uintms)//每步延时de子程序
{
uinTI;
for(i=0;i_delay_loop_2(8*250);
}
voida_step(uchard,uchart)//步进电机走一步d=0正转d=1反转t越大走得越慢
{
if(d&0x01)
{
if(np==0)
np=7;
else
np--;
}
else
{
if(np==7)
np=0;
else
np++;
}
PORTD=motortb[np];
delay_nms(t);
}
voida_turn(uchard,uchart)//步进电机走一圈
{
uchari;
for(i=0;i《96;i++)
a_step(d,t);
}
intmain(void)
{
DDRD=0xff;
PORTD=0x44;
DDRB=0xff;
PORTB=0xff;
np=4;
while(1)
a_turn(1,200);
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)