延時函數(shù)屏蔽掉就正常改一下 輸出變得更怪異 有誰知道是怎么回事么附void delay1ms(uchar t) //1ms延時{uchar a,b;for(a=0;a<t;a++)for(b=0;b<125;b++);}#include <reg52.h> #define uchar unsigned char #define uint unsigned int #define ulong unsigned long sbit IN4=P1^2; //B-sbit IN3=P1^3; //B+sbit EN2=P1^4; //B使能 sbit IN2=P1^5; //A- sbit IN1=P1^6; //A+sbit EN1=P1^7; //A使能uchar np;uchar steptable[]={//時序表 0-7為正轉,7-0為反轉0xd3, 0xdb,0x9b,0xbb,0xb3,0xb7,0x97,0xd7};void delay1ms(uchar t) //1ms延時{uchar a,b;for(;t>0;t--)for(a=2;a>0;a--)for(b=220;b>0;b--);}void a_step(uchar d,uchar t) {if(d&0x01) {if(np==0) np=7; else np--; }else{if(np==7)np=0;else np++;}P1=steptable[np];delay1ms(t); }void a_turn(uchar d,uchar t){ uchar i;for(i=0;i<96;i++)a_step(d,t);}void main(void){while(SEN){ a_step(0,200); }while(1) //主循環(huán){ a_turn(0,200);}}
- 2 回答
- 0 關注
- 152 瀏覽