谁帮我看看独立按键程序,不知道哪里出问题
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula = P2^6;
sbit wela = P2^7;
sbit KEY_1 = P3^7;
unsigned char leddata[]={
0x3F, //"0"
0x06, //"1"
0x5B, //"2"
0x4F, //"3"
0x66, //"4"
0x6D, //"5"
0x7D, //"6"
0x07, //"7"
0x7F, //"8"
0x6F, //"9"
};
void delay_xms(uint xms) //延时函数
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar shi,uchar ge) //显示函数
{
wela = 1;
P0 = 0xfe;
wela = 0;
P0 = 0xff;
dula = 1;
P0 = leddata[shi];
dula = 0;
delay_xms(5);
wela = 1;
P0 = 0xfd;
wela = 0;
P0 = 0xff;
dula = 1;
P0 = leddata[ge];
dula = 0;
delay_xms(5);
}
void keyscan() //按键扫描
{
uchar num,shi,ge;
if(KEY_1==0)
{
delay_xms(10);
if(KEY_1==0)
{
num++;
if(num==20)
num=0;
shi=num/10;
ge=num%10;
while(!KEY_1);
}
display(shi,ge);
}
}
void main()
{
while(1)
{
keyscan();
}
}
实现功能:用独立按键 按下数码管加1
我这样写的函数,实现不了,求解哪里的问题 谢谢大神。小白一枚
#define uint unsigned int
#define uchar unsigned char
sbit dula = P2^6;
sbit wela = P2^7;
sbit KEY_1 = P3^7;
unsigned char leddata[]={
0x3F, //"0"
0x06, //"1"
0x5B, //"2"
0x4F, //"3"
0x66, //"4"
0x6D, //"5"
0x7D, //"6"
0x07, //"7"
0x7F, //"8"
0x6F, //"9"
};
void delay_xms(uint xms) //延时函数
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar shi,uchar ge) //显示函数
{
wela = 1;
P0 = 0xfe;
wela = 0;
P0 = 0xff;
dula = 1;
P0 = leddata[shi];
dula = 0;
delay_xms(5);
wela = 1;
P0 = 0xfd;
wela = 0;
P0 = 0xff;
dula = 1;
P0 = leddata[ge];
dula = 0;
delay_xms(5);
}
void keyscan() //按键扫描
{
uchar num,shi,ge;
if(KEY_1==0)
{
delay_xms(10);
if(KEY_1==0)
{
num++;
if(num==20)
num=0;
shi=num/10;
ge=num%10;
while(!KEY_1);
}
display(shi,ge);
}
}
void main()
{
while(1)
{
keyscan();
}
}
实现功能:用独立按键 按下数码管加1
我这样写的函数,实现不了,求解哪里的问题 谢谢大神。小白一枚
数组少code,在leddata前加
你这是仿郭天祥写的吧,num没初值
你这什么现象都没有,谁知道哪边有问题
SHE和GE改为全局变量试试