下面这个程序K1=1步进电机正转(两相四线,l298驱动),K1=0为什么不反转呢?求好心人帮忙! 跪求单片机控制2相四线步进电机的启停、正反转,步进电机控制器...
\u771f\u5fc3\u6c42\u4e00\u6bb5\u4e24\u76f8\u56db\u7ebf\u6b65\u8fdb\u7535\u673a\u6b63\u53cd\u8f6c\u7684C\u8bed\u8a00\u9a71\u52a8\u7a0b\u5e8f\uff0c\u5355\u7247\u673a89c52\uff0c\u7528L298N\u9a71\u52a8\uff0c\u8dea\u6c42\u5404\u4f4d\u5927\u4fa0\u5e2e\u5fd9\uff0c\u8fd9\u4e2a\u4e0d\u96be\u554a
#include //51\u82af\u7247\u7ba1\u811a\u5b9a\u4e49\u5934\u6587\u4ef6
#include //\u5185\u90e8\u5305\u542b\u5ef6\u65f6\u51fd\u6570 _nop_();
#define uchar unsigned char
#define uint unsigned int
uchar code FFW[8]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9};
uchar code REV[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1};
sbit K1 = P3^4; //\u6b63\u8f6c
sbit K2 = P3^5; //\u53cd\u8f6c
sbit K3 = P3^6; //\u505c\u6b62
sbit K4 = P3^7;
sbit BEEP = P0^6; //\u8702\u9e23\u5668
/********************************************************/
/*
/* \u5ef6\u65f6t\u6beb\u79d2
/* 11.0592MHz\u65f6\u949f\uff0c\u5ef6\u65f6\u7ea61ms
/*
/********************************************************/
void delay(uint t)
{
uint k;
while(t--)
{
for(k=0; k<125; k++)
{ }
}
}
/**********************************************************/
void delayB(uchar x) //x*0.14MS
{
uchar i;
while(x--)
{
for (i=0; i<13; i++)
{ }
}
}
/**********************************************************/
void beep()
{
uchar i;
for (i=0;i<180;i++)
{
delayB(5);
BEEP=!BEEP; //BEEP\u53d6\u53cd
}
BEEP=1; //\u5173\u95ed\u8702\u9e23\u5668
}
/********************************************************/
/*
/*\u6b65\u8fdb\u7535\u673a\u6b63\u8f6c
/*
/********************************************************/
void motor_ffw()
{
uchar i;
uint j;
for (j=0; j<12; j++) //\u8f6c1*n\u5708
{
if(K4==0)
{break;} //\u9000\u51fa\u6b64\u5faa\u73af\u7a0b\u5e8f
for (i=0; i<8; i++) //\u4e00\u4e2a\u5468\u671f\u8f6c30\u5ea6
{
P0 = FFW[i]; //\u53d6\u6570\u636e
delay(15); //\u8c03\u8282\u8f6c\u901f
}
}
}
/********************************************************/
/*
/*\u6b65\u8fdb\u7535\u673a\u53cd\u8f6c
/*
/********************************************************/
void motor_rev()
{
uchar i;
uint j;
for (j=0; j<12; j++) //\u8f6c1\u00d7n\u5708
{
if(K4==0)
{break;} //\u9000\u51fa\u6b64\u5faa\u73af\u7a0b\u5e8f
for (i=0; i<8; i++) //\u4e00\u4e2a\u5468\u671f\u8f6c30\u5ea6
{
P0 = REV[i]; //\u53d6\u6570\u636e
delay(15); //\u8c03\u8282\u8f6c\u901f
}
}
}
/********************************************************
*
* \u4e3b\u7a0b\u5e8f
*
*********************************************************/
main()
{
uchar r,N=5; //N \u6b65\u8fdb\u7535\u673a\u8fd0\u8f6c\u5708\u6570
P2=0xDF;
while(1)
{
if(K1==0)
{
beep();
for(r=0;r<N;r++)
{
motor_ffw(); //\u7535\u673a\u6b63\u8f6c
if(K4==0)
{beep();break;} //\u9000\u51fa\u6b64\u5faa\u73af\u7a0b\u5e8f
}
}
else if(K2==0)
{
beep();
for(r=0;r<N;r++)
{
motor_rev(); //\u7535\u673a\u53cd\u8f6c
if(K4==0)
{beep();break;} //\u9000\u51fa\u6b64\u5faa\u73af\u7a0b\u5e8f
}
}
else
P0 = 0xf0;
}
}
/********************************************************/
\u7a0b\u5e8f\u4ec5\u4f9b\u53c2\u8003
绛旓細sbit K1=P1^0;sbit K2=P1^1;char y=0;while(1){ pangduan();for(i=0;i<4;i++) //4鐩 { /*P1=F_Rotation[i]; //杈撳嚭瀵瑰簲鐨鐩 鍙互鑷鎹㈡垚鍙嶈浆琛ㄦ牸 Delay(500); //鏀瑰彉杩欎釜鍙傛暟鍙互璋冩暣鐢垫満杞 Delay(5000);*/ P1=B_Rotation[i];Delay(265+y);P1=F_Rotation[i];De...
绛旓細include <REGX52.H> bit aj = 0;sbit clk1=P1^0;//瀹氫箟X鑴夊啿杈撳嚭浣 sbit dir1=P1^1;//瀹氫箟X姝e弽杞帶鍒朵綅 sbit ena1=P1^2;//瀹氫箟Y浣胯兘鎺у埗浣 sbit x1 =P1^6;unsigned int k=0,x11,y11,cycle=2000,yk,xk,xk1;//瀹氫箟寮濮嬫帶鍒朵綅 unsigned char x = 1;unsigned int kx;void ...
绛旓細TEST AL,00010000B ;娴嬭瘯鏄惁K1鎸変笅锛屾槸缁х画娴嬭瘯锛屼笉鏄垯璺宠浆 JNZ A1 JMP A0 A1: TEST AL,00100000B ;娴嬭瘯鏄惁K2鎸変笅锛屾槸鍒欒烦杞埌鍙嶈浆 JZ A2 TEST AL,01000000B ;娴嬭瘯鏄惁K3鎸変笅锛屾槸鍒欒烦杞埌姝h浆 JZ A3 JMP A0 A2: LEA SI,DATA1 ;鍙栦娇鐢垫満鍙嶈浆鐨浠g爜鍦板潃 MO...
绛旓細0x08,0x0c,0x04,0x06,0x02,0x03,0x01};sbit k1=P3^0; //姝h浆sbit k2=P3^1; //鍙嶈浆sbit k3=P3^2; //鍋滄//寤舵椂void delay(uchar ms){ uchar us; while(ms--)for(us=0;us<120;us++);}//姝h浆void SETP_MOTOR_FFW(uchar n){ uchar i,j; for(i=0;i<5*n;i++)...
绛旓細缁涓涓互鍓嶉珮涓啓鐨勬杩涚數鏈虹▼搴缁欎綘锛屼笉鐭ラ亾琛屼笉琛岋紝濡傛灉姝ヨ繘鐢垫満涓嶄竴鏍峰簲璇ユ槸涓嶈鐨勶紝楂樹腑鍐欑殑锛屼篃娌℃湁鏀硅繃锛屼及璁′笉鏄庝箞涓ヨ皑锛屽啓寰椾篃涓嶅ソ锛屼笉杩囧笇鏈涜兘甯埌浣犮傜敤51鍗曠墖鏈哄啓鐨 define _121_C_include "reg51.h"include "121.h"include "intrins.h"sbit k1=P1^7;sbit k2=P1^6;sbit cp=...
绛旓細/*姝ヨ繘鐢垫満姝杞 / /***/ void motor_ffw(){ uchar i;uint j;for (j=0; j<8; j++) //杞1*n鍦 { if(K3==0){break;} //閫鍑烘寰幆绋嬪簭 for (i=0; i<8; i++) //涓涓懆鏈熻浆45搴 { P1 = FFW[i]; //鍙栨暟鎹 delay(2); //璋冭妭杞 } } }/***...
绛旓細浣犲ソ锛屾妸浣鐨鐢佃矾鍥炬嬁鍑烘潵锛岀粰鎴戠湅涓鐪嬨傚彟澶栨垜瑙夊緱鍙互鐢ㄥ畾鏃朵腑鏂紝鏉ュ疄鐜板欢杩熸帶鍒姝ヨ繘鏈虹殑杞燂紝浠ヤ究璁〤PU骞叉洿澶氱殑娲汇
绛旓細瑕佷娇鐢姝ヨ繘鐢垫満杞姩,鍙杞祦缁欏悇寮曞嚭绔氱數鍗冲彲銆傚皢COM绔爣璇嗕负C,鍙AC銆 C銆丅C銆 C,杞祦鍔犵數灏辫兘椹卞姩姝ヨ繘鐢垫満杩愯浆,鍔犵數鐨鏂瑰紡鍙互鏈夊绉,濡傛灉灏咰OM绔帴姝g數婧,閭d箞鍙鐢ㄥ紑鍏冲厓浠(濡備笁鏋佺),灏咥銆 銆丅銆 杞祦鎺ュ湴銆 涓嬭〃鍒楀嚭浜嗚鐢垫満鐨勪竴浜涘吀鍨嬪弬鏁:琛1 35BY48S03鍨嬫鏈虹數鏈哄弬鏁板瀷鍙 姝ヨ窛瑙 鐩告暟 ...
绛旓細JNB P3.2,JIASUZ ;鍔犻熷瓙绋嬪簭 JNB P3.3,JIANSUZ ;鍑忛熷瓙绋嬪簭 ACALL DELAY INC R4 AJMP KEY FZ1:JB P3.1,KEY CJNE R4,#255,LOOPF MOV R4,#8 LOOPF: DEC R4 MOV A,R4 MOVC A,@A+DPTR ;璇昏剦鍐 MOV P0,A ;缁姝ヨ繘鐢垫満杈撳叆鑴夊啿 SETB P1...
绛旓細涓柇0锛岃閿洏銆傛病鏈塻can_key()鐨勬簮浠g爜锛屼笉鐭ラ亾閲岄潰鏈変簺浠涔堟搷浣溿倃hile(1){...}寰幆鏄鐢垫満杩愯浆锛宖lag_status鏄姸鎬侊紝1杞姩锛0鍋滄銆傛病鏈夌湅鍒颁笌姝h浆鍙嶈浆鏈夊叧鐨勪唬鐮併備篃璁稿湪motor_cw_ccw();鍑芥暟閲岄潰锛杩欎釜灏辨槸鐢垫満鍔涓涓嬬殑鍑芥暟銆傚師绋嬪簭涓嶅畬鏁达紝娌℃湁鐩稿簲鍑芥暟銆佸彉閲忕殑瀹氫箟鍙婃剰涔夎鏄庛傞毦浠ョ‘鍒囩悊瑙...