你的位码不对
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define LEDPort P0
- uchar code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00}; //数码管段码选表
- uchar code wei[] ={0xFE ,0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F}; //数码管位码
- sbit DU = P2^0;
- sbit WE = P2^1;
- void delay(int z)
- {
- int x,y;
- for(x=50;x>0;x--)
- for(y=z;y>0;y--);
- }
- void main()
- {
- while(1)
- {
- WE = 1;
- LEDPort = wei[0];
- WE = 0;
- DU = 1;
- LEDPort = duan[ 1];
- DU = 0;
- delay(2);
-
- WE = 1;
- LEDPort = wei[1];
- WE = 0;
- DU = 1;
- LEDPort = duan[ 2 ];
- DU = 0;
- delay(2);
-
- WE = 1;
- LEDPort = wei[2];
- WE = 0;
- DU = 1;
- LEDPort = duan[ 3];
- DU = 0;
- delay(2);
-
- WE = 1;
- LEDPort = wei[3];
- WE = 0;
- DU = 1;
- LEDPort = duan[ 4];
- DU = 0;
- delay(2);
-
- WE = 1;
- LEDPort = wei[4];
- WE = 0;
- DU = 1;
- LEDPort = duan[ 5 ];
- DU = 0;
- delay(2);
-
- WE = 1;
- LEDPort = wei[5];
- WE = 0;
- DU = 1;
- LEDPort = duan[ 6];
- DU = 0;
- delay(2);
-
- WE = 1;
- LEDPort = wei[6];
- WE = 0;
- DU = 1;
- LEDPort = duan[ 7 ];
- DU = 0;
- delay(2);
-
- WE = 1;
- LEDPort = wei[7];
- WE = 0;
- DU = 1;
- LEDPort = duan[ 8];
- DU = 0;
- delay(2);
- }
- }
复制代码 |