ATMEGA8单片机对步进电机的驱动

控制/MCU

1811人已加入

描述

#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);

}

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分