|
- #include<reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit LSA=P2^2;
- sbit LSB=P2^3;
- sbit LSC=P2^4;
- sbit key_k1=P3^1;
- sbit key_k2=P3^0;
- sbit key_k3=P3^2;
- sbit key_k4=P3^3;
- uchar i,count;
- uchar code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- void delayms(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void init()
- {
- P0=0x00;
- P0=smgduan[i];
- LSA=0;LSB=0;LSC=0;
- delayms(5);
- P0=0x00;
- P0=smgduan[i];
- LSA=1;LSB=0;LSC=0;
- delayms(5);
- P0=0x00;
- P0=smgduan[i];
- LSA=0;LSB=1;LSC=0;
- delayms(5);
- P0=0x00;
- P0=smgduan[i];
- LSA=1;LSB=1;LSC=0;
- delayms(5);
- TMOD=0x01;//定时器0,工作模式1
- TH0=(65535-45872)/256;
- TL0=(65535-45872)%256;
- TR0=0;//启动定时器0
- }
- void main()
- {
- init();
- while(1)
- {
- if(TF0==1)
- {
- TF0=0;
- TH0=(65535-45872)/256;
- TL0=(65535-45872)%256;
- count++;
- }
- if(count==2)
- {
- count=0;
- i++;
- if(i>15)
- i=0;
- }
- if(key_k1==0)
- {
- delayms(5);
- if(key_k1==0)
- {
- TR0=1; //启动定时器0
- }
- while(!key_k1);
- }
- if(key_k2==0)
- {
- delayms(5);
- if(key_k2==0)
- {
- TR0=0; //停止定时器0
- }
- while(!key_k2);
- }
- }
- }
复制代码 |
|