高手帮我解释一下。
#include<reg51.h>
#define lie P1
#define hang P2
#define uchar unsigned char
uchar d[][8]=
{
{0x38,0x38,0x38,0xfe,0x7c,0x38,0x10,0x00},
{0x10,0x38,0x7c,0xfe,0x38,0x38,0x38,0x00}
};
uchar speed=30;
uchar scan;
sbit key1=P3^0;
sbit key2=P3^1;
void Delayms(uchar x)
{int i,j;
for(i=0;i<x;i++)
for(j=0;j<120;j++);
}
void up(uchar word,uchar counts)
{char i,j,k,l;
for(l=0;l<counts;l++)
for(j=7;j>=0;j--)
for(k=0;k<speed;k++)
{scan=0x01;
for(i=7;i>=0;i--)
{lie=0x00;
hang=~scan;
if(i>j) lie=d[word][8+(j-i)];
else lie=d[word][j-i];
Delayms(2);
scan<<=1;
}
}
}
void down(uchar word,uchar counts)
{char i,j,k,l;
for(l=0;l<counts;l++)
for(j=0;j<8;j++)
for(k=0;k<speed;k++)
{scan=0x80;
for(i=0;i<8;i++)
{lie=0x00;
hang=~scan;
if(i>j) lie=d[word][8+(j-i)];
else lie=d[word][j-i];
Delayms(2);
scan>>=1;
}
}
}
main()
{P3=0xff;
while(1)
{if (key1==0)up(0,3);
if (key2==0)down(1,3);
Delayms(2);
lie=0x00;}}
|