- #include<reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit key1=P3^4;
- sbit D1=P1^0;
- sbit dula=P2^6;
- sbit wela=P2^7;
- void delay(uint z);
- void display(uchar num);
- uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar temp=0;
- void main()
- {
- wela=1; //单个数码管一直保持选通状态。
- P0=0xdf;
- wela=0;
- P1=0xff;
- key1=1;
- while(1)
- {
- display(temp);
- if(key1==0)
- {
- delay(9);
- if(key1==0)
- {
- D1=0;
- temp++;
- if(temp==10)
- {
- temp=0;
- }
- while(!key1); //关键语句,只要按着按键,就不会退出if检测语句
- }
- }
- else
- D1=1;
- }
- }
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- {
- for(y=110;y>0;y--);
- }
- }
- void display(uchar num)
- {
- dula=1;
- P0=table[num];
- dula=0;
- delay(10);
- }
|