林志财 发表于 2013-8-5 21:59
拿来主义那个给你慢慢改吧,改到合适你的
#include
#define uint unsigned int
老兄,我就是改不成才来问的,我本想用一循环右移来使位选在按下一个键后自动右移,以便在第二个数码管显示,但是就是不成功,我不知道该将这个循环右移放在哪?
这是我改的代码,劳烦看看错在哪?
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar tema[5];
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x80,0};
uint x,y;
uchar num,temp,z,n1=0,n2=0,n3=0,n4=0,h;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar keyscan()
{
P1=0xfe;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
n1=1;
temp=P1;
switch(temp)
{
case 0xee:num=1;
break;
case 0xde:num=8;
break;
case 0xbe:num=5;
break;
case 0x7e:num=2;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfd;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
n2=1;
temp=P1;
switch(temp)
{
case 0xed:num=17;
break;
case 0xdd:num=9;
break;
case 0xbd:num=6;
break;
case 0x7d:num=3;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfb;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
n3=1;
temp=P1;
switch(temp)
{
case 0xeb:num=9;
break;
case 0xdb:num=10;
break;
case 0xbb:num=7;
break;
case 0x7b:num=4;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xf7;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
n4=0;
temp=P1;
switch(temp)
{
case 0xe7:num=13;
break;
case 0xd7:num=14;
break;
case 0xb7:num=15;
break;
case 0x77:num=16;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
return num;
}
void display(uchar wan,uchar qin)
{
dula=1;
P0=table[wan-1];
dula=0;
P0=0xff;
wela=1;
P0=qin;
wela=0;
delay(1);
}
void main()
{
uchar b,i=0,n;
b=0xfe;
num=18;
while(1)
{
tema=keyscan();
n=n1+n2+n3+n4;
if(n!=0)
{
display(tema,b);
b=_cror_(b,1);
n=0;
i++;
}
}
} |