|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
从黑体的地方开始,我想通过矩阵键盘控制数码管显示0-15,但是不知道怎么搞两位数的显示,是不是延时什么的有问题
#include <REGX52.H>
sfr P4 = 0xC0;
unsigned char code duanma[18]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc0,0x86,0x8e,0xbf,0x7f};
sbit R1 = P3^0;
sbit R2 = P3^1;
sbit R3 = P3^2;
sbit R4 = P3^3;
sbit C1 = P3^4;
sbit C2 = P3^5;
sbit C3 = P4^2;
sbit C4 = P4^4;
void HC573(unsigned char one)
{
switch(one)
{
case 4:
P2 = (P2 & 0x1f) | 0X80;
break;
case 5:
P2 = (P2 & 0x1f) | 0xa0;
break;
case 6:
P2 = (P2 & 0X1f) | 0Xc0;
break;
case 7:
P2 = (P2 & 0X1f) | 0Xe0;
break;
}
}
void Delay(unsigned char t)
{
while(t--);
}
void SHUMA(unsigned char two, unsigned char thr )
{
HC573(6);
P0 = 0x01 << thr;
HC573(7);
P0 = two;
}
unsigned char num = 0, yum = 0;
void Juzhen()
{
C1 = 0; C2 = C3 = C4 = 1;
R1 = R2 = R3 = R4 = 1;
if(R1 == 0)
{
while(R1 == 0);
num =0 ;
SHUMA(duanma[num],1);
}
else if(R2 == 0)
{
while(R2 == 0);
num = 1 ;
SHUMA(duanma[num],1);
}
else if(R3 == 0)
{
while(R3 == 0);
num = 2;
SHUMA(duanma[num],1);
}
else if(R4 == 0)
{
while(R4 == 0);
num = 3;
SHUMA(duanma[num],1);
}
C2 = 0; C1 = C3 = C4 = 1;
R1 = R2 = R3 = R4 = 1;
if(R1 == 0)
{
while(R1 == 0);
num = 4;
SHUMA(duanma[num],1);
}
else if(R2 == 0)
{
while(R2 == 0);
num = 5;
SHUMA(duanma[num],1);
}
else if(R3 == 0)
{
while(R3 == 0);
num = 6;
SHUMA(duanma[num],1);
}
else if(R4 == 0)
{
while(R4 == 0);
num = 7;
SHUMA(duanma[num],1);
}
C3 = 0; C2 = C1 = C4 = 1;
R1 = R2 = R3 = R4 = 1;
if(R1 == 0)
{
while(R1 == 0);
num = 8;
SHUMA(duanma[num],1);
}
else if(R2 == 0)
{
while(R2 == 0);
num = 9;
SHUMA(duanma[num],1);
}
else if(R3 == 0)
{
while(R3 == 0);
num = 0 , yum = 1;
SHUMA(duanma[num],1);
Delay(100);
SHUMA(duanma[yum],0);
Delay(100);
}
else if(R4 == 0)
{
while(R4 == 0);
num = 1,yum = 1 ;
SHUMA(duanma[num],1);
Delay(100);
SHUMA(duanma[yum],0);
while(R4 == 0);
}
C4 = 0; C2 = C3 = C1 = 1;
R1 = R2 = R3 = R4 = 1;
if(R1 == 0)
{
while(R1 == 0);
num = 2,yum = 1 ;
SHUMA(duanma[num],1);
Delay(500);
SHUMA(duanma[yum],0);
}
else if(R2 == 0)
{
while(R2 == 0);
num = 3,yum = 1 ;
SHUMA(duanma[num],1);
Delay(500);
SHUMA(duanma[yum],0);
}
else if(R3 == 0)
{
while(R3 == 0);
num = 4,yum = 1 ;
SHUMA(duanma[num],1);
Delay(500);
SHUMA(duanma[yum],0);
}
else if(R4 == 0)
{
while(R4 == 0);
num = 5 ,yum = 1;
SHUMA(duanma[num],1);
Delay(500);
SHUMA(duanma[yum],0);
}
}
void main()
{
while(1)
{
Juzhen();
}
}
猜一下,
我看你这个代码好像不是直接用管脚直接驱动,
HC573是不是一个有缓存的驱动芯片啊,那样的话要显示两位数字,要把两个数字都存进去再显示,而不是先显示十位再显示个位
还有就是delay(100)这个是delay了100个指令周期,非常快,这点要注意,时间够不够要查看时序,如果前面显示1位数字正常,这个delay好像也没什么用处
还有一个 while(R4 == 0); 这个东西是不能按键除颤的,你的输入会很不稳定,可能按了一次5,出了5555
|
|