从黑体的地方开始,我想通过矩阵键盘控制数码管显示0-15,但是不知道怎么搞两位数的显示,是不是延时什么的有问题
#include
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();
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款