ATMEGA8驱动4线步进机程序 -
来源: 网络用户发布,如有版权联系网管删除 2018-09-08
[导读]ATMEGA8驱动4线步进机程序
#include
本文引用地址: http://www.21ic.com/app/mcu/201712/747152.htm
#include
#define uchar unsigned char
#define uint unsigned int
uchar np;
//步进电机运行数据表
const uchar motortb[]={0x11,0x99,0x88,0xCC,0x44,0x66,0x22,0x33};
void delay_nms(uint ms)// 每步延时的子程序
{
uint i;
for(i=0;i _delay_loop_2(8*250);
}
void a_step(uchar d,uchar t) //步进电机走一步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);
}
void a_turn(uchar d,uchar t)// 步进电机走一圈
{
uchar i;
for (i=0;i<96;i++)
a_step(d,t);
}
int main(void)
{
DDRD=0xff;
PORTD=0x44;
DDRB=0xff;
PORTB=0xff;
np=4;
while (1)
a_turn(1,200);
}
查看评论 回复
"ATMEGA8驱动4线步进机程序 -"的相关文章
- 上一篇:玩转单片机之对AD转换的理解 -
- 下一篇:如何使用AVR-GCC编译软件 -