这张是显示的图纸!
单片机源程序如下:- #include<reg52.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit led1=P3^3;
- sbit led=P1^5;
- sbit led2=P3^6;
- sbit fan=P1^6;
- sbit ptc=P3^4;
- sbit we1=P2^6;
- sbit we2=P2^7;
- sbit we3=P2^1;
- sbit we4=P2^0;
- sbit we5=P2^2;
- sbit fm=P2^5;
- sbit sw1=P1^0;
- sbit sw2=P1^4;
- sbit sw3=P3^5;
- sbit sw4=P3^7;
- uchar code duma[]={0x3f,0x06,0x5b,0x4f,
- 0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,
- 0x39,0x5e,0x79,0x71
- };
-
-
- uchar counter, time,time_counter, h;
-
-
-
- uchar i ;
- void delay(uint z);
- void delay(uint z)
- {
- while (z--);
- }
- void display(uchar mshi,mge,sge,sshi,hge,hshi )
- {
- mge=time_counter%10;
- mshi=time_counter/10;
- sge=time/10;
- sshi=time%10;
- hge=h/10;
- hshi=h%10;
- P0=0XFF;
- we2=0;
- P0=duma[mshi];
- delay(100);
- P0=0XFF;
- we1=0;
- P0=duma[mge];
- delay(100);
- P0=0XFF;
- we4=0;
- P0=duma[sshi];
- delay(100);
- P0=0XFF;
- we3=0;
- P0=duma[sge];
- delay(100);
- /* P0=0XFF;
- wea=0;
- web=0;
- wec=1;
- P0=duma[hge];
- delay(100);
- P0=0XFF;
- wea=1;
- web=0;
- wec=1;
- P0=duma[hshi];
- delay(100);*/
- }
- void keypros()
- {
- if(sw1==0)
- {
- delay(10);
- if(sw1==0&&time!=60)
- {
- time+=1;
-
- while(!sw1);
- }
- }
- if(sw2==0)
- {
- delay(10);
- if(sw2==0&&time!=0)
- {
- time-=1;
-
- while(!sw2);
- }
- }
- if(sw3==0)
- {
- delay(10);
- if(sw3==0)
- {
- TR1=0;
- led=1;
- time=0;
- time_counter=0;
-
-
- fan=1;
- ptc=1;
- while(!sw3);
-
- }
-
-
-
- }
- if(sw4==0)
- {
- delay(10);
-
- if(sw4==0)
- {
- TR1=~TR1;
- led=~led;
-
-
- ptc=~ptc;
- fan=~fan;
- while(!sw4);
- }
-
- }
- }
- void init()
- {
- TMOD=0x10;
- TH1=0x4b;
- TL1=0x00;
- TR1=0;
- }
- void main()
- {
-
- init();
- led2=0;
-
- while(1)
- {
- keypros();
-
- if(TF1==1)
- { TF1=0;
- TH1=0x4b;
- TL1=0x00;
- counter++;
- }
- if(counter==20)
- {
- counter=0;
- time_counter++;
- led1=~led1;
- }
- if(time_counter==60)
- {
- time--;
- time_counter=0;
-
- }
- if(time==0)
- {
- TR1=0;
- led=1;
- led1=1;
- ptc=1;
- fan=1;
- time=60;
-
- }
- display();
- }
-
-
- }
复制代码
|