应用介绍
舞蹈机器人步进机仿真
#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 InitTimer(void) //初始化计数器
{
TH0 = 0xFA; //设置触发周期:1000次
TL0 = 0x24;
TMOD = TMOD |0x01; //select mode 1
TR0 = 1; //start timer0
ET0 = 1; //enable timer 0 interrupt
EA =1; //global interrupt enable
}
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;
}
else if(speed_tickers[i] <= -MAX_SPEED_TICKER) //同上,反响旋转
{
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 OnTimer(void) interrupt 1 using 2
{
unsigned char j;
SetAllSpeeds();
InitTimer();
time_t++;
if(time_t==200) //每200次触发读取一次新舞步数据
{
for(j=0;j<8;j++)
speeds[j] = dancedata[data_pointer+j];
data_pointer += 8;
time_t = 0;
}
}
void main() //程序的入口
{
InitTimer(); //初始化后等中断
while(1);
}
©版权声明:本文内容由互联网用户自发贡献,版权归原创作者所有,本站不拥有所有权,也不承担相关法律责任。如果您发现本站中有涉嫌抄袭的内容,欢迎发送邮件至: www_apollocode_net@163.com 进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。
转载请注明出处: apollocode » 舞蹈机器人步进机仿真
文件列表(部分)
名称 | 大小 | 修改日期 |
---|---|---|
123.DSN | 16.76 KB | 2019-06-24 |
123.PWI | 0.36 KB | 2019-06-24 |
Last Loaded 123.DBK | 16.77 KB | 2019-06-24 |
robot | 1.93 KB | 2019-06-24 |
robot.c | 1.16 KB | 2019-06-24 |
robot.hex | 0.85 KB | 2019-06-24 |
robot.lnp | 0.02 KB | 2019-06-24 |
robot.LST | 1.71 KB | 2019-06-24 |
robot.M51 | 1.20 KB | 2019-06-24 |
robot.OBJ | 2.07 KB | 2019-06-24 |
robot.Opt | 0.65 KB | 2019-06-24 |
robot.plg | 0.20 KB | 2019-06-24 |
robot.Uv2 | 0.86 KB | 2019-06-24 |
robot.__i | 0.03 KB | 2019-06-24 |
robot_Opt.Bak | 0.65 KB | 2019-06-24 |
robot_Uv2.Bak | 0.83 KB | 2019-06-24 |
robot | 0.00 KB | 2019-06-24 |
0044、舞蹈机器人步进机仿真 | 0.00 KB | 2019-06-24 |
发表评论 取消回复