本帖最后由 白沙漠之鹰 于 2012-3-31 15:20 编辑
显示中有两位数码管显示重叠了,不知怎么才能正常显示。望各位大侠帮帮忙..电路中使用3个74ls374锁存器,两个锁存位码,前八和后六。一个锁存断码,用138进行锁存器位选。
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned char
sbit C1=P2^7;
sbit B1=P2^6;
sbit A1=P2^5;
sbit To=P3^4;
sbit KEY=P3^5;
sbit W=P3^6;
sbit SCL=P3^2;
sbit SDA=P3^3;
uchar code DSY_CODE[]= //断码
{
0xc0,
0xf9,
0xa4,
0xb0,
0x99,
0x92,
0x82,
0xf8,
0x80,
0x90,
0x88,
0x83,
0xC6,
0xA1,
0x86,
0x8E,
};
void Delay() //延时0.5ms
{
uchar a,b,c;
for(a=0;a<5;a++)
for(b=0;b<1;b++)
for(c=0;c<63;c++);
}
void main()
{
uchar i,wei;
P0=0xff;
P1=0xff;
P2=0x00;
P3=0xff;
IE=0x00;
while(1)
{
SDA=0;
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1;
To=0;
for(i=0;i<16;i++)
{
switch(i)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
//选通锁存器2给断码
W=0;
C1=0;
B1=1;
A1=1;
P0=DSY_CODE[5];
//选通锁存器1给位码
C1=0;
B1=1;
A1=0;
wei=DSY_IDX;
wei=_crol_(wei,1);
P0=wei;
Delay();
break;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
W=0;
//选通锁存器2给段码
C1=0;
B1=1;
A1=1;
P0=DSY_CODE[1+Keynum2];
//选通锁存器3给位码
C1=0;
B1=0;
A1=1;
wei=DSY_IDX[i-8];
wei=_crol_(wei,1);
P0=wei;
Delay();
break;
}
}
}
} |