久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 7063|回復: 10
打印 上一主題 下一主題
收起左側(cè)

51單片機PM2.5室內(nèi)環(huán)境檢測儀源程序+PCB文件 還有時鐘+溫濕度功能

  [復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:238191 發(fā)表于 2018-3-25 19:54 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
Altium Designer畫的時鐘+溫濕度+PM2.5檢測系統(tǒng)PCB圖如下:(51hei附件中可下載工程文件)



單片機源程序如下:
  1. /*************************************
  2. 環(huán)境檢測系統(tǒng)
  3. 主要功能及硬件:
  4. 1、功能:環(huán)境時鐘的顯示和調(diào)整,
  5.    硬件:DS1302
  6. 2、功能:溫度(單位℃)和濕度(單位H%)顯示
  7.    硬件:DHT22
  8. 3、功能:PM2.5(單位ug/m3)顯示
  9.    硬件:ZPH11
  10. 屏幕:12864B(自帶字庫)
  11. 說明:
  12.     大家好,我叫小木(^_^)·
  13. *************************************/
  14. #include<reg51.h>
  15. #include<lcd12864.h>
  16. #include<ds1302.h>

  17. void showtime();
  18. void showweek();
  19. void showweek1();
  20. void showTH();
  21. void showPM();
  22. void Usartinit();
  23. unsigned char Read_SensorData(void);
  24. unsigned char Read_Sensor(void);
  25. void Delay_N10us(unsigned char t);
  26. void Delay_N1ms(unsigned int t);
  27. void form1();
  28. void form2();
  29. void data1();
  30. void clearping();
  31. void Hgarden(int x);//空心圓
  32. void Sgarden(int x);//實心圓
  33. void timesetting(int x);


  34. /********************************************
  35. 界面文字顯示
  36. ********************************************/
  37. //第1界面顯示
  38. unsigned char code CharCode[13]="0123456789.-:";
  39. unsigned char code Temperature[]="溫度:";
  40. unsigned char code Tsign[]="℃";
  41. unsigned char code Humidity[]="濕度:";
  42. unsigned char code Hsign[]="RH";
  43. unsigned char code PM1[]="PM2.5:";
  44. unsigned char code TPM1[]="ug/m3";

  45. //第2界面顯示
  46. unsigned char code year1[]="年";
  47. unsigned char code mouth1[]="月";
  48. unsigned char code day1[]="日";
  49. unsigned char code hour1[]="時";
  50. unsigned char code minute1[]="分";
  51. unsigned char code second1[]="秒";
  52. unsigned char code week3[]="周";
  53. unsigned char code week1[]="星期";

  54. //清屏
  55. unsigned char code clear[]="                ";

  56. unsigned char code week2_0[]="日";
  57. unsigned char code week2_1[]="一";
  58. unsigned char code week2_2[]="二";
  59. unsigned char code week2_3[]="三";
  60. unsigned char code week2_4[]="四";
  61. unsigned char code week2_5[]="五";
  62. unsigned char code week2_6[]="六";
  63. unsigned int  flagkeyup_down=1;
  64. unsigned int page=1;
  65. unsigned int i,j,m;
  66. unsigned int flag2,flag3;
  67.                                        
  68. uchar UART_Upload[9];
  69. uchar UARTnum[11]={"0123456789."};
  70. uchar UARTdata[5];
  71. uint pm_rateH,pm_rateL,pm_particle,pm_density;//低脈沖率高位。低脈沖率低位, 比率,顆粒,濃度
  72. uchar accord,pm_URV=20,temp_pM; //PM_URV  pm上限值


  73. uchar Sensor_Data[5]={0x00,0x00,0x00,0x00,0x00};
  74. uchar Sensor_AnswerFlag;  //收到起始標志位
  75. uchar Sensor_ErrorFlag;   //讀取傳感器錯誤標志
  76. uchar Sensor_Check;                  //校驗和
  77. uint Sys_CNT;
  78. uint Tmp;
  79. uint t0;
  80. uchar num;
  81. uchar flag;
  82. sbit Sensor_SDA = P1^7;//溫濕度傳感器DHT22數(shù)據(jù)接入

  83. uchar timetest[7];
  84. /*******************************
  85. 定義按鍵:
  86. modekey  為功能選擇按鍵/確定按鍵
  87. upkey    為向上選擇/增加按鍵
  88. dowmkey  為向下選擇/減少按鍵
  89. backkey  為返回/取消按鍵
  90. *******************************/
  91. sbit modekey=P1^6;
  92. sbit upkey  =P1^5;
  93. sbit downkey=P1^4;
  94. sbit backkey=P1^3;

  95. /*****************************
  96. 主函數(shù)main
  97. *****************************/
  98. void main()
  99. {
  100.   LCD12864_Init();          //12864屏幕模塊的初始化
  101.   Usartinit();                  //串口初始化
  102.   form1();                          //form1為主界面
  103.   while(1)
  104.   {
  105.     data1();                  //加載時鐘、DHT22和ZPH01數(shù)據(jù)
  106.         if(modekey==0)          //判斷是否進入調(diào)整時間界面
  107.         {
  108.           Delay_N1ms(5);  //消抖處理,防止誤判
  109.           if(modekey==0)  //二次判斷,確定按下
  110.           {
  111.             for(i=0; i<8; i++)
  112.             {
  113.                   timetest[i]=TIME[i]; //截取當前時間放入第二界面,這樣便于調(diào)整時鐘
  114.                 }
  115.             form2();         //進入時間調(diào)整界面
  116.           }
  117.         }
  118.   }                                                                  
  119. }
  120. /*************************************
  121. form1為第一界面
  122. 即為開機時看到的界面,
  123. 為了加快運行數(shù)度,減少不必要的重復
  124. 將form1放在main函數(shù)主循環(huán)的前面
  125. *************************************/
  126. void form1()  
  127. {
  128.   LCD12864_SetWindow(0, 2);             //位置坐標顯示
  129.   LCD12864_WriteData(year1[0]);  //年
  130.   LCD12864_WriteData(year1[1]);
  131.   LCD12864_SetWindow(0, 4);             //星期
  132.   for(i=0;i<4;i++)                               
  133.   LCD12864_WriteData(week1[i]);
  134.   LCD12864_SetWindow(1, 1);            //月
  135.   LCD12864_WriteData(mouth1[0]);
  136.   LCD12864_WriteData(mouth1[1]);
  137.   LCD12864_SetWindow(1, 3);           //日
  138.   LCD12864_WriteData(day1[0]);
  139.   LCD12864_WriteData(day1[1]);
  140.   LCD12864_SetWindow(1, 7);           //℃
  141.   for(i=0;i<2;i++)
  142.   LCD12864_WriteData(Tsign[i]);
  143.   LCD12864_SetWindow(2, 7);           //H%
  144.   for(i=0;i<2;i++)
  145.   LCD12864_WriteData(Hsign[i]);
  146.   LCD12864_SetWindow(3, 0);          //pm2.5
  147.   for(i=0;i<6;i++)
  148.   LCD12864_WriteData(PM1[i]);
  149. }
  150. /************************************
  151. form2為第二界面,即為時間調(diào)整界面當
  152. 按下第一個建,即確定鍵的時候,進入
  153. 該界面。
  154. ************************************/
  155. void form2()
  156. {
  157.   clearping(); //清屏函數(shù)
  158.   flag2=1;           //界面2標識循環(huán)判斷,用于退出界面2
  159.   /******************************
  160.   本段代碼用于顯示時、分、秒、年、
  161.   月、日、周
  162.   ******************************/
  163.   LCD12864_SetWindow(0, 1);
  164.   for(i=0;i<2;i++)
  165.     LCD12864_WriteData(hour1[i]);
  166.   LCD12864_SetWindow(1, 1);                  
  167.   for(i=0;i<2;i++)
  168.     LCD12864_WriteData(minute1[i]);
  169.   LCD12864_SetWindow(2, 1);
  170.   for(i=0;i<2;i++)
  171.     LCD12864_WriteData(second1[i]);
  172.   LCD12864_SetWindow(3, 1);
  173.   for(i=0;i<2;i++)
  174.     LCD12864_WriteData(week3[i]);
  175.   LCD12864_SetWindow(0, 5);
  176.   for(i=0;i<2;i++)
  177.     LCD12864_WriteData(year1[i]);
  178.   LCD12864_SetWindow(1, 5);
  179.   for(i=0;i<2;i++)
  180.     LCD12864_WriteData(mouth1[i]);
  181.   LCD12864_SetWindow(2, 5);
  182.   for(i=0;i<2;i++)
  183.     LCD12864_WriteData(day1[i]);
  184.   LCD12864_SetWindow(3, 5);
  185.   LCD12864_WriteData(0xc8);
  186.   LCD12864_WriteData(0xb7);
  187.   LCD12864_WriteData(0xb6);
  188.   LCD12864_WriteData(0xa8);
  189.   /************************************
  190.   本段代碼用于顯示進入時間調(diào)整界面時的
  191.   當前時間顯示
  192.   ************************************/
  193.   LCD12864_SetWindow(0, 6);                        //年
  194.   LCD12864_WriteData(CharCode[timetest[6]/16]);
  195.   LCD12864_WriteData(CharCode[(timetest[6]&0x0f)]);
  196.   showweek1();                                     //星期
  197.   LCD12864_SetWindow(1, 6);
  198.   LCD12864_WriteData(CharCode[timetest[4]/16]);           //月
  199.   LCD12864_WriteData(CharCode[(timetest[4]&0x0f)]);
  200.   LCD12864_SetWindow(2, 6);
  201.   LCD12864_WriteData(CharCode[timetest[3]/16]);           //日
  202.   LCD12864_WriteData(CharCode[(timetest[3]&0x0f)]);
  203.   LCD12864_SetWindow(0, 2);
  204.   LCD12864_WriteData(CharCode[timetest[2]/16]);           //小時
  205.   LCD12864_WriteData(CharCode[(timetest[2]&0x0f)]);
  206.   LCD12864_SetWindow(1, 2);
  207.   LCD12864_WriteData(CharCode[timetest[1]/16]);           //分鐘
  208.   LCD12864_WriteData(CharCode[(timetest[1]&0x0f)]);
  209.   LCD12864_SetWindow(2, 2);
  210.   LCD12864_WriteData(CharCode[timetest[0]/16]);           //秒
  211.   LCD12864_WriteData(CharCode[(timetest[0]&0x0f)]);
  212.   /***********************************************
  213.   分隔線
  214.   ***********************************************/
  215.   LCD12864_SetWindow(0, 3);
  216.   LCD12864_WriteData(0xa3);
  217.   LCD12864_WriteData(0xfc);
  218.   LCD12864_SetWindow(1, 3);
  219.   LCD12864_WriteData(0xa3);
  220.   LCD12864_WriteData(0xfc);
  221.   LCD12864_SetWindow(2, 3);
  222.   LCD12864_WriteData(0xa3);
  223.   LCD12864_WriteData(0xfc);
  224.   LCD12864_SetWindow(3, 3);
  225.   LCD12864_WriteData(0xa3);
  226.   LCD12864_WriteData(0xfc);
  227.   //-------------------------------------------
  228.   while(flag2)               //在界面二中進入鍵盤掃描
  229.   {
  230.     Hgarden(flagkeyup_down);         //顯示按鍵指針,以便知道在什么位置
  231.     /****向上************/
  232.     if(upkey==0)        
  233.         {
  234.           Delay_N1ms(5);
  235.       if(upkey==0)
  236.           {
  237.             flagkeyup_down--;          //按鍵指針向上運動          
  238.             if(flagkeyup_down<1) //當按鍵指針運動到最上時不在運動
  239.             {
  240.               flagkeyup_down=8;
  241.             }
  242.             Hgarden(flagkeyup_down);       
  243.             i=0;                 
  244.             while ((i<40) && (upkey==0))//檢測按鍵是否松開,如果按著不動,則400ms后自動跳出向下運行
  245.             {
  246.               Delay_N1ms(10);
  247.               i++;
  248.             }
  249.           }
  250.     }
  251.         /****向下************/
  252.     if(downkey==0)        
  253.         {
  254.           Delay_N1ms(5);
  255.           if(downkey==0)
  256.           {       
  257.             flagkeyup_down++;          //按鍵指針向下運動       
  258.                 if(flagkeyup_down>8) //當按鍵指針運動到最下時不在運動
  259.                 {
  260.               flagkeyup_down=1;
  261.                 }
  262.                 Hgarden(flagkeyup_down);
  263.                 i=0;                         
  264.             while ((i<40) && (downkey==0))         //檢測按鍵是否松開
  265.             {
  266.               Delay_N1ms(10);
  267.                   i++;
  268.             }
  269.           }
  270.         }
  271.         /****確定************/
  272.         if(modekey==0)         //按下確定鍵后,可以進行時間的修改
  273.         {
  274.           Delay_N1ms(10);
  275.           if(modekey==0)
  276.           {       
  277.                 i=0;
  278.             while ((i<40) && (modekey==0))         //檢測按鍵是否松開
  279.             {
  280.               Delay_N1ms(10);
  281.                   i++;
  282.             }
  283.                 if(flagkeyup_down==8)
  284.                 {
  285.                   timetest[0]++;
  286.                   for(j=0; j<8; j++)
  287.                   TIME[j]=timetest[j];
  288.                   Ds1302Init();
  289.                   flag2=0;
  290.                   clearping(); //清屏函數(shù)
  291.                   form1();
  292.                 }
  293.                 else
  294.                 {
  295.                 flag3=1;
  296.                 while(flag3)
  297.                 {
  298.                   Sgarden(flagkeyup_down);
  299.           timesetting(flagkeyup_down);
  300.                   if(modekey==0)         //按下確定鍵后,可以進行時間的修改
  301.               {
  302.                 Delay_N1ms(15);
  303.                 if(modekey==0)
  304.                 {
  305.                            flag3=0;
  306.                    while ((i<40) && (modekey==0))         //檢測按鍵是否松開
  307.                    {
  308.                      Delay_N1ms(10);
  309.                          i++;
  310.                    }
  311.                          }                                                 
  312.               }
  313.             }
  314.           }
  315.           }
  316.         }
  317.         /****返回************/
  318.     if(backkey==0)         //按下確定鍵后,可以進行時間的修改
  319.         {
  320.           Delay_N1ms(10);
  321.           if(backkey==0)
  322.           {       
  323.                 i=0;
  324.                 flag2=0;
  325.                 clearping(); //清屏函數(shù)
  326.                 form1();                 
  327.             while ((i<50) && (backkey==0))         //檢測按鍵是否松開
  328.             {
  329.                   Delay_N1ms(10);
  330.                   i++;
  331.                 }
  332.           }
  333.         }
  334.   }
  335. }

  336. void timesetting(int x)
  337. {
  338.     unsigned int d;
  339.         unsigned int m1,m2,m3,m4,m5,m6,m7;
  340.         /****加************/
  341.     if(upkey==0)        
  342.         {
  343.           Delay_N1ms(5);
  344.       if(upkey==0)
  345.           {
  346.             if(x==1)//小時
  347.                 {
  348.                   timetest[2]++;
  349.                   if((timetest[2]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  350.                   {
  351.                     timetest[2]=timetest[2]+6;
  352.                   }
  353.               if(timetest[2]>0x23)
  354.                      {
  355.                            timetest[2]=0;
  356.                            m1=1;
  357.                          }
  358.                   LCD12864_SetWindow(0, 2);
  359.           LCD12864_WriteData(CharCode[timetest[2]/16]);          
  360.           LCD12864_WriteData(CharCode[(timetest[2]&0x0f)]);
  361.                 }
  362.                 else if(x==2)//分鐘
  363.                 {
  364.                   timetest[1]++;
  365.                   if((timetest[1]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  366.                   {
  367.                     timetest[1]=timetest[1]+6;
  368.                   }
  369.               if(timetest[1]>0x59)
  370.                   {
  371.                            timetest[1]=0;
  372.                            m2=1;
  373.                          }
  374.                   LCD12864_SetWindow(1, 2);
  375.           LCD12864_WriteData(CharCode[timetest[1]/16]);          
  376.           LCD12864_WriteData(CharCode[(timetest[1]&0x0f)]);
  377.                 }
  378.                 else if(x==3)//秒
  379.                 {
  380.                   timetest[0]++;
  381.                   if((timetest[0]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  382.                   {
  383.                     timetest[0]=timetest[0]+6;
  384.                   }
  385.               if(timetest[0]>0x59)
  386.                   {
  387.                            timetest[0]=0;
  388.                            m3=1;
  389.                   }
  390.                   LCD12864_SetWindow(2, 2);
  391.           LCD12864_WriteData(CharCode[timetest[0]/16]);          
  392.           LCD12864_WriteData(CharCode[(timetest[0]&0x0f)]);
  393.                 }
  394.                 else if(x==4)//周
  395.                 {
  396.                   timetest[5]++;
  397.               if(timetest[5]>0x6)
  398.                   {
  399.                            timetest[5]=0;
  400.                            m4=1;
  401.                          }
  402.                   showweek1();  
  403.                 }
  404.                 else if(x==5)//年
  405.                 {
  406.                   timetest[6]++;
  407.                   if((timetest[6]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  408.                   {
  409.                     timetest[6]=timetest[6]+6;
  410.                   }
  411.               if(timetest[6]>0x90)
  412.                   {
  413.                            timetest[6]=0;
  414.                            m5=1;
  415.                          }
  416.                   LCD12864_SetWindow(0, 6);                       
  417.           LCD12864_WriteData(CharCode[timetest[6]/16]);
  418.           LCD12864_WriteData(CharCode[(timetest[6]&0x0f)]);
  419.                 }
  420.                 else if(x==6)//月
  421.                 {
  422.                   timetest[4]++;
  423.                   if((timetest[4]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  424.                   {
  425.                     timetest[4]=timetest[4]+6;
  426.                   }
  427.               if(timetest[4]>0x12)
  428.                   {
  429.                            timetest[4]=0x01;
  430.                            m6=1;
  431.                          }
  432.                   LCD12864_SetWindow(1, 6);                        
  433.           LCD12864_WriteData(CharCode[timetest[4]/16]);
  434.           LCD12864_WriteData(CharCode[(timetest[4]&0x0f)]);
  435.                 }
  436.                 else if(x==7)//日
  437.                 {
  438.                  
  439.                   if(timetest[4]==0x01||timetest[4]==0x03||timetest[4]==0x05||timetest[4]==0x07||timetest[4]==0x08||timetest[4]==0x10||timetest[4]==0x12)
  440.                 d=0x31;
  441.                   else if(timetest[4]==0x04||timetest[4]==0x06||timetest[4]==0x09||timetest[4]==0x11)
  442.                     d=0x30;
  443.                   else if((CharCode[timetest[6]/16]*10+CharCode[(timetest[6]&0x0f)])%4==0)
  444.                     d=0x29;
  445.                   else
  446.                     d=0x28;
  447.                   timetest[3]++;
  448.                   if((timetest[3]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  449.                   {
  450.                     timetest[3]=timetest[3]+6;
  451.                   }
  452.                   if(timetest[3]>d)
  453.                   {
  454.                            timetest[3]=0;
  455.                            m7=1;
  456.                          }
  457.                   LCD12864_SetWindow(2, 6);                        
  458.           LCD12864_WriteData(CharCode[timetest[3]/16]);
  459.           LCD12864_WriteData(CharCode[(timetest[3]&0x0f)]);
  460.                 }
  461.                        
  462.             i=0;                 
  463.             while ((i<40) && (upkey==0))//檢測按鍵是否松開,如果按著不動,則400ms后自動跳出向下運行
  464.             {
  465.               Delay_N1ms(10);
  466.               i++;
  467.             }
  468.           }
  469.     }
  470.         /****減************/
  471.     if(downkey==0)        
  472.         {
  473.           Delay_N1ms(5);
  474.           if(downkey==0)
  475.           {       
  476.            if(x==1)//小時
  477.                 {
  478.                   timetest[2]--;
  479.                   if((timetest[2]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  480.                   {
  481.                     timetest[2]=timetest[2]-6;
  482.                   }
  483.                   if(m1==1)
  484.                   timetest[2]=0x23;
  485.               if(timetest[2]==0x00)
  486.                      m1=1;
  487.                   else m1=0;
  488.                   LCD12864_SetWindow(0, 2);
  489.           LCD12864_WriteData(CharCode[timetest[2]/16]);          
  490.           LCD12864_WriteData(CharCode[(timetest[2]&0x0f)]);
  491.                 }
  492.                 else if(x==2)//分鐘
  493.                 {
  494.                   timetest[1]--;
  495.                   if((timetest[1]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  496.                   {
  497.                     timetest[1]=timetest[1]-6;
  498.                   }
  499.               if(m2==1)
  500.                   timetest[1]=0x59;
  501.               if(timetest[1]==0x00)
  502.                      m2=1;
  503.                   else m2=0;
  504.                   LCD12864_SetWindow(1, 2);
  505.           LCD12864_WriteData(CharCode[timetest[1]/16]);          
  506.           LCD12864_WriteData(CharCode[(timetest[1]&0x0f)]);
  507.                 }
  508.                 else if(x==3)//秒
  509.                 {
  510.                   timetest[0]--;
  511.                   if((timetest[0]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  512.                   {
  513.                     timetest[0]=timetest[0]-6;
  514.                   }
  515.               if(m3==1)
  516.                   timetest[0]=0x59;
  517.               if(timetest[0]==0x00)
  518.                      m3=1;
  519.                   else m3=0;
  520.                   LCD12864_SetWindow(2, 2);
  521.           LCD12864_WriteData(CharCode[timetest[0]/16]);          
  522.           LCD12864_WriteData(CharCode[(timetest[0]&0x0f)]);
  523.                 }
  524.                 else if(x==4)//周
  525.                 {
  526.                   timetest[5]--;
  527.               if(m4==1)
  528.                   timetest[5]=0x06;
  529.               if(timetest[5]==0x00)
  530.                      m4=1;
  531.                   else m4=0;
  532.                   showweek1();  
  533.                 }
  534.                 else if(x==5)//年
  535.                 {
  536.                   timetest[6]--;
  537.                   if((timetest[6]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  538.                   {
  539.                     timetest[6]=timetest[6]-6;
  540.                   }
  541.               if(m5==1)
  542.                   timetest[6]=0x59;
  543.               if(timetest[6]==0x00)
  544.                      m5=1;
  545.                   else m5=0;
  546.                   LCD12864_SetWindow(0, 6);                       
  547.           LCD12864_WriteData(CharCode[timetest[6]/16]);
  548.           LCD12864_WriteData(CharCode[(timetest[6]&0x0f)]);
  549.                 }
  550.                 else if(x==6)//月
  551.                 {
  552.                   timetest[4]--;
  553.                   if((timetest[4]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  554.                   {
  555.                     timetest[4]=timetest[4]-6;
  556.                   }
  557.               if(m6==1)
  558.                   timetest[4]=0x12;
  559.               if(timetest[4]==0x00)
  560.                      m6=1;
  561.                   else m6=0;
  562.                   LCD12864_SetWindow(1, 6);                        
  563.           LCD12864_WriteData(CharCode[timetest[4]/16]);
  564.           LCD12864_WriteData(CharCode[(timetest[4]&0x0f)]);
  565.                 }
  566.                 else if(x==7)//日
  567.                 {
  568.                  
  569.                   if(timetest[4]==0x01||timetest[4]==0x03||timetest[4]==0x05||timetest[4]==0x07||timetest[4]==0x08||timetest[4]==0x10||timetest[4]==0x12)
  570.                 d=0x31;
  571.                   else if(timetest[4]==0x04||timetest[4]==0x06||timetest[4]==0x09||timetest[4]==0x11)
  572.                     d=0x30;
  573.                   else if((CharCode[timetest[6]/16]*10+CharCode[(timetest[6]&0x0f)])%4==0)
  574.                     d=0x29;
  575.                   else
  576.                     d=0x28;
  577.                   timetest[3]--;
  578.                   if((timetest[3]&0x0f)>9)                                         //換成BCD碼,跳過a-e段
  579.                   {
  580.                     timetest[3]=timetest[3]-6;
  581.                   }
  582.                   if(m7==1)
  583.                   timetest[3]=d;
  584.               if(timetest[3]==0x00)
  585.                      m7=1;
  586.                   else m7=0;
  587.                   LCD12864_SetWindow(2, 6);                        
  588.           LCD12864_WriteData(CharCode[timetest[3]/16]);
  589.           LCD12864_WriteData(CharCode[(timetest[3]&0x0f)]);
  590.                 }
  591.                 i=0;                         
  592.             while ((i<40) && (downkey==0))         //檢測按鍵是否松開
  593.             {
  594.               Delay_N1ms(10);
  595.                   i++;
  596.             }
  597.           }
  598.         }


  599. }
  600. void Hgarden(int x)
  601. {
  602.     if(x==1)
  603.         {
  604.         LCD12864_SetWindow(3, 4);
  605.           LCD12864_WriteData(0xa1);       
  606.         LCD12864_WriteData(0xa0);
  607.         LCD12864_SetWindow(0, 0);
  608.         LCD12864_WriteData(0xa1);       
  609.         LCD12864_WriteData(0xf0);       
  610.         LCD12864_SetWindow(1, 0);
  611.           LCD12864_WriteData(0xa1);       
  612.         LCD12864_WriteData(0xa0);
  613.         }
  614.         else if(x==2)
  615.         {
  616.         LCD12864_SetWindow(0, 0);
  617.           LCD12864_WriteData(0xa1);       
  618.         LCD12864_WriteData(0xa0);         
  619.         LCD12864_SetWindow(1, 0);
  620.         LCD12864_WriteData(0xa1);       
  621.         LCD12864_WriteData(0xf0);
  622.     LCD12864_SetWindow(2, 0);
  623.           LCD12864_WriteData(0xa1);       
  624.         LCD12864_WriteData(0xa0);
  625.         }
  626.         else if(x==3)
  627.         {
  628.         LCD12864_SetWindow(1, 0);
  629.           LCD12864_WriteData(0xa1);       
  630.         LCD12864_WriteData(0xa0);         
  631.         LCD12864_SetWindow(2, 0);
  632.         LCD12864_WriteData(0xa1);       
  633.         LCD12864_WriteData(0xf0);
  634.     LCD12864_SetWindow(3, 0);
  635.           LCD12864_WriteData(0xa1);       
  636.         LCD12864_WriteData(0xa0);
  637.         }
  638.         else if(x==4)
  639.         {
  640.         LCD12864_SetWindow(2, 0);
  641.           LCD12864_WriteData(0xa1);       
  642.         LCD12864_WriteData(0xa0);         
  643.         LCD12864_SetWindow(3, 0);
  644.         LCD12864_WriteData(0xa1);       
  645.         LCD12864_WriteData(0xf0);
  646.     LCD12864_SetWindow(0, 4);
  647.           LCD12864_WriteData(0xa1);       
  648.         LCD12864_WriteData(0xa0);
  649.         }
  650.         else if(x==5)
  651.         {
  652.         LCD12864_SetWindow(3, 0);
  653.           LCD12864_WriteData(0xa1);       
  654.         LCD12864_WriteData(0xa0);         
  655.         LCD12864_SetWindow(0, 4);
  656.         LCD12864_WriteData(0xa1);       
  657.         LCD12864_WriteData(0xf0);
  658.     LCD12864_SetWindow(1, 4);
  659.           LCD12864_WriteData(0xa1);       
  660.         LCD12864_WriteData(0xa0);
  661.         }
  662.         else if(x==6)
  663.         {
  664.         LCD12864_SetWindow(0, 4);
  665.           LCD12864_WriteData(0xa1);       
  666.         LCD12864_WriteData(0xa0);         
  667.         LCD12864_SetWindow(1, 4);
  668.         LCD12864_WriteData(0xa1);       
  669.         LCD12864_WriteData(0xf0);
  670.     LCD12864_SetWindow(2, 4);
  671.           LCD12864_WriteData(0xa1);       
  672.         LCD12864_WriteData(0xa0);
  673.         }
  674.         else if(x==7)
  675.         {
  676.         LCD12864_SetWindow(1, 4);
  677.           LCD12864_WriteData(0xa1);       
  678.         LCD12864_WriteData(0xa0);         
  679.         LCD12864_SetWindow(2, 4);
  680.         LCD12864_WriteData(0xa1);       
  681.         LCD12864_WriteData(0xf0);
  682.     LCD12864_SetWindow(3, 4);
  683.           LCD12864_WriteData(0xa1);       
  684.         LCD12864_WriteData(0xa0);
  685.         }
  686.         else if(x==8)
  687.         {
  688.         LCD12864_SetWindow(0, 0);
  689.           LCD12864_WriteData(0xa1);       
  690.         LCD12864_WriteData(0xa0);
  691.         LCD12864_SetWindow(2, 4);
  692.           LCD12864_WriteData(0xa1);       
  693.         LCD12864_WriteData(0xa0);         
  694.         LCD12864_SetWindow(3, 4);
  695.         LCD12864_WriteData(0xa1);       
  696.         LCD12864_WriteData(0xf0);
  697.         }               
  698. }

  699. void Sgarden(int x)
  700. {
  701.     if(x==1)
  702.         {
  703.         LCD12864_SetWindow(0, 0);
  704.         LCD12864_WriteData(0xa1);       
  705.         LCD12864_WriteData(0xf1);       
  706.         }
  707.         else if(x==2)
  708.         {         
  709.         LCD12864_SetWindow(1, 0);
  710.         LCD12864_WriteData(0xa1);       
  711.         LCD12864_WriteData(0xf1);
  712.         }
  713.         else if(x==3)
  714.         {         
  715.         LCD12864_SetWindow(2, 0);
  716.         LCD12864_WriteData(0xa1);       
  717.         LCD12864_WriteData(0xf1);
  718.         }
  719.         else if(x==4)
  720.         {         
  721.         LCD12864_SetWindow(3, 0);
  722.         LCD12864_WriteData(0xa1);       
  723.         LCD12864_WriteData(0xf1);
  724.         }
  725.         else if(x==5)
  726.         {         
  727.         LCD12864_SetWindow(0, 4);
  728.         LCD12864_WriteData(0xa1);       
  729.         LCD12864_WriteData(0xf1);
  730.         }
  731.         else if(x==6)
  732.         {         
  733.         LCD12864_SetWindow(1, 4);
  734.         LCD12864_WriteData(0xa1);       
  735.         LCD12864_WriteData(0xf1);
  736.         }
  737.         else if(x==7)
  738.         {         
  739.         LCD12864_SetWindow(2, 4);
  740.         LCD12864_WriteData(0xa1);       
  741.         LCD12864_WriteData(0xf1);
  742.         }
  743.         else if(x==8)
  744.         {
  745.         LCD12864_SetWindow(3, 4);
  746.         LCD12864_WriteData(0xa1);       
  747.         LCD12864_WriteData(0xf1);
  748.         }
  749. }
  750. void data1()
  751. {
  752.   showtime();
  753.   showTH();
  754.   showPM();
  755. }



  756. void showtime()
  757. {
  758.   Ds1302ReadTime();
  759.   LCD12864_SetWindow(0, 0);
  760.   LCD12864_WriteData(CharCode[2]);
  761.   LCD12864_WriteData(CharCode[0]);                                   //年
  762.   LCD12864_WriteData(CharCode[TIME[6]/16]);
  763.   LCD12864_WriteData(CharCode[(TIME[6]&0x0f)]);
  764.   
  765.   showweek();//星期
  766.   LCD12864_SetWindow(1, 0);
  767.   LCD12864_WriteData(CharCode[TIME[4]/16]);           //月
  768.   LCD12864_WriteData(CharCode[(TIME[4]&0x0f)]);
  769.   LCD12864_SetWindow(1, 2);
  770.   LCD12864_WriteData(CharCode[TIME[3]/16]);           //日
  771.   LCD12864_WriteData(CharCode[(TIME[3]&0x0f)]);
  772.   LCD12864_SetWindow(2, 0);
  773.   LCD12864_WriteData(CharCode[TIME[2]/16]);          //小時
  774.   LCD12864_WriteData(CharCode[(TIME[2]&0x0f)]);
  775.   LCD12864_WriteData(CharCode[12]);
  776.   LCD12864_WriteData(CharCode[TIME[1]/16]);         //分鐘
  777.   LCD12864_WriteData(CharCode[(TIME[1]&0x0f)]);
  778.   LCD12864_WriteData(CharCode[12]);
  779.   LCD12864_WriteData(CharCode[TIME[0]/16]);         //秒
  780.   LCD12864_WriteData(CharCode[(TIME[0]&0x0f)]);
  781. }

  782. void showweek()         //周
  783. {
  784.   uint wek;         
  785.   wek=CharCode[(TIME[5]&0x0f)];
  786.   LCD12864_SetWindow(0, 6);
  787.   if(wek=='0')
  788.    for(i=0;i<2;i++)
  789.    LCD12864_WriteData(week2_0[i]);
  790.   else if(wek=='1')
  791.    for(i=0;i<2;i++)
  792.    LCD12864_WriteData(week2_1[i]);       
  793.   else if(wek=='2')
  794.    for(i=0;i<2;i++)
  795.    LCD12864_WriteData(week2_2[i]);
  796.   else if(wek=='3')
  797.    {
  798.     LCD12864_WriteData(0xc8);
  799.     LCD12864_WriteData(0xfd);
  800.     }
  801.   else if(wek=='4')
  802.    for(i=0;i<2;i++)
  803.    LCD12864_WriteData(week2_4[i]);
  804.   else if(wek=='5')
  805.    for(i=0;i<2;i++)
  806.    LCD12864_WriteData(week2_5[i]);
  807.   else if(wek=='6')
  808.    for(i=0;i<2;i++)
  809.    LCD12864_WriteData(week2_6[i]);
  810.   else
  811.    ;                            
  812. }

  813. void showweek1()         //周
  814. {
  815.   uint wek;         
  816.   wek=CharCode[(timetest[5]&0x0f)];
  817.   LCD12864_SetWindow(3, 2);
  818.   if(wek=='0')
  819.    for(i=0;i<2;i++)
  820.    LCD12864_WriteData(week2_0[i]);
  821.   else if(wek=='1')
  822.    for(i=0;i<2;i++)
  823.    LCD12864_WriteData(week2_1[i]);       
  824.   else if(wek=='2')
  825.    for(i=0;i<2;i++)
  826.    LCD12864_WriteData(week2_2[i]);
  827.   else if(wek=='3')
  828.    {
  829.     LCD12864_WriteData(0xc8);
  830.     LCD12864_WriteData(0xfd);
  831.     }
  832.   else if(wek=='4')
  833.    for(i=0;i<2;i++)
  834.    LCD12864_WriteData(week2_4[i]);
  835.   else if(wek=='5')
  836.    for(i=0;i<2;i++)
  837.    LCD12864_WriteData(week2_5[i]);
  838.   else if(wek=='6')
  839.    for(i=0;i<2;i++)
  840.    LCD12864_WriteData(week2_6[i]);
  841.   else
  842.    ;                            
  843. }

  844. void showTH()
  845. {
  846.    Read_Sensor();
  847.    Tmp = Sensor_Data[2]*256+Sensor_Data[3];
  848.    LCD12864_SetWindow(1, 5);
  849.    LCD12864_WriteData(CharCode[Tmp/100%10]);
  850.    LCD12864_WriteData(CharCode[Tmp/10%10]);
  851.    LCD12864_WriteData(CharCode[10]);
  852.    LCD12864_WriteData(CharCode[Tmp%10]);

  853.    Tmp = Sensor_Data[0]*256+Sensor_Data[1];
  854.    LCD12864_SetWindow(2, 5);
  855.    LCD12864_WriteData(CharCode[Tmp/100%10]);
  856.    LCD12864_WriteData(CharCode[Tmp/10%10]);
  857.    LCD12864_WriteData(CharCode[10]);
  858.    LCD12864_WriteData(CharCode[Tmp%10]);

  859. }

  860. unsigned char Read_SensorData(void)
  861.   {
  862.         unsigned char i,cnt;
  863.         unsigned char buffer,tmp;
  864.         buffer = 0;
  865.         for(i=0;i<8;i++)
  866.         {
  867.                 cnt=0;
  868.                 while(!Sensor_SDA)        //檢測上次低電平是否結(jié)束
  869.                 {
  870.                   if(++cnt >= 300)
  871.                    {
  872.                           break;
  873.                    }
  874.                 }
  875.                 //延時Min=26us Max50us 跳過數(shù)據(jù)"0" 的高電平
  876.                 Delay_N10us(4);         //延時30us   
  877.                
  878.                 //判斷傳感器發(fā)送數(shù)據(jù)位
  879.                 tmp =0;
  880.                 if(Sensor_SDA)         
  881.                 {
  882.                   tmp = 1;
  883.                 }  
  884.                 cnt =0;
  885.                 while(Sensor_SDA)                //等待高電平 結(jié)束
  886.                 {
  887.                            if(++cnt >= 200)
  888.                         {
  889.                           break;
  890.                         }
  891.                 }
  892.                 buffer <<=1;
  893.                 buffer |= tmp;       
  894.         }
  895.         return buffer;
  896.   }

  897. /********************************************\
  898. |* 功能: 讀傳感器                              *|
  899. \********************************************/
  900. unsigned char Read_Sensor(void)
  901.   {
  902.         unsigned char i;
  903.         //主機拉低(Min=800US Max=20Ms)
  904.         Sensor_SDA = 0;
  905.         Delay_N1ms(10);  //延時2Ms
  906.           
  907.         //釋放總線 延時(Min=30us Max=50us)
  908.         Sensor_SDA = 1;        
  909.         Delay_N10us(4);//延時30us
  910.         //主機設(shè)為輸入 判斷傳感器響應信號
  911.         Sensor_SDA = 1;
  912.                
  913.         Sensor_AnswerFlag = 0;  // 傳感器響應標志         

  914.         //判斷從機是否有低電平響應信號 如不響應則跳出,響應則向下運行          
  915.         if(Sensor_SDA ==0)
  916.         {
  917.            Sensor_AnswerFlag = 1;//收到起始信號
  918.            Sys_CNT = 0;
  919.            //判斷從機是否發(fā)出 80us 的低電平響應信號是否結(jié)束         
  920.            while((!Sensor_SDA))
  921.            {
  922.              if(++Sys_CNT>300) //防止進入死循環(huán)
  923.                  {
  924.                    Sensor_ErrorFlag = 1;
  925.                    return 0;
  926.                   }
  927.             }
  928.             Sys_CNT = 0;
  929.             //判斷從機是否發(fā)出 80us 的高電平,如發(fā)出則進入數(shù)據(jù)接收狀態(tài)
  930.             while((Sensor_SDA))
  931.             {
  932.                if(++Sys_CNT>300) //防止進入死循環(huán)
  933.                    {
  934.                      Sensor_ErrorFlag = 1;
  935.                      return 0;
  936.                    }
  937.             }                  
  938.             // 數(shù)據(jù)接收        傳感器共發(fā)送40位數(shù)據(jù)
  939.             // 即5個字節(jié) 高位先送  5個字節(jié)分別為濕度高位 濕度低位 溫度高位 溫度低位 校驗和
  940.             // 校驗和為:濕度高位+濕度低位+溫度高位+溫度低位
  941.             for(i=0;i<5;i++)
  942.             {
  943.               Sensor_Data[i] = Read_SensorData();
  944.             }
  945.           }
  946.           else
  947.           {
  948.             Sensor_AnswerFlag = 0;          // 未收到傳感器響應       
  949.           }
  950. ……………………

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

所有資料51hei提供下載:
51單片機室內(nèi)環(huán)境檢測儀.zip (9.74 MB, 下載次數(shù): 247)


評分

參與人數(shù) 3黑幣 +65 收起 理由
kljie1000 + 10
zqy181818 + 5 贊一個!
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

沙發(fā)
ID:334964 發(fā)表于 2018-5-21 16:07 | 只看該作者
謝謝樓主~~~~~~~~~~~~
回復

使用道具 舉報

板凳
ID:161797 發(fā)表于 2018-11-10 11:45 | 只看該作者
不錯,好東西.謝謝.
回復

使用道具 舉報

地板
ID:364389 發(fā)表于 2018-11-24 21:13 | 只看該作者
下載的里面沒有原理圖也沒有程序,白浪費幣了
回復

使用道具 舉報

5#
ID:364389 發(fā)表于 2018-11-24 21:14 | 只看該作者
下載的里面沒有pcb也沒有程序
回復

使用道具 舉報

6#
ID:364389 發(fā)表于 2018-11-24 21:21 | 只看該作者
里面沒有原理圖也沒有程序,pcb是錯的
回復

使用道具 舉報

7#
ID:364389 發(fā)表于 2018-11-24 21:25 | 只看該作者
下載的沒有原理圖。。。。
回復

使用道具 舉報

8#
ID:624914 發(fā)表于 2019-10-16 18:07 | 只看該作者
有沒有仿真圖
回復

使用道具 舉報

9#
ID:599674 發(fā)表于 2019-10-25 14:22 來自手機 | 只看該作者
感謝樓主
回復

使用道具 舉報

10#
ID:441206 發(fā)表于 2020-2-14 16:00 | 只看該作者
這個里面有仿真嗎
回復

使用道具 舉報

11#
ID:502881 發(fā)表于 2020-3-9 20:37 | 只看該作者
好好好,正好需要,非常感謝
回復

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 99在线视频观看 | 成人在线免费视频 | 亚洲色欲色欲www | 一区二区三区视频在线观看 | 国产精品久久久久久福利一牛影视 | 免费成人av网站 | 午夜视频一区二区 | 色网站入口 | 中文字幕一区二区三区四区五区 | 免费观看a级毛片在线播放 黄网站免费入口 | 久久午夜精品福利一区二区 | 亚洲网站在线观看 | 99re6在线视频精品免费 | 国产精品久久久久无码av | 欧美日韩电影免费观看 | 久久综合伊人一区二区三 | 亚洲精品视频免费 | 人人人人干 | 午夜影院 | 久久亚洲一区二区三区四区 | 久久久69| 91麻豆精品一区二区三区 | 一级国产精品一级国产精品片 | 污书屋 | 国产成人久久精品一区二区三区 | av片免费 | 男人的天堂久久 | 精品视频在线观看 | 国产视频中文字幕 | 亚洲精品毛片av | 久久久一二三 | 91婷婷韩国欧美一区二区 | 99精品在线观看 | 欧美一区在线视频 | 免费视频一区二区 | 国产一二三区精品视频 | 麻豆精品国产91久久久久久 | 99热在线免费 | 久久久日韩精品一区二区三区 | 五月激情婷婷网 | 亚洲444kkkk在线观看最新 |