重新提问:51单片机四位数码管,不用锁存器,怎么写?
图:数码管是共阴,但打开完全不亮。
我试过,display函数如果写成wela=1再给P0赋值再wela=0屏幕能有显示,
但1234会显示成4123!而wela1,即P2^4确实控制1。
这样。到底显示函数应该怎么写呢?谢谢各位!
#include<reg52.h>
unsigned char clear = 0xff;
sbit wela1 = P2^4;
sbit wela2 = P2^5;
sbit wela3 = P2^6;
sbit wela4 = P2^7;
unsigned char code table[] = {0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};
void delay(int z)
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display( char one,char two,char three,char four )
{
wela1 = wela2 = wela3 = wela4 = 1;
wela1 = 0;
P0 = clear;
P0 = table[one];
wela1 = 1;
delay(5);
wela2 = 0;
P0 = clear;
P0 = table[two];
wela2 = 1;
delay(5);
wela3 = 0;
P0 = clear;
P0 = table[three];
wela3 = 1;
delay(5);
wela4 = 0;
P0 = clear;
P0 = table[four];
wela4 = 1;
delay(5);
}
void main()
{
display(1,2,3,4);
}
wela3 = 0;
P0 = clear;
P0 = table[three];
delay(5);
wela3 = 1;
wela4 = 0;
P0 = clear;
P0 = table[four];
delay(5);
wela4 = 1;}
[其他解释]
顶起来……谢谢各位高手!!
[其他解释]
谢谢!我明白了,
P0 = clear;
P0 = table[four];
wela4 = 0;
delay(5);
wela4 = 1;
只要位选打开的时间有个延时。
这样也可以。
如果用锁存器,是给了锁存器值,这时候不用延时直接关闭,因为有锁存器也没影响。
[其他解释]
可以把程序发给我吗?357700682@qq.com谢谢