本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
图:数码管是共阴,但打开完全不亮。
我试过,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);
- }
复制代码 |
|