include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key=P1^0;
uchar num=0;
//共陰數碼管七段碼,需新增至16個
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77};
void Delay1ms(uint i) //1ms延時程式
{
uint j;
for(;i>0;i--)
for(j=0;j<164;j++)
{;}
}
void main(void )//主程式
while(1)
if(key==0)//判斷按鍵是否按下
Delay1ms(10);//延時消抖
if(key==0)
while(key==0);//等待按鍵抬起
num++;
if(num==16)num=0;
P0=table[num];
include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key=P1^0;
uchar num=0;
//共陰數碼管七段碼,需新增至16個
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77};
void Delay1ms(uint i) //1ms延時程式
{
uint j;
for(;i>0;i--)
{
for(j=0;j<164;j++)
{;}
}
}
void main(void )//主程式
{
while(1)
{
if(key==0)//判斷按鍵是否按下
{
Delay1ms(10);//延時消抖
if(key==0)
{
while(key==0);//等待按鍵抬起
num++;
if(num==16)num=0;
}
}
P0=table[num];
}
}