流水灯已实现向左,向右和左右,暂停的功能,还差快速和低速两个功能不知道怎么加上去
[复制链接]
#include<reg51.h>
sbit key1=P3^0;
sbit key2=P3^1;
unsigned char dat1[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char dat2[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
unsigned char dat3[15]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
unsigned char MODE=0,stu=0,num;
void delay(unsigned int x);
void keyscan(void);
void main(void)
{
while(1)
{
keyscan();
switch(MODE)
{
case 0:if(stu) {P0=dat1[num];num++;num%=8;}break;
case 1:if(stu) {P0=dat2[num];num++;num%=8;}break;
case 2:if(stu) {P0=dat3[num];num++;num%=15;}break;
}
delay(100);
}
}
void delay(unsigned int x)
{
unsigned int i,j;
for(i=0;i<x;i++)
{
for(j=0;j<333;j++);
}
}
void keyscan(void)
{
if(key1==0)
{
delay(10);
if(key1==0)
{
MODE++;
MODE%=3;
num=0;
while(key1==0);
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
stu++;
stu%=2;
while(key2==0);
}
}
}
|