《51单片机控制(按键)2相步进电机-L298N驱动(共3页).doc》由会员分享,可在线阅读,更多相关《51单片机控制(按键)2相步进电机-L298N驱动(共3页).doc(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上/*本程序用于2相步进电机控制 L298N驱动通过独立按键进行控制转速和转向*/#include /52系列单片机头文件#define uchar unsigned char/宏定义#define uint unsigned int /宏定义sbit key1=P34; /解除锁定sbit key2=P35; /反转2圈sbit key3=P36; /反转4圈sbit key4=P37; /正转4圈/延时void delay(uint xms) uint i,j; for(i=xms;i0;i-) /i=xms即延时约xms毫秒 for(j=110;j0;j-);/主
2、函数void main() uint i=200; P3=0xff; while(1) if(key1=0) delay(10); if(key1=0) while(i-) P1=0X08; delay(2); P1=0X0a; delay(2); P1=0X02; delay(2); P1=0X06; delay(2); P1=0X04; delay(2); P1=0X05; delay(2); P1=0X01; delay(2); P1=0X09; delay(2); while(!key1); i=200; if(key2=0) delay(10); if(key2=0) while(i
3、-) P1=0X09; delay(2); P1=0X01; delay(2); P1=0X05; delay(2); P1=0X04; delay(2); P1=0X06; delay(2); P1=0X02; delay(2); P1=0X0a; delay(2); P1=0X08; delay(2); while(!key2); i=50; if(key3=0) delay(10); if(key3=0) while(i-) P1=0X08; delay(5); P1=0X0a; delay(5); P1=0X02; delay(5); P1=0X06; delay(5); P1=0X04; delay(5); P1=0X05; delay(5); P1=0X01; delay(5); P1=0X09; delay(5); while(!key3); if(key4=0) delay(10); if(key4=0) P1=0Xff; while(!key4); 专心-专注-专业