×

用户注册

已有账号? 登录
javascript

cloud-cola

2020-11-03 20:07

窄足机器人代码 203

#include <reg60s2.h>
#include <math.h>
#include <delay.h>
#define uchar unsigned char
#define uint unsigned int
sbit KG=P1^7;
sbit pwm0 = P0^0;
sbit pwm1 = P0^1;
sbit pwm2 = P0^2;
sbit pwm3 = P0^3;
sbit pwm4 = P0^4;
sbit pwm5 = P0^5;
sbit pwm6 = P0^6;
sbit pwm7 = P0^7;

uchar position[8];
uchar pick_up[8];
uchar arr[8];
uchar t0bit=0;
uchar N;
void go_ahead_3_1();
void go_ahead_3_2();

void go_ahead_3_3();
void qian_gendou_3_4();
void hou_gendou_3_5();
void go_ahead_3_6();

//����ɨβֵ�IJ���
uchar zsax=15;
uchar psax=10;
uchar zsag=20;
uchar psag=20;

void low_level_500u(uint time)
{
uint i;
for(i=0;i<time;i++)
{delay500us(1);}
}

void t0_init(void)
{
TMOD = TMOD & 0xf0;
TMOD = TMOD | 0x01;

TH0=0xee;
TL0=0x00;
ET0=1;
EA=1;
t0bit=1;
}

void low_level_t0(uint THTL)
{
TH0=THTL>>8;
TL0=THTL;
t0bit=0;
TR0=1;
}

void T0_Interrupt(void) interrupt 1
{
TH0=0xee;
TL0=0x00;
t0bit=1;
}

void init_cpu(void)
{
t0_init();
delay500us(10);
}


void array()
{
uchar i=0,j=0,x=0;

pick_up[0]=0xFE;
pick_up[1]=0xFD;
pick_up[2]=0xFB;
pick_up[3]=0xF7;
pick_up[4]=0xEF;
pick_up[5]=0xDF;
pick_up[6]=0xBF;
pick_up[7]=0x7F;

//����
for(i=0;i<=6;i++)
{ for(j=i+1;j<=7;j++)
{
if(arr[i]<arr[j])//��������
{
x=arr[j];
arr[j]=arr[i];
arr[i]=x;

x=pick_up[j];
pick_up[j]=pick_up[i];
pick_up[i]=x;
}
}
}
for(i=0;i<7;i++)
{
arr[i]= arr[i]- arr[i+1];
}
}

void PWM_8()
{
uchar i=0,j;

for(i=0;i<8;i++) //ȡP0�ڶ����Ӧ��ֵ
{arr[i]=position[i];}
array();
low_level_t0(0xee00);
P0=0xff; //ʹ��P0ȫ������
delay500us(1); //������ʱ500us����
for(i=0;i<8;i++) //P0��8·ͬʱ���
{
for(j=0;j<arr[7-i];j++)
{delay8us(1);}
P0=P0&pick_up[7-i];
}
while(t0bit==0);
TR0=0;
}

void initial_position(void)
{
uint i,j,x=0;
for(i=0;i<30;i++)
{ x++;
//////��ʼ
position[0]=130;

position[1]=128;
position[2]=135;

position[3]=135;

position[4]=130;
position[5]=130;
position[6]=130;
position[7]=127;



PWM_8();
if(x<10)
{j=20;j--;
low_level_500u(j);
}
else
{ j=10;
j++;
low_level_500u(j);
}
}
}

void main(void)
{
SP=0x70;
P0M1 = 0x00;
P0M0 = 0x00;

init_cpu();

delay500us(10);
P0=0xff;
delay500ms(1);
initial_position();
delay500ms(1);

while(KG)
{
if(!KG)
delay500us(1);
if(!KG)
break;
}
delay10ms(50);

go_ahead_3_3();//�岽





while(1);
}

void go_ahead_3_3(void) //���岽
{
uchar i,a;
for(a=0;a<5;a++)
{
//a ////////�������㣬0��+12��3��+12
if(a==0)
{

for(i=0;i<10;i++)
{
position[0]+=1;
position[3]+=1; ////ԭ��3��+8����+12����Ų������Ҵ�
PWM_8();
delay500us(10);
}
}


//b // ����ŵĶ�����
for(i=0;i<10;i++)
{
position[2]+=1; //////// 2��+20
position[1]+=2; //////// 1��+40
position[4]+=1; //////// 4��+20
position[5]+=1; //////// 5��+20
position[6]+=1; //////// 5��+20
position[7]+=1; //////// 5��+20
PWM_8();
delay500us(40);
}




//c //// 0�ź�3��ֵ�ص�130,ʹ���ű���ˮƽ
for(i=0;i<10;i++)
{
position[0]-=1;
position[3]-=1;
PWM_8();
delay500us(22);
}
//d ////�������� 0��-12,3��-12
for(i=0;i<10;i++)
{
position[3]-=1;
position[0]-=1;
PWM_8();
delay500us(20);
}

//e ///////���ҽ� ��e��f�����Ժ�Ϊһ����������̫�죬��Э����
for(i=0;i<10;i++)
{
position[4]-=1;
position[5]-=1;
position[6]-=1;
position[7]-=1;

position[1]-=2;
position[2]-=1;

PWM_8();
delay500us(20); ///25
}
//f ////////���ҽ�
for(i=0;i<10;i++)
{
position[4]-=1;

position[7]-=1;


position[1]-=2;
position[2]-=1;
PWM_8();
delay500us(20); ///25
}

//g ////// 0�ź�3�Żص�130��˫�ű���ˮƽ
for(i=0;i<10;i++)
{
position[0]+=1;
position[3]+=1;
PWM_8();
delay500us(20);
}
//h /////// ��������,0��+12,3��+12
for(i=0;i<10;i++)
{
position[0]+=1;
position[3]+=1;
PWM_8();
delay500us(20);
}
// // ����ŵĶ�����


for(i=0;i<10;i++)
{
position[2]+=1; //////// 2��+20
position[1]+=2; //////// 1��+40
position[4]+=1; //////// 4��+20
position[5]+=1; //////// 5��+20
position[6]+=1; //////// 5��+20
position[7]+=1; //////// 5��+20
PWM_8();
delay500us(40);
}


if(a==4)
{

for(i=0;i<10;i++)
{
position[0]-=1;
position[3]-=1; ////ԭ��3��+8����+12����Ų������Ҵ�
PWM_8();
delay500us(90);
}
}
}
}


暂无任何评论