📄 1.c
字号:
sfr P1= 0x90;
#include"reg52.h"
#include"user.h"
#include"math.h"
#define uchar unsigned char
#define out P1
sbit EN=P3^7;
void run(int motor_A_counter,int motor_B_counter)
{
uchar state_A,state_B,new_state,temp1,temp2;
unsigned int temp_A,temp_B;
if (motor_A_counter==0)
goto B;
if (motor_A_counter>0)
{
temp_A=abs(motor_A_counter);
while((temp_A--)!=0)
{
temp1=out;
temp1 &=0x0f;
state_A=out;
state_A &= 0xf0;
state_A>>=4;
switch (state_A)
{
case 1:
new_state=3;
break;
case 3:
new_state=2;
break;
case 2:
new_state=6;
break;
case 6:
new_state=4;
break;
case 4:
new_state=12;
break;
case 12:
new_state=8;
break;
case 8:
new_state=9;
break;
case 9:
new_state=1;
break;
}
new_state<<=4;
out=new_state | temp1;
delay(3);
}
}
if (motor_A_counter<0)
{
temp_A=abs(motor_A_counter);
while((temp_A--)!=0)
{
temp1=out;
temp1 &=0x0f;
state_A=out;
state_A &= 0xf0;
state_A>>=4;
switch (state_A)
{
case 9:
new_state=8;
break;
case 8:
new_state=12;
break;
case 12:
new_state=4;
break;
case 4:
new_state=6;
break;
case 6:
new_state=2;
break;
case 2:
new_state=3;
break;
case 3:
new_state=1;
break;
case 1:
new_state=9;
break;
}
new_state<<=4;
out=new_state | temp1;
delay(3);
}
}
//----------------------------------------------------------------
B: if (motor_B_counter==0)
goto exit;
if (motor_B_counter>0)
{
temp_B=abs(motor_B_counter);
while((temp_B--)!=0)
{
temp2=out;
temp2 &=0xf0;
state_B=out;
state_B &= 0x0f;
switch (state_B)
{
case 1:
new_state=3;
break;
case 3:
new_state=2;
break;
case 2:
new_state=6;
break;
case 6:
new_state=4;
break;
case 4:
new_state=12;
break;
case 12:
new_state=8;
break;
case 8:
new_state=9;
break;
case 9:
new_state=1;
break;
}
out=new_state | temp2;
delay(3);
}
}
if (motor_B_counter<0)
{
temp_B=abs(motor_B_counter);
while((temp_B--)!=0)
{
temp2=out;
temp2 &=0xf0;
state_B=out;
state_B &= 0x0F;
switch (state_B)
{
case 9:
new_state=8;
break;
case 8:
new_state=12;
break;
case 12:
new_state=4;
break;
case 4:
new_state=6;
break;
case 6:
new_state=2;
break;
case 2:
new_state=3;
break;
case 3:
new_state=1;
break;
case 1:
new_state=9;
break;
}
out=new_state | temp2;
delay(3);
}
}
exit : delay(1);
}
void main(void)
{
// uchar code a[8]={0x11,0x33,0x22,0x66,0x44,0xcc,0x88,0x99};
double L1,L2,x,y,H,W;
EN=0;
out=0x11;
H=10000;
W=10000;
x=1;
y=1;
L1=sqrt(x*x+(H-y)*(H-y));
L2=sqrt((W-x)*(W-x)+(H-y)*(H-y));
while(1)
{
run(-1,0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -