1个回答
展开全部
假设P0 P1口各接一个数码管,p2.0接按键,程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key=P2^0;
uchar num=0;
//共阴数码管七段码
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==20)num=0;
}
}
P0=table[num%10];
P1=table[num/10];
}
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key=P2^0;
uchar num=0;
//共阴数码管七段码
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==20)num=0;
}
}
P0=table[num%10];
P1=table[num/10];
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询