- #include<reg52.h>
- typedef unsigned char uchar;
- typedef unsigned int uint;
- sbit LSA = P2^2;
- sbit LSB = P2^3;
- sbit LSC = P2^4;
- uchar time [] ={2,0,2,0,1,1,0,7};
- uchar code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//显示0~F的值
-
- //延时函数,i=1;延时大约等于1us
- void delay(uint i)
- {
- while(i--);
- }
- void DigDisplay()
- {
- uchar i;
- for(i= 0 ; i<8;i++)
- {
- switch(i)
- {
- case 7:
- LSA=0; LSB=0; LSC=0; break; //显示1位;
- case 6:
- LSA=1; LSB=0; LSC=0; break;//显示2位;
- case 5:
- LSA=0; LSB=1; LSC = 0;break;//显示3位
- case 4:
- LSA=1; LSB=1; LSC=0; break; //显示4位;
- case 3:
- LSA=0; LSB=0; LSC=1; break;//显示5位;
- case 2:
- LSA=1; LSB=0; LSC =1;break;//显示6位
- case 1:
- LSA=0; LSB=1; LSC=1; break; //显示7位;
- case 0:
- LSA=1; LSB=1; LSC=1; break;//显示8位;
- }
- P0 = smgduan[time[i]];
- delay(10000);
- P0 = 0X00;
- }
- }
- void main ()
- {
- while(1)
- {
- DigDisplay();
- }
- }
复制代码 |