各位師兄可以用到,原理圖,,仿真都有
②573驅動:
硬件構成:單片機+最小系統+數碼管顯示模塊+74HC573數碼管驅動模塊+溫度采集模塊+風扇驅動模塊+按鍵模塊
1.采用DS18B20溫度傳感器測溫,74HC573驅動數碼管,數碼管顯示溫度和風扇的檔位;
2.三個按鍵:設置、加、減。按一下設置可以設置上限,再按下設置下限,均可以按鍵加減調整;
3.利用PWM調速,當溫度低于下限時,風扇不轉動,當溫度處于上、下限之間時1檔轉動(風扇50%轉速轉動),當溫度超過上限時,全速轉動。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.png (15.29 KB, 下載次數: 40)
下載附件
2019-12-12 00:28 上傳
51hei.png (32.25 KB, 下載次數: 36)
下載附件
2019-12-12 00:29 上傳
制作出來的實物圖如下:
1正面照.jpg (93.36 KB, 下載次數: 48)
下載附件
2019-12-12 00:30 上傳
2反面照.jpg (222.82 KB, 下載次數: 37)
下載附件
2019-12-12 00:30 上傳
3正面照 帶原件介紹.jpg (166.56 KB, 下載次數: 33)
下載附件
2019-12-12 00:30 上傳
溫控風扇元件清單
1) 7*9萬用板
2) 風扇
3) STC89C51單片機
4) 74hc573
5) 40腳IC座
6) 20腳IC座
7) 0.36四位一體共陰數碼管
8) 10k電阻*2
9) 1k電阻*2
10) 103排阻
11) DS18B20
12) 10uf電容
13) 11.0592M晶振
14) 30pf瓷片電容*2
15) 9012三極管
16) 2p排針
17) 按鍵*3
18) DC電源接口
19) 自鎖開關
20) 導線若干
21) 焊錫若干
22) 電源線或電池盒+DC電源插頭
單片機源程序如下:
- #include <reg52.h>
- #include <stdio.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit ds=P3^6;
- sbit w1=P2^4;
- sbit w2=P2^5;
- sbit w3=P2^6;
- sbit w4=P2^7; //數碼管的位選端
- sbit dp=P0^7;
- sbit fm=P3^7;
- sbit key_shezhi=P1^5;
- sbit key_jia=P1^6;
- sbit key_jian=P1^7;
- uchar flag_0;
- uint t_max=250,t_max_1=300;
- uint count=0;
- int wendu,t;
- void delay(uint z) //延時函數
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- /********************************/
- void pro()
- {
- if(key_shezhi==0)
- {
- delay(10);
- if(key_shezhi==0)
- {
- flag_0++;
- if(flag_0>=3)
- flag_0=0;
- while(!key_shezhi) ;
- }
- }
- }
- /**********************************/
- uchar code table[]={
- 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x40
- };
- uchar code table1[]={
- 0x38,0x76
- };
- uint temp,mm;uchar i;float f_temp;
- /*******************************************************
- 溫度函數
- *******************************************************/
- void dsreset(void) //下邊是溫度獲取子程序
- {
- uint i;
- ds=0;
- i=103;
- while(i>0)i--;
- ds=1;
- i=4;
- while(i>0)i--;
- }
- bit tempreadbit(void) //讀一位
- {
- uint i;
- bit dat;
- ds=0;i++;
- ds=1;i++;i++;
- dat=ds;
- i=8;while(i>0)i--;
- return(dat);
- }
- uchar tempread(void) //獲取溫度
- {
- uchar i,j,dat;
- dat=0;
- for(i=1;i<=8;i++)
- {
- j=tempreadbit();
- dat=(j<<7)|(dat>>1);
- }
- return(dat);
- }
- void tempwritebyte(uchar dat) //寫一個字節
- {
- uint i;
- uchar j;
- bit testb;
- for(j=1;j<=8;j++)
- {
- testb=dat&0x01;
- dat=dat>>1;
- if(testb)
- {
- ds=0;
- i++;i++;
- ds=1;
- i=8;while(i>0)i--;
- }
- else
- {
- ds=0;
- i=8;while(i>0)i--;
- ds=1;
- i++;i++;
- }
- }
- }
- void tempchange(void) //溫度轉換
- {
- dsreset();
- delay(1);
- tempwritebyte(0xcc);
- tempwritebyte(0x44);
- }
- uint get_temp() //獲取溫度
- {
- uchar a,b;
- dsreset();
- delay(1);
- tempwritebyte(0xcc);
- tempwritebyte(0xbe);
- a=tempread();
- b=tempread();
- temp=b;
- temp<<=8;
- temp=temp|a;
- f_temp=temp*0.0625;
- temp=f_temp*10+0.5;
- f_temp=f_temp+0.05;
- return temp;
- }
- /***********************************/
- void display0()
- {
- P0=0x00;
- w1=0;
- P0=0x00;
- delay(2);
- w1=1;
-
- P0=0x00;
- w2=0;
- P0=table[wendu/100];
- delay(2);
- w2=1;
-
- P0=0x00;
- w3=0;
- P0=table[wendu%100/10];
- dp=1;
- delay(2);
- w3=1;
-
- P0=0x00;
- w4=0;
- P0=table[wendu%10];
- delay(2);
- w4=1;
- }
- /***************************************/
- void baojing()
- {
- count++;
- if(count>=3)
- count=0;
- if(wendu>=t_max&&wendu<t_max_1)
- {
- if(count<2) //只有三分之二的時間會給風扇供電
- fm=0;
- else
- fm=1;
- }
- else if(wendu>=t_max_1) //高于設定的最高溫度, 全速轉動
- {
- fm=0;
- }
- else //高于設定的次級溫度,緩慢轉動
- {
- fm=1;
- }
- }
- /**************************************/
- /**************************************/
- void display1()
- {
- P0=0x00;
- w1=0;
- P0=table1[0];
- delay(2);
- w1=1;
-
- P0=0x00;
- w2=0;
- P0=table[t_max/100];
- delay(2);
- w2=1;
-
- P0=0x00;
- w3=0;
- P0=table[t_max%100/10];
- dp=1;
- delay(2);
- w3=1;
-
- P0=0x00;
- w4=0;
- P0=table[t_max%10];
- delay(2);
- w4=1;
- }
- /**************************************/
- void display2()
- {
- P0=0x00;
- w1=0;
- P0=table1[1];
- delay(2);
- w1=1;
-
- P0=0x00;
- w2=0;
- P0=table[t_max_1/100];
- delay(2);
- w2=1;
-
- P0=0x00;
- w3=0;
- P0=table[t_max_1%100/10];
- dp=1;
- delay(2);
- w3=1;
-
- P0=0x00;
- w4=0;
- P0=table[t_max_1%10];
- delay(2);
- w4=1;
- }
- /***************************************/
- void shezhi()
- {
- if(flag_0==1)
- {
- if(key_jia==0)
- {
- delay(10);
- if(key_jia==0)
- {
- t_max=t_max+5;
- if(t_max>=t_max_1) //防止低溫度高于高溫度
- t_max=t_max_1-5;
- while(!key_jia);
- }
- }
- if(key_jian==0)
- {
- delay(10);
- if(key_jian==0)
- {
- t_max=t_max-5;
- while(!key_jian);
- }
- }
- }
- if(flag_0==2)
- {
- if(key_jia==0)
- {
- delay(10);
- if(key_jia==0)
- {
- t_max_1=t_max_1+5;
- while(!key_jia);
- }
- }
- if(key_jian==0)
- {
- delay(10);
- if(key_jian==0)
- {
- t_max_1=t_max_1-5;
- if(t_max_1<=t_max) //防止高溫度小于低溫度
- t_max_1=t_max+5;
- while(!key_jian);
- }
- }
- }
- }
- void display()
- {
- if(flag_0==0)
- display0();
- else if(flag_0==1)
- display1();
- else if(flag_0==2)
- display2();
- }
- void main()
- {
- while(1)
- {
- tempchange();
- t=get_temp();
- if(t>=0&&t<=1250) //溫度合法范圍,不在這個范圍就是沒有獲取到合適的值
- {
- wendu=t;
- }
- pro();
- display();
- shezhi();
- baojing();
- }
- }
復制代碼
所有資料51hei提供下載:
溫度風扇74HC573+.7z
(869.48 KB, 下載次數: 62)
2019-12-12 00:31 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|