QQ圖片20190614124255.png (60.26 KB, 下載次數: 66)
下載附件
2019-6-14 12:43 上傳
QQ圖片20190614124133.jpg (2.58 MB, 下載次數: 46)
下載附件
2019-6-14 12:41 上傳
是電路連接出錯?還是程序有毛病呢?程序如下
#include <reg52.h>#define uint unsigned int #define uchar unsigned char uchar code FFW[]= { 0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09 };
uchar code REV[]= { 0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01 };
sbit K1 = P3^0; sbit K2 = P3^1; sbit K3 = P3^2; sbit K4 = P3^3; sbit K5 = P3^4; void DelayMS(uint ms) { uchari; while(ms--) { for(i=0;i<120;i++); } }
void SETP_MOTOR_FFW(uchar n) { uchari,j; int M=25; for(i=0;i<5*n;i++) { for(j=0;j<8;j++) { if(K3 == 0) break; P1 = FFW[j]; if(K4 == 0) { P0=0xf6; DelayMS(20); } else if(K5 == 0) { P0=0xee; DelayMS(100); } else DelayMS(50); if(K4 == 1&&K5 == 1) { P0 = 0xfe; } } } } void SETP_MOTOR_REV(uchar n) { uchari,j; int M=25; for(i=0;i<5*n;i++) { for(j=0;j<8;j++) { if(K3 == 0) break; P1 = REV[j]; if(K4 == 0) { P0=0xf5; DelayMS(20); } else if(K5 == 0) { P0=0xed; DelayMS(100); } else DelayMS(50); if(K4 == 1&&K5 == 1) { P0 = 0xfd; } } } } void main() { ucharN = 50; while(1) { if(K1 == 0) { P0 = 0xfe; SETP_MOTOR_FFW(N); if(K3 == 0) break; } else if(K2 == 0) { P0 = 0xfd; SETP_MOTOR_REV(N); if(K3 == 0) break; } else { P0 = 0xfb; P1 = 0x03; } } }
|