一个独立按键控制数码管动态显示程序亮灭c语言
求:一个独立按键控制数码管动态显示程序亮灭c语言,按下松开数码管就显示动态0~9999,再按下就关不显示了...
求:一个独立按键控制数码管动态显示程序亮灭c语言,按下松开数码管就显示动态0~9999,再按下就关不显示了
展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
展开全部
有点类似,你看看吧:
#include<reg52.h>
#include<intrins.h> //反转法控制按键
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar a,b,c,d,keya,keyb;
uint e;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uint x) //延时
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void shumaguan(uchar a) //数码管
{
wela=1;
P0=0xc0;
wela=0;
dula=1;
P0=table[a]; //a在键盘函数引用
dula=0;
delay(10);
}
void liushuideng() //流水灯
{
b=0xc9;
while(e>=0&&e<=80)
{
P1=b;
delay(50);
b=_crol_(b,1);
e++;
if(e==80)
b=0xff;
}
}
uchar key() //有返回值的按键函数
{
P3=0x0f; //定行
P3=P3&0x0f; //判断哪一行有被按下的键
if(P3!=0x0f)
{
delay(10);
P3=0x0f;
P3=P3&0x0f;
if(P3!=0x0f)
{
c=P3&0x0f;
P3=0xf0;
d=P3&0xf0; //判断列 ,行反转
return(c+d);
}
}
return 0xff;
}
void main()
{
while(1)
{
keyb=key();
switch(keyb)
{
case 0xee:keya=0;while(key()!=0xff);shumaguan(keya);break; //判断按键
case 0xed:keya=1;while(key()!=0xff);shumaguan(keya);break;
case 0xeb:keya=2;while(key()!=0xff);shumaguan(keya);break;
case 0xe7:keya=3;while(key()!=0xff);shumaguan(keya);break;
case 0xde:keya=4;while(key()!=0xff);shumaguan(keya);break;
case 0xdd:keya=5;while(key()!=0xff);shumaguan(keya);break;
case 0xdb:keya=6;while(key()!=0xff);shumaguan(keya);break;
case 0xd7:keya=7;while(key()!=0xff);shumaguan(keya);break;
case 0xbe:keya=8;while(key()!=0xff);shumaguan(keya);break;
case 0xbd:keya=9;while(key()!=0xff);shumaguan(keya);break;
case 0xbb:keya=10;while(key()!=0xff);shumaguan(keya);break;
case 0xb7:keya=11;while(key()!=0xff);shumaguan(keya);break;
case 0x7e:keya=12;while(key()!=0xff);shumaguan(keya);break;
case 0x7d:keya=13;while(key()!=0xff);shumaguan(keya);break;
case 0x7b:keya=14;while(key()!=0xff);shumaguan(keya);break;
case 0x77:keya=15;while(key()!=0xff);shumaguan(keya);delay(1000);liushuideng();e=0;break;
default:break;
}
}
}
#include<reg52.h>
#include<intrins.h> //反转法控制按键
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar a,b,c,d,keya,keyb;
uint e;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uint x) //延时
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void shumaguan(uchar a) //数码管
{
wela=1;
P0=0xc0;
wela=0;
dula=1;
P0=table[a]; //a在键盘函数引用
dula=0;
delay(10);
}
void liushuideng() //流水灯
{
b=0xc9;
while(e>=0&&e<=80)
{
P1=b;
delay(50);
b=_crol_(b,1);
e++;
if(e==80)
b=0xff;
}
}
uchar key() //有返回值的按键函数
{
P3=0x0f; //定行
P3=P3&0x0f; //判断哪一行有被按下的键
if(P3!=0x0f)
{
delay(10);
P3=0x0f;
P3=P3&0x0f;
if(P3!=0x0f)
{
c=P3&0x0f;
P3=0xf0;
d=P3&0xf0; //判断列 ,行反转
return(c+d);
}
}
return 0xff;
}
void main()
{
while(1)
{
keyb=key();
switch(keyb)
{
case 0xee:keya=0;while(key()!=0xff);shumaguan(keya);break; //判断按键
case 0xed:keya=1;while(key()!=0xff);shumaguan(keya);break;
case 0xeb:keya=2;while(key()!=0xff);shumaguan(keya);break;
case 0xe7:keya=3;while(key()!=0xff);shumaguan(keya);break;
case 0xde:keya=4;while(key()!=0xff);shumaguan(keya);break;
case 0xdd:keya=5;while(key()!=0xff);shumaguan(keya);break;
case 0xdb:keya=6;while(key()!=0xff);shumaguan(keya);break;
case 0xd7:keya=7;while(key()!=0xff);shumaguan(keya);break;
case 0xbe:keya=8;while(key()!=0xff);shumaguan(keya);break;
case 0xbd:keya=9;while(key()!=0xff);shumaguan(keya);break;
case 0xbb:keya=10;while(key()!=0xff);shumaguan(keya);break;
case 0xb7:keya=11;while(key()!=0xff);shumaguan(keya);break;
case 0x7e:keya=12;while(key()!=0xff);shumaguan(keya);break;
case 0x7d:keya=13;while(key()!=0xff);shumaguan(keya);break;
case 0x7b:keya=14;while(key()!=0xff);shumaguan(keya);break;
case 0x77:keya=15;while(key()!=0xff);shumaguan(keya);delay(1000);liushuideng();e=0;break;
default:break;
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
华北工控
2023-08-25 广告
2023-08-25 广告
工控主板主要应用于工业级计算机、自动化设备、通讯设备、军工设备等多个领域。在工业计算机领域,工控主板可作为工业控制系统的核心,实现数据采集、控制、管理等功能;在自动化设备领域,工控主板可作为自动化设备的控制器,实现设备的自动化运行;在通讯设...
点击进入详情页
本回答由华北工控提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询