找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2941|回復: 0
打印 上一主題 下一主題
收起左側

led亮度溫控風扇系統(tǒng)源程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:215105 發(fā)表于 2017-6-28 15:08 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式


單片機源程序如下:
  1. #include "ds18b20.h"
  2. #include "smg.h"
  3. #include "eepom52.h"
  4. #include"motor_pwm.h"

  5. sbit Reduc  = P3^3;         //減
  6. sbit Add = P3^4;         //加
  7. sbit Mode = P3^5;         //設置

  8. sbit fs = P3^6;
  9. uchar m=0;
  10. uint time_when=0,time_points=0,time_seconds=0,time_100ms=0;
  11. void Timer0Init(void)                //1000微秒@12.000MHz
  12. {
  13.         TMOD |= 0x01;                //設置定時器模式
  14.         TL0 = 0x80;                //設置定時初值
  15.         TH0 = 0xD8;                //設置定時初值
  16.     TR0 = 1;                        //timer0 start running
  17.     ET0 = 1;                        //enable timer0 interrupt
  18.     EA = 1;                         //open global interrupt switch
  19. }
  20. void tm0_isr() interrupt 1 using 1
  21. {
  22.         TL0 = 0x80;                //設置定時初值
  23.         TH0 = 0xD8;                //設置定時初值
  24.         time_100ms++;
  25.         if (time_100ms==99)
  26.     {  
  27.                 time_100ms = 0;
  28.                 time_seconds++;
  29.                 m=~m;      
  30.                 if (time_seconds==60)
  31.             {                       
  32.                         time_seconds=0;
  33.                 time_points++;      
  34.                         if (time_points==60)
  35.                     {
  36.                         time_points=0;
  37.                         time_when++;      
  38.                                 if (time_when==24)
  39.                             {
  40.                                 TR0 = 0;
  41.                             }
  42.                     }
  43.             }     
  44.     }       
  45. }


  46. void main(void)
  47. {       
  48.         uint T_tada;//溫度數(shù)據(jù)變量
  49.         char T_L=2,T_H=0;
  50.         uchar Mode_project=1,key_count=0;//設置變量
  51.         uint disp_count=300;//顯示300次采集一次溫度數(shù)據(jù),解決采集時閃爍               
  52.         uchar temp_disp[4];//數(shù)據(jù)緩存
  53.         /****DS18B20檢測,沒有檢測到數(shù)碼管顯示四個‘----’****/                
  54.         while(reset())
  55.         {
  56.                 disp_count=100;while(disp_count--){SMG_setxy(1,11,0);SMG_setxy(2,11,0);SMG_setxy(3,11,0);SMG_setxy(4,11,0);}
  57.                 disp_count=100;while(disp_count--){SMG_setxy(1,10,0);SMG_setxy(2,10,0);SMG_setxy(3,10,0);SMG_setxy(4,10,0);}
  58.         }
  59.         /****開機采集溫度,避免第一次讀取溫度為85度誤報警****/
  60.         disp_count=30;
  61.         while(disp_count--)
  62.         {

  63.                 T_tada=read_temp();
  64.         }
  65.         /***開機把數(shù)據(jù)從單片機內(nèi)部eepom中讀出來***/
  66.         if(byte_read(0x2050)!=0)
  67.         {               
  68.                 SectorErase(0x2000);
  69.                 byte_write(0x2000,T_L);
  70.                 byte_write(0x2001,T_H);
  71.                 byte_write(0x2050,1);               
  72.         }
  73.         if(byte_read(0x2050)==1)
  74.         {
  75.                 T_L=byte_read(0x2000);
  76.                 T_H=byte_read(0x2001);
  77.         }
  78.         Timer0Init();
  79.         pwm_init();       
  80.         while(1)
  81.         {
  82.                 temp_disp[0]=time_when/10;
  83.                 temp_disp[1]=time_when%10;

  84.                 temp_disp[2]=time_points/10;
  85.                 temp_disp[3]=time_points%10;

  86.                 /*******加速*******/
  87.                 if(Add==0)
  88.                 {       
  89.                         //利用顯示延時
  90.                         key_count=60;
  91.                         while(key_count--)
  92.                         {
  93.                                 SMG_setxy(1,temp_disp[0],0);
  94.                                 SMG_setxy(2,temp_disp[1],m);
  95.                                 SMG_setxy(3,temp_disp[2],0);
  96.                                 SMG_setxy(4,temp_disp[3],0);
  97.                         }
  98.                         speed+=5;
  99.                         if(speed>=100)speed=100;
  100.                 }
  101.                 /*******減速*******/
  102.                 if(Reduc==0)
  103.                 {
  104.                         //利用顯示延時
  105.                         key_count=60;
  106.                         while(key_count--)
  107.                         {
  108.                                 SMG_setxy(1,temp_disp[0],0);
  109.                                 SMG_setxy(2,temp_disp[1],m);
  110.                                 SMG_setxy(3,temp_disp[2],0);
  111.                                 SMG_setxy(4,temp_disp[3],0);
  112.                         }
  113.                         speed-=5;
  114.                         if(speed<=0)speed=0;
  115.                 }
  116.                 if(T_tada>3500)//溫度大于35度,打開風扇
  117.                 {
  118.                         fs=1;
  119.                 }
  120.                 else
  121.                 {
  122.                         fs=0;
  123.                 }

  124.                 if(T_H==time_when && T_L==time_points && time_seconds<0x01)
  125.                 {
  126.                         EA=0;
  127.                         M1=0;       
  128.                 }
  129. //                temp_disp[2]=time_seconds/10;
  130. //                temp_disp[3]=time_seconds%10;

  131.                 /****溫度數(shù)據(jù)采集****/
  132.                 loop:
  133.                 if(++disp_count>=3000)
  134.                 {
  135.                         disp_count=0;
  136.                         TR1=0;T_tada=read_temp();if(speed==0)TR1=1;
  137. //                        if(T_tada>20000)//負數(shù)
  138. //                        {
  139. //                                temp_disp[0]=11;
  140. //                                T_tada-=20000;
  141. //                        }
  142. //                        else temp_disp[0]=T_tada/10000; //正數(shù)溫度百位        
  143. //                                       
  144. //                        temp_disp[1]=T_tada/1000%10; //溫度十位
  145. //                        temp_disp[2]=T_tada/100%10;//溫度個位
  146. //                        temp_disp[3]=T_tada/10%10;//溫度小數(shù)第一位
  147. //                        if(temp_disp[0]==0)temp_disp[0]=10;//百位消隱
  148.                 }
  149.                 /****數(shù)碼管掃描顯示****/               
  150.                 SMG_setxy(1,temp_disp[0],0);
  151.                 SMG_setxy(2,temp_disp[1],m);
  152.                 SMG_setxy(3,temp_disp[2],0);
  153.                 SMG_setxy(4,temp_disp[3],0);
  154.                
  155.                 /****按下設置鍵,設置參數(shù)****/
  156.                 if(Mode==0)
  157.                 {                         
  158.                         Mode_project=1;
  159.                         while(Mode==0);//按鍵松開                       
  160.                         while(1)
  161.                         {
  162.                                 //設置頁面顯示
  163.                                 switch(Mode_project)
  164.                                 {
  165.                                         case 1:
  166.                                                 SMG_setxy(1,12,0);
  167.                                                 SMG_setxy(2,11,0);
  168.                                                 SMG_setxy(3,T_H/10,0);
  169.                                                 SMG_setxy(4,T_H%10,0);
  170.                                         break;
  171.                                         case 2:
  172.                                                 SMG_setxy(1,13,0);
  173.                                                 SMG_setxy(2,11,0);
  174.                                                 SMG_setxy(3,T_L/10,0);
  175.                                                 SMG_setxy(4,T_L%10,0);
  176.                                         break;
  177.                                 }
  178.                                 //按下加鍵,對設定目標加
  179.                                 if(Add==0)
  180.                                 {
  181.                                         //利用顯示延時
  182.                                         key_count=60;
  183.                                         while(key_count--)
  184.                                         {
  185.                                                 switch(Mode_project)
  186.                                                 {
  187.                                                         case 1:
  188.                                                                 SMG_setxy(1,12,0);
  189.                                                                 SMG_setxy(2,11,0);
  190.                                                                 SMG_setxy(3,T_H/10,0);
  191.                                                                 SMG_setxy(4,T_H%10,0);
  192.                                                         break;
  193.                                                         case 2:
  194.                                                                 SMG_setxy(1,13,0);
  195.                                                                 SMG_setxy(2,11,0);
  196.                                                                 SMG_setxy(3,T_L/10,0);
  197.                                                                 SMG_setxy(4,T_L%10,0);
  198.                                                         break;
  199.                                                 }
  200.                                         }
  201.                                         switch(Mode_project)
  202.                                         {
  203.                                                 case 1:T_H+=1;if(T_H>=100)T_H=100;break;
  204.                                                 case 2:T_L+=1;if(T_L>=100)T_L=100;break;
  205.                                         }               
  206.                                 }
  207.                                 //按下減鍵,對設定目標減
  208.                                 if(Reduc==0)
  209.                                 {
  210.                                         //利用顯示延時
  211.                                         key_count=60;
  212.                                         while(key_count--)
  213.                                         {
  214.                                                 switch(Mode_project)
  215.                                                 {
  216.                                                         case 1:
  217.                                                                 SMG_setxy(1,12,0);
  218.                                                                 SMG_setxy(2,11,0);
  219.                                                                 SMG_setxy(3,T_H/10,0);
  220.                                                                 SMG_setxy(4,T_H%10,0);
  221.                                                         break;
  222.                                                         case 2:
  223.                                                                 SMG_setxy(1,13,0);
  224.                                                                 SMG_setxy(2,11,0);
  225. ……………………

  226. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
程序.rar (48.04 KB, 下載次數(shù): 16)




分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表