我写的按键程序,求大神指教!
时间:10-02
整理:3721RD
点击:
先发程序
#include <reg51.h>
#define u8 unsigned char
u8 code seg[]={0x3f,6,0x5b,0x4f,0x66,0x6d,0x7d,7,0x7f,0x6f};
sbit w1=P2^0;
sbit w2=P2^1;
sbit up=P2^6;
sbit down=P2^7;
u8 x=90;
disp()
{u8 i;
P0=~seg[x/10];
w1=1;for(i=0;i<100;i++);w1=0;
P0=~seg[x%10];
w2=1;for(i=0;i<100;i++);w2=0;
}
key()
{u8 i;
if(up==0)
{for(i=0;i<100;i++)disp();
if(up==0)
{x++;if(x==100)x=0;
while(up==0)disp();
}
}
if(down==0)
{for(i=0;i<100;i++)disp();
if(down==0)
{x--;if(x==-1)x=99;
while(down==0)disp();
}
}
}
main()
{
while(1){disp();key();}
}
#include <reg51.h>
#define u8 unsigned char
u8 code seg[]={0x3f,6,0x5b,0x4f,0x66,0x6d,0x7d,7,0x7f,0x6f};
sbit w1=P2^0;
sbit w2=P2^1;
sbit up=P2^6;
sbit down=P2^7;
u8 x=90;
disp()
{u8 i;
P0=~seg[x/10];
w1=1;for(i=0;i<100;i++);w1=0;
P0=~seg[x%10];
w2=1;for(i=0;i<100;i++);w2=0;
}
key()
{u8 i;
if(up==0)
{for(i=0;i<100;i++)disp();
if(up==0)
{x++;if(x==100)x=0;
while(up==0)disp();
}
}
if(down==0)
{for(i=0;i<100;i++)disp();
if(down==0)
{x--;if(x==-1)x=99;
while(down==0)disp();
}
}
}
main()
{
while(1){disp();key();}
}