您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 综合/其它 > 51单片机步进电机调速c程序
#includereg52.h#includeabsacc.h#defineuintunsignedintsbitp27=P2^7;sbitp26=P2^6;sbitp25=P2^5;sbitd0=P0^0;sbitd1=P0^1;sbitd2=P0^2;sbitd3=P0^3;sbitd4=P0^4;sbitd5=P0^5;sbitd6=P0^6;sbitd7=P0^7;#defineLED7XBYTE[0x9000]#defineLED6XBYTE[0x9001]#defineLED5XBYTE[0x9f02]#defineLED4XBYTE[0x9f03]#defineLED3XBYTE[0x9f04]#defineLED2XBYTE[0x9f05]#defineLED1XBYTE[0x9f06]#defineLED0XBYTE[0x9f07]uinttt[]=//ÊýÂëÏÔʾ±í£¨89c52£©{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};uintz=50;//uintm=5;uintflag=0;voiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voidmotor_z()//Õý´«{P1=0x01;delay(z);P1=0x02;delay(z);P1=0x04;delay(z);P1=0x08;delay(z);}voidmotor_f()//·´×ª{P1=0x08;delay(z);P1=0x04;delay(z);P1=0x02;delay(z);P1=0x01;delay(z);}voidmotor_stop()//Í£Ö¹{P1=0x00;}voidinit(){LED0=0;LED1=0;LED2=0;LED3=0;LED4=0;LED5=0;LED6=0;LED7=0;//¹ØµôÊýÂë¹Üflag=2;//ʹ²½½øµç»úÒ»¿ªÊ¼¾Í´¦ÓÚֹͣ״̬}voidkeyscan(){p27=1;p26=0;p25=1;/////////////////////////////key1Õýתif(d1==0){delay(5);if(d1==0)flag=0;}/////////////////////////////key2·´×ªif(d2==0){delay(5);if(d2==0)flag=1;}/////////////////////////////key3Í£Ö¹if(d3==0){delay(5);if(d3==0)flag=2;}/////////////////////////////key4¼õËÙif(d4==0){//delay(100);while(~d4);//Ð޸Ĵ¦delay(5);if(d4==1)z+=5;if(z=0)z=50;}/////////////////////////////key5¼ÓËÙif(d5==0){//delay(100);while(~d5);delay(5);if(d5==1)z-=5;if(z=0)z=50;}/////////////////////////////key6Ö±½Ó¼ÓËÙÖÁ10µµif(d6==0){delay(5);if(d6==0)z=10;}}voiddisplay(uintz){LED7=tt[z/100];LED6=tt[z%100/10];LED5=tt[z%10];}voidmain(){init();//³õʼ»¯while(1){switch(flag){case0:motor_z();break;case1:motor_f();break;default:motor_stop();break;}keyscan();//¼üÅÌɨÃèdisplay(z);}}±¾ÎÄÀ´×Ô£ºproteus·ÂÕæÂÛ̳£¨£©£¬Ïêϸ³ö´¦²Î¿¼:
本文标题:51单片机步进电机调速c程序
链接地址:https://www.777doc.com/doc-7226206 .html