89c52分别控制2个步进电机控制器编程

89C52驱动两个步进电机的问题 - 单片机/MCU论坛 -
中国电子技术论坛 -
最好最受欢迎电子论坛!
后使用快捷导航没有帐号?
89C52驱动两个步进电机的问题
14:48:52  
思路& &两个步进电机模拟两个轮子& &使二驱车能够实现加速 减速 转向& && & 既做到匀速加速减速左右转&&其中非转向时两点机同步转动
设备和连接&&89C82& &其中电阻除了单片机供电是10K之外全是220&&电容30PF& && &按键分别有加减速&&倒车&&左右转&&寻迹模式和壁障模式& &&&7个
#include&AT89X52.h&
#define step_moto_port1 P0
#define step_moto_port2 P3
#define JIASU_KEY (!(P2_0))
#define JIANSU_KEY (!(P2_1))
#define ZZ_KEY (!(P2_2))
#define YZ_KEY (!(P2_3))
#define XJ_KEY (!(P2_4))
#define BZ_KEY (!(P2_5))
#define DC_KEY (!(P2_6))
sbit LED1 = P1^0;
sbit LED2 = P1^1;
unsigned int speed=1000;
unsigned int speed_change=1000;
unsigned char dir=1;& & & & & & & && &//倒车控制,1为前进,0为倒车
unsigned char zhuan=0;& & & && &//转向控制,0为直线,1为左转,2为右转
unsigned char ji=0;& & & && &//模拟接收寻迹传感器读数,0为关闭,1为开启寻迹
unsigned char bi=0;& & & && &//避障模式,0为无障碍,1为需要避障
void Delay()
unsigned char t,y;
&&for (t=0;t&245;t++)
& & for (y=0;y&240;y++);& & & &
void run()
speed=speed_
while(speed--)
if(zhuan==0)
&&if(dir==1)
& &if(step_moto_port1 &=0x80)
& & step_moto_port1=0x01;
& & else& & & &&&
& & step_moto_port1 &&= 1;
& &if(step_moto_port2 &=0x80)
& & step_moto_port2=0x01;
& & else& & & &&&
& & step_moto_port2 &&= 1;
if(dir==0)
& &LED1 = ~LED1;
& &LED2 = ~LED2;
& &if(step_moto_port1 &=0x01)
& & step_moto_port1=0x08;
& & step_moto_port1 &&= 1;
& &if(step_moto_port2 &=0x01)
& & step_moto_port2=0x08;
& & step_moto_port2 &&= 1;
if(zhuan==1)
&&LED1 = ~LED1;
&&step_moto_port1=0x00;
&&if(step_moto_port2 &=0x80)
& &step_moto_port2=0x01;
&&else& & & &&&
& &step_moto_port2 &&= 1;
if(zhuan==2)
&&LED2 = ~LED2;
&&step_moto_port2=0x00;
&&if(step_moto_port1 &=0x80)
& &step_moto_port1=0x01;
&&else& & & &&&
& &step_moto_port1 &&= 1;
&&LED1 = ~LED1;
&&LED2 = ~LED2;
&&if(step_moto_port1 &=0x01)
& & step_moto_port1=0x08;
& & step_moto_port1 &&= 1;
&&if(step_moto_port2 &=0x01)
& & step_moto_port2=0x08;
& & step_moto_port2 &&= 1;
&&Delay();
&&Delay();
&&Delay();
&&LED1 = ~LED1;
&&step_moto_port1=0x00;
&&if(step_moto_port2 &=0x80)
& &step_moto_port2=0x01;
&&else& & & &&&
& &step_moto_port2 &&= 1;
void main(void)
step_moto_port1=0x01;
step_moto_port2=0x01;
&&if(DC_KEY)
&&if(ji==0)&&
&&dir = 0;
&&while(DC_KEY)&&run();
&&dir = 1;
&&if(JIANSU_KEY)
&&if(speed_change &= 2000)
&&speed_change = speed_change - 1000;
&&while(JIANSU_KEY) run();
&&if(JIASU_KEY)
&&if(speed_change & 20000)
&&speed_change = speed_change + 1000;
&&while(JIASU_KEY) run();
&&if(ZZ_KEY)
&&if(ji==0)
& &zhuan=1;
& &while(ZZ_KEY) run();
& &zhuan=0;
&&if(YZ_KEY)
&&if(ji==0)
& &zhuan=2;
& &while(YZ_KEY) run();
& &zhuan=0;
&&if(BZ_KEY)
&&if(ji==0)
& &while(BZ_KEY) run();
&&if(XJ_KEY)
&&if(ZZ_KEY)
& &zhuan=1;
& &while(ZZ_KEY) run();
& &zhuan=0;
&&if(YZ_KEY)
& &zhuan=2;
& &while(YZ_KEY) run();
& &zhuan=0;
&&while(XJ_KEY) run();
程序无法实现控制```````````按任何键都是减速到近乎停止& &&&而且电机要按倒车按键启动& &求助大神````````````
本帖子中包含更多资源
才可以下载或查看,没有帐号?
助理工程师
17:08:06  
虽不晓,但觉吊~~~
18:29:59  
一直很想做一个这样的东西来玩一下,但是现在都没有做,你如果要想别人给你答案,我建议你把程序的流程图也贴出来,我觉得看别人的程序是一件很头痛的事
Powered by
供应链服务
版权所有 (C) 深圳华强聚丰电子科技有限公司涓婁紶鍙戝竷
禄 鎻愬嚭浜嗕竴涓?敱AT89C52鍗曠墖鏈烘帶鍒舵?杩涚數鏈虹殑瀹炰緥銆傚彲浠ラ}

我要回帖

更多关于 arduino控制步进电机 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信