#include <reg51.h>
sbit key1=P3^0;
sbit key2=P3^4;
unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned char num=8;
void delay_ms(unsigned char t)
{
unsigned char x,y;
for(x=t;x>0;x–)
for(y=110;y>0;y–);
}
void keysan() //键盘扫描函数
{
if(key10)
{
delay_ms(10); //消抖
if(key10)
{
while(!key1); //等待按键释放
num++;
if(num>=15)num=0;
}
}
if(key2==0)
{
delay_ms(10); //消抖
if(key2==0)
{
while(!key2); //等待按键释放
if(num>=1) num--;
}
}
}
void main(void)
{
while(1) //主循环
{
keysan();
P1=tab[num];
}
}