劳烦各位大侠帮我瞧瞧哪里出错了((矩阵键盘控制数码.....
时间:10-02
整理:3721RD
点击:
在此先谢过了
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit mog=P2^2;
sbit r_clk=P2^3;
sbit s_clk=P2^4;
uchar code duan[]={~0x3F,~0x06,~0x5B,~0x4F,~0x66,~0x6D,~0x7D,~0x07,~0x7F,~0x6F};//此表为LED数码管段选字模
uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //此表为LED数码管位选字模
uchar num_key,num; //扫描按键计数
void delay(uchar z)
{
uchar i;
while(z--)
for(i=0;i<110;i++);
}
void send595(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
if((dat<<i)&0x80)
mog=1;
else mog=0;
s_clk=0;
s_clk=1;
}
void out595()
{
r_clk=0;
r_clk=1;
}
void disp(uchar w,uchar d)
{
send595(wei[w]);
send595(duan[d]);
out595();
}
void dispoff(void)
{
send595(0);
send595(0);
out595();
send595(0xff);
out595();
}
void scan(void)
{
P3=0xfe;
num_key=P3;
if(num_key!=0xfe)
{
delay(8);
P3=0xfe;
num_key=P3;
if(num_key!=0xfe)
switch(num_key)
{
case 0xee:num=1;break;
case 0xde:num=2;break;
case 0xbe:num=3;break;
case 0x7e:num=4;break;
}
}
else
{
P3=0xfd;
num_key=P3;
if(num_key!=0xfd)
{
delay(8);
P3=0xfd;
num_key=P3;
if(num_key!=0xfd)
switch(num_key)
{
case 0xed:num=5;break;
case 0xdd:num=6;break;
case 0xbd:num=7;break;
case 0x7d:num=8;break;
}
}
else
{
P3=0xfb;
num_key=P3;
if(num_key!=0xfb)
{
delay(8);
P3=0xfb;
num_key=P3;
if(num_key!=0xfb)
switch(num_key)
{
case 0xeb:num=9;break;
case 0xdb:num=10;break;
case 0xbb:num=11;break;
case 0x7b:num=12;break;
}
}
else
{
P3=0xf7;
num_key=P3;
if(num_key!=0xf7)
{
delay(8);
P3=0xf7;
num_key=P3;
if(num_key!=0xf7)
switch(num_key){
case 0xe7:num=13;break;
case 0xd7:num=14;break;
case 0xb7:num=15;break;
case 0x77:num=16;break;}
}
}
}
}
}
void main()
{
uchar ge,shi;
while(1)
{
scan();
ge=num%10;
shi=num/10;
dispoff();
disp(6,shi);
delay(8);
disp(7,ge) ;
delay(8);
}
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit mog=P2^2;
sbit r_clk=P2^3;
sbit s_clk=P2^4;
uchar code duan[]={~0x3F,~0x06,~0x5B,~0x4F,~0x66,~0x6D,~0x7D,~0x07,~0x7F,~0x6F};//此表为LED数码管段选字模
uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //此表为LED数码管位选字模
uchar num_key,num; //扫描按键计数
void delay(uchar z)
{
uchar i;
while(z--)
for(i=0;i<110;i++);
}
void send595(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
if((dat<<i)&0x80)
mog=1;
else mog=0;
s_clk=0;
s_clk=1;
}
void out595()
{
r_clk=0;
r_clk=1;
}
void disp(uchar w,uchar d)
{
send595(wei[w]);
send595(duan[d]);
out595();
}
void dispoff(void)
{
send595(0);
send595(0);
out595();
send595(0xff);
out595();
}
void scan(void)
{
P3=0xfe;
num_key=P3;
if(num_key!=0xfe)
{
delay(8);
P3=0xfe;
num_key=P3;
if(num_key!=0xfe)
switch(num_key)
{
case 0xee:num=1;break;
case 0xde:num=2;break;
case 0xbe:num=3;break;
case 0x7e:num=4;break;
}
}
else
{
P3=0xfd;
num_key=P3;
if(num_key!=0xfd)
{
delay(8);
P3=0xfd;
num_key=P3;
if(num_key!=0xfd)
switch(num_key)
{
case 0xed:num=5;break;
case 0xdd:num=6;break;
case 0xbd:num=7;break;
case 0x7d:num=8;break;
}
}
else
{
P3=0xfb;
num_key=P3;
if(num_key!=0xfb)
{
delay(8);
P3=0xfb;
num_key=P3;
if(num_key!=0xfb)
switch(num_key)
{
case 0xeb:num=9;break;
case 0xdb:num=10;break;
case 0xbb:num=11;break;
case 0x7b:num=12;break;
}
}
else
{
P3=0xf7;
num_key=P3;
if(num_key!=0xf7)
{
delay(8);
P3=0xf7;
num_key=P3;
if(num_key!=0xf7)
switch(num_key){
case 0xe7:num=13;break;
case 0xd7:num=14;break;
case 0xb7:num=15;break;
case 0x77:num=16;break;}
}
}
}
}
}
void main()
{
uchar ge,shi;
while(1)
{
scan();
ge=num%10;
shi=num/10;
dispoff();
disp(6,shi);
delay(8);
disp(7,ge) ;
delay(8);
}
}
把錯誤原因說出來,那麼長的程序,沒人原因花那麼多的時間給你一行一行都看過去