#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
/* 延时 */
void delay(uint i){while(i--);}
sbit row0=P3^0;sbit row1=P3^1;sbit col0=P3^2;
sbit col1=P3^3;sbit col2=P3^4;sbit col3=P3^5;
/* 机械手引脚定义 */
sbit wl1=P1^0; sbit wl2=P1^1; sbit wl3=P1^2; sbit wl4=P1^3;
sbit wl5=P1^4; sbit wl6=P1^5; sbit wl7=P1^6; sbit wl8=P1^7;
sbit j1=P3^6; sbit j2=P3^7; sbit j3=P2^0; sbit j4=P2^1; sbit j5=P2^2;
sbit k1=P2^4; sbit k2=P2^5; sbit sw1=P2^6; sbit sw2=P2^7;
#define stop j1=j2=1
#define zuo j1=0;j2=1
#define you j1=1;j2=0
#define shang j5=1
#define xia j5=0
#define jia j3=0;j4=1
#define song j3=1;j4=0
//字模数组,一个8*8字符占1行
uchar code zm[][8] =
{
0x3c,0x7E,0xff,0xff,0xff,0xff,0x7E,0x3C,
0x00,
};
uchar buf[8];
uchar n=0,q;
bit flag,work;
uint c,j;
uchar h=6;
void dis()
{
uchar i,n;
uint row=0x01;
for(i=0;i<16;i++){
n=i<8?0:1;
P0=zm[buf[0+4*n]][i-8*n]; col0=1;col0=0;
P0=zm[buf[1+4*n]][i-8*n]; col1=1;col1=0;
P0=zm[buf[2+4*n]][i-8*n]; col2=1;col2=0;
P0=zm[buf[3+4*n]][i-8*n]; col3=1;col3=0;
P0=row%0x100; row0=1;row0=0;
P0=row/0x100; row1=1;row1=0;
delay(50);
row=_irol_(row,1);
P0=0;
row0=row1=col0=col1=col2=col3=1;
row0=row1=col0=col1=col2=col3=0;
}
}
void jxs(){
if(sw2==0)
{
switch(n)
{
case 0:
if(wl4){shang;break;}
n=1;
//delay(50000);
case 1:
if(wl3){zuo;break;}
stop;
n=2;
// delay(50000);
case 2:
if(wl6==0){song;break;}
n=3;
case 3:
if(wl1&&flag==1){you;break;}
else if(wl2&&flag==0){you;break;}
stop;
n=4;
//delay(50000);
case 4:
if(wl5){xia;break;}
n=5;
// delay(50000);
case 5:
if(wl6){jia;break;}
n=0;
// delay(50000);
}
}
else {stop;shang;}
}
void anjian()
{
if(k1==0)
{
delay(500);
if(k1==0)
{
flag=1;
}
}
else if(k2==0)
{
delay(500);
if(k2==0)
{
flag=0;
}
}
q=wl3==0?1:(wl2==0&&wl4==0)?2:(wl1==0&&wl4==0)?3:(wl2==0&&wl5==0)?4:(wl1==0&&wl5==0)?5:0;
if(q==1){buf[1]=0;buf[2]=buf[3]=buf[6]=buf[7]=1;}
else if(q==2){buf[2]=0;buf[1]=buf[3]=buf[6]=buf[7]=1;}
else if(q==3){buf[3]=0;buf[1]=buf[2]=buf[6]=buf[7]=1;}
else if(q==4){buf[6]=0;buf[1]=buf[3]=buf[2]=buf[7]=1;}
else if(q==5){buf[7]=0;buf[1]=buf[3]=buf[6]=buf[2]=1;}
else if(q==0){buf[0]=buf[1]=buf[2]=buf[3]=buf[4]=buf[5]=buf[6]=buf[7]=1;}
}
void main(){
TMOD=0x10;
EA=TR1=ET1=1;
while(1){
buf[0]=buf[4]=buf[5]=1;
anjian();
jxs();
dis();
}
}
void time0() interrupt 3
{
TH0=0xfc;
TL0=0x17;
if(++c==1000)
{
c=0;
if(j>0)j--;
}
}
|