#include<reg52.h>
#define uchar unsigned char
sbit jia_key=P3^1;
sbit jian_key=P3^0;
sbit zf_key=P3^2;
bit flag;
uchar num=0,maichong=4,table_begin=0;
uchar code table[]={0x01,0x02,0x04,0x08,0x08,0x04,0x02,0x01};
void delay(uchar i)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void key()
{
if(jia_key==0)
{
delay(5);
if(jia_key==0)
{
num++;
if(num==4)
num=3;
while(jia_key==0);
}
}
if(jian_key==0)
{
delay(5);
if(jian_key==0)
{
if(num!=0)
num--;
else
num=0;
while(jian_key==0);
}
}
if(zf_key==0)
{
delay(5);
if(zf_key==0)
{
flag=~flag;
while(zf_key==0);
}
}
}
void dispose()
{
switch(num)
{
case 0:maichong=5;break;
case 1:maichong=4;break;
case 2:maichong=3;break;
case 3:maichong=2;break;
}
if(flag==0)
{
table_begin=0;
}
else
table_begin=4;
}
void qudong()
{
uchar i,j;
for(j=0+table_begin;j<4+table_begin;j++)
{
P0=table[i];
delay(20);
}
}
void main()
{
while(1)
{
key();
dispose();
qudong();
}
}
|