欢迎来到天天文库
浏览记录
ID:43555745
大小:16.15 KB
页数:3页
时间:2019-10-10
《步进电机正转按键有效控制加减速》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、#include"reg52.h"sbitF1=P1^0;sbitF2=P1^1;sbitF3=P1^2;sbitF4=P1^3;sbitkey1=P0^0;sbitkey2=P0^1;unsignedinti,t;//unsignedcharcodeFFW[8]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9};//电机延时voidmotor_delay(intz){intx,y;for(x=z;x>=0;x--)for(y=120;y>=0;y--);}//消抖voiddelay(void){
2、unsignedchari,j;for(i=0;i<150;i++)for(j=0;j<100;j++);}//按键选择voidkey(){if(key1==0){delay();if(key1==0){while(!key1);t++;}}elseif(key2==0){delay();if(key2==0){while(!key2);t--;}}}//正转voidmotor_turn(){unsignedchari;for(i=0;i<8;i++)//一个周期转30度{//P1=FFW[i]&0x1f;//取数据switch(
3、i){//case0:F1=1;F2=0;F3=0;F4=0;//motor_delay(t);//调节转速case1:F1=1;F2=1;F3=0;F4=0;motor_delay(t);break;//调节转速//case2:F1=0;F2=1;F3=0;F4=0;//motor_delay(t);//调节转速case3:F1=0;F2=1;F3=1;F4=0;motor_delay(t);break;//调节转速//case4:F1=0;F2=0;F3=1;F4=0;//motor_delay(t);//调节转速case5:
4、F1=0;F2=0;F3=1;F4=1;motor_delay(t);break;//调节转速//case6:F1=0;F2=0;F3=0;F4=1;//motor_delay(t);//调节转速case7:F1=1;F2=0;F3=0;F4=1;motor_delay(t);break;//调节转速}}}//反转voidmotor_back(){unsignedchari;for(i=0;i<4;i++)//一个周期转30度{switch(i){case3:F1=1;F2=1;F3=0;F4=0;motor_delay(t);b
5、reak;//调节转速case2:F1=0;F2=1;F3=1;F4=0;motor_delay(t);break;//调节转速case1:F1=0;F2=0;F3=1;F4=1;motor_delay(t);break;//调节转速case0:F1=1;F2=0;F3=0;F4=1;motor_delay(t);break;//调节转速}}}//主函数voidmain(){t=30;while(1){key();motor_turn();}}
此文档下载收益归作者所有