基于51单片机的舞蹈机器人步进机仿真设计

发布时间:2023-02-09  

程序运行图:

仿真原理图:

部分程序:

#include "reg51.h"

#include "intrins.H"

//8步式步进电机脉冲序列

//unsigned char steps[8] = {0x77,0x33,0xbb,0x99,0xdd,0xcc,0xee,0x66};

unsigned char steps[8] = {0x2,0x6,0x4,0xc,0x8,0x9,0x1,0x3};

//当前各电机在上述序列中的位置

unsigned char cur_step[8] = {0,0,0,0,0,0,0,0};

//这个文件用于记录舞步信息序列

char speed_tickers[8] = {0,0,0,0,0,0,0,0};

//从上述文件中读出的当前舞步信息

unsigned char speeds[8] = {0,0,0,0,0,0,0,0};

unsigned char data_pointer = 0;//指向舞步数据的指针

unsigned char time_t = 0;//指定重新读取一次 speeds 值的计时周期

code char dancedata[] = {54,15,12,12,87,95,65,45,-89,-88,-54,-54,54,68,-45,-65,-65,-48,101,121,115,117,19,

-98,-100,-21,-114,-101,-24,-98,95,102,102,100,130,30,10,-90,-120,87,102,103,105,109,104,-30,-102,-104,-106,110,100,

54,15,12,12,87,95,65,45,-89,-88,-54,-54,-98,95,102,102,100,130,30,10,-90,-120,87,102-114,-101,-24,-98,95,102,102,

100,130,30,10,-90,-120,87,102,102,100,130,30,10,-90,-120,87,102,103,105,54,15,12,12,87,95,65,45,-89,-88,-54,

-98,-100,-21,-114,-101,-24,-98,95,102,102,100,130,30,10,-90,-120,87,102,103,105,12,87,95,65,45,-89,-88,-54,

-98,-100,-21,-114,-101,-24,-98,95,102,102,100,130,30,10,-90,-120,87,102,103,105,109,104,-30,-102,-104,-106,110,

100,130,30,10,-90,-120,87,102,102,100,130,30,10,-90,-120,87,-120,87,102,103,105,109,104,-30,-102,-104,-106,110,

54,15,12,12,87,95,65,45,-89,-88,-54,-54,-98,95,102,102,100,130,30,10,-90,-120,87,102-114,-101,-24,-98,95,102,102,

54,15,12,12,87,95,65,45,-89,-88,-54,-54,-98,95,102,102,100,130,30,10,-90,-120,87,102-114,-101,-24,-98,95,102,102,

54,15,12,12,87,95,65,45,-89,-88,-54,-54,-98,95,102,102,100,130,30,10,-90,-120,87,102-114,-101,-24,-98,95,102,102,

54,15,12,12,87,95,65,45,-89,-88,-54,-54,-98,95,102,102,100,130,30,10,-90,-120,87,102-114,-101,-24,-98,95,102,102,

-98,-100,-21,-114,-101,-24,-98,95,102,102,100,130,30,10,-90,-120,87,102,103,105,12,87,95,65,45,-89,-88,-54,

-98,-100,-21,-114,-101,-24,-98,95,102,102,100,130,30,10,-90,-120,87,102,103,105,12,87,95,65,45,-89,-88,-54,

-98,-100,-21,-114,-101,-24,-98,95,102,102,100,130,30,10,-90,-120,87,102,103,105,12,87,95,65,45,-89,-88,-54,

};

code char pin[8] = {1,2,4,8,16,32,64,128};

char MAX_SPEED_TICKER = 120;

unsigned char i; //电机序号




void SetAllSpeeds(void) //设置各电机的速度,并让它运动起来

{

char delta; //旋转方向 1:正 -1:反 0:停

for(i=0;i<8;i++)

{

P2=pin[i]; //发送锁存信号

speed_tickers[i] += speeds[i]; //计数值增加 speed[i]越高,增加得越多

if(speed_tickers[i] >= MAX_SPEED_TICKER) //如果计数值超过预定最大值,就发送脉冲

{

speed_tickers[i] = 0;

delta = 1;

}

{

speed_tickers[i] = 0;

delta = -1;

}

else delta = 0;

cur_step[i] += delta;

cur_step[i] &= 0x07; //计算当前应发脉冲

P0 = steps[cur_step[i]];

P2 = 0;

}

}



void main() //程序的入口

{

InitTimer(); //初始化后等中断

while(1);

}


文章来源于:电子工程世界    原文链接
本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。

我们与500+贴片厂合作,完美满足客户的定制需求。为品牌提供定制化的推广方案、专属产品特色页,多渠道推广,SEM/SEO精准营销以及与公众号的联合推广...详细>>

利用葫芦芯平台的卓越技术服务和新产品推广能力,原厂代理能轻松打入消费物联网(IOT)、信息与通信(ICT)、汽车及新能源汽车、工业自动化及工业物联网、装备及功率电子...详细>>

充分利用其强大的电子元器件采购流量,创新性地为这些物料提供了一个全新的窗口。我们的高效数字营销技术,不仅可以助你轻松识别与连接到需求方,更能够极大地提高“闲置物料”的处理能力,通过葫芦芯平台...详细>>

我们的目标很明确:构建一个全方位的半导体产业生态系统。成为一家全球领先的半导体互联网生态公司。目前,我们已成功打造了智能汽车、智能家居、大健康医疗、机器人和材料等五大生态领域。更为重要的是...详细>>

我们深知加工与定制类服务商的价值和重要性,因此,我们倾力为您提供最顶尖的营销资源。在我们的平台上,您可以直接接触到100万的研发工程师和采购工程师,以及10万的活跃客户群体...详细>>

凭借我们强大的专业流量和尖端的互联网数字营销技术,我们承诺为原厂提供免费的产品资料推广服务。无论是最新的资讯、技术动态还是创新产品,都可以通过我们的平台迅速传达给目标客户...详细>>

我们不止于将线索转化为潜在客户。葫芦芯平台致力于形成业务闭环,从引流、宣传到最终销售,全程跟进,确保每一个potential lead都得到妥善处理,从而大幅提高转化率。不仅如此...详细>>