你这个端口定义写法是错误的,两个IO口控制4个位选也不是简单取反就能完成。两个IO口可以组成4种状态,是BCD码,用BCD码/十进制译码器CD4028 就能完美解决,为什么非得要用非门?
- #include <reg51.h>
- sbit wela1=P3^3;
- sbit wela2=P3^4;
- unsigned char code table[]={//共阳数码管段码"0~f-."
- 0xc0,0xf9,0xa4,0xb0,
- 0x99,0x92,0x82,0xf8,
- 0x80,0x90,0x88,0x83,
- 0xc6,0xa1,0x86,0x8e,0xbf,0x7f};
- void delay(unsigned int k)
- {
- unsigned int i,j;
- for(i=k;i>0;i--)
- for(j=120;j>0;j--);
- }
- void main()
- {
- while(1)
- {
- P0=0xff; //消隐
- wela1=0; //位选
- wela2=0; //位选
- P0=table[1];//段码
- delay(2); //延时
- P0=0xff;
- wela1=1;
- wela2=0;
- P0=table[2];
- delay(2);
- P0=0xff;
- wela1=0;
- wela2=1;
- P0=table[3];
- delay(2);
- P0=0xff;
- wela1=1;
- wela2=1;
- P0=table[4];
- delay(2);
- }
- }
复制代码
|