找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4018|回復(fù): 6
打印 上一主題 下一主題
收起左側(cè)

關(guān)于SDS011模塊(空氣中pm2.5及pm10)單片機(jī)c程序?qū)崿F(xiàn)(鏈接附源碼)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:473505 發(fā)表于 2019-4-7 14:42 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
這些天在做一個有關(guān)空氣質(zhì)量檢測的一個玩意,運用了sds011這個傳感器,在網(wǎng)上找了很多資料,發(fā)現(xiàn)都沒有源碼。!由此我將我自己寫的源碼發(fā)布出來,供大家直接參考及使用!為的是方便大家,為大家節(jié)省一些不必要的時間,還有就是希望大家都可以將自己的東西開源出來,大家相互交流,共同學(xué)習(xí)!!

普中開發(fā)板,直接
連接模塊直接下載程序,lcd1602液晶屏顯示。有些的不好的地方還望大家指正。!

初創(chuàng)不易請大家多多支持!!

單片機(jī)源程序如下:
  1. #include "lcd.h"

  2. unsigned char        ge,shi,bai,qian,wan,shiwan;                        //顯示變量

  3. void Read_Busy()           //忙檢測函數(shù),判斷bit7        是0:允許執(zhí)行;1:禁止執(zhí)行
  4. {
  5.     unsigned char sta;      
  6.     LCD1602_DB = 0xff;
  7.     LCD1602_RS = 0;
  8.     LCD1602_RW = 1;
  9.     do
  10.     {
  11.         LCD1602_EN = 1;                //使能
  12.         sta = LCD1602_DB;        //讀取數(shù)據(jù)位
  13.         LCD1602_EN = 0;                //失能,用完就拉低,釋放總線
  14.     }while(sta & 0x80);                // 1000 0000
  15. }

  16. void Lcd1602_Write_Cmd(unsigned char cmd)     //寫命令
  17. {
  18.     Read_Busy();
  19.     LCD1602_RS = 0;                        //0:對命令操作                (數(shù)據(jù),命令選擇端)
  20.     LCD1602_RW = 0;                        //0:寫                                (讀寫命令選擇端        )
  21.     LCD1602_DB = cmd;                //命令發(fā)送到io口
  22.     LCD1602_EN = 1;                       
  23.     LCD1602_EN = 0;   
  24. }

  25. void Lcd1602_Write_Data(unsigned char dat)   //寫數(shù)據(jù)
  26. {
  27.       Read_Busy();
  28.       LCD1602_RS = 1;                //1:對數(shù)據(jù)操作                (數(shù)據(jù),命令選擇端)
  29.       LCD1602_RW = 0;                //0:寫                                (讀寫命令選擇端        )
  30.       LCD1602_DB = dat;                //命令發(fā)送到io口
  31.       LCD1602_EN = 1;
  32.       LCD1602_EN = 0;
  33. }

  34. //void LcdSetCursor(unsigned char x,unsigned char y)  //坐標(biāo)顯示
  35. //{
  36. //    unsigned char addr;
  37. //    if(y == 0)
  38. //        addr = 0x00 + x;
  39. //    else
  40. //        addr = 0x40 + x;
  41. //   
  42. //    Lcd1602_Write_Cmd(addr|0x80);
  43. //}

  44. //按指定位置顯示一個字符
  45. void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)
  46. {
  47.         Y &= 0x1;
  48.         X &= 0xF;                                                 //限制X不能大于15,Y不能大于1        (坐標(biāo))
  49.         if (Y) X |= 0x40;                                 //當(dāng)要顯示第二行時地址碼+0x40;
  50.         X |= 0x80;                                                 //算出指令碼
  51.         Lcd1602_Write_Cmd(X);                         //發(fā)命令字
  52.         Lcd1602_Write_Data(DData);                 //發(fā)數(shù)據(jù)
  53. }


  54. //void LcdShowStr(unsigned char x,unsigned char y,unsigned char *str)     //顯示字符串
  55. //{
  56. //    LcdSetCursor(x,y);      //當(dāng)前字符的坐標(biāo)
  57. //    while(*str != '\0')
  58. //    {
  59. //        Lcd1602_Write_Data(*str++);
  60. //    }
  61. //}


  62. void InitLcd1602()              //1602初始化
  63. {
  64.        
  65.     Lcd1602_Write_Cmd(0x38);    //打開,5*8,8位數(shù)據(jù)                8總線數(shù)據(jù)傳輸
  66.         Lcd1602_Write_Cmd(0x08);       
  67.     Lcd1602_Write_Cmd(0x0c);        //開顯示不顯示光標(biāo)
  68.     Lcd1602_Write_Cmd(0x06);        //寫一個指針加1
  69.     Lcd1602_Write_Cmd(0x01);    //清屏   
  70. }



  71. //取余運算
  72. void conversion(int temp_data)
  73. {
  74.         temp_data=temp_data;
  75.        
  76.     bai=temp_data/100+0x30   ;
  77.     temp_data=temp_data%100;                //取余運算
  78.     shi=temp_data/10+0x30    ;
  79.     temp_data=temp_data%10;                        //取余運算
  80.     ge=temp_data+0x30;
  81. }



  82. void Lcd1602_Show_PM()
  83. {
  84.         usart_date_process();                       

  85.         conversion(pm2_5);       
  86.         DisplayOneChar(0,0,'P');                //PM2.5顯示
  87.         DisplayOneChar(1,0,'M');
  88.         DisplayOneChar(2,0,'2');
  89.         DisplayOneChar(3,0,'.');
  90.         DisplayOneChar(4,0,'5');
  91.         DisplayOneChar(5,0,':');
  92.         DisplayOneChar(7,0,bai);              //溫度的十位
  93.         DisplayOneChar(8,0,shi);                //溫度的個位
  94.         DisplayOneChar(9,0,ge);              //溫度的十位
  95.         DisplayOneChar(11,0,'u');
  96.         DisplayOneChar(12,0,'g');
  97.         DisplayOneChar(13,0,'/');
  98.         DisplayOneChar(14,0,'m');
  99.         DisplayOneChar(15,0,'3');
  100.        
  101.         conversion(pm10);       
  102.         DisplayOneChar(0,1,'P');                //PM2.5顯示
  103.         DisplayOneChar(1,1,'M');
  104.         DisplayOneChar(2,1,'1');
  105.         DisplayOneChar(3,1,'0');
  106.         DisplayOneChar(4,1,' ');
  107.         DisplayOneChar(5,1,':');
  108.         DisplayOneChar(7,1,bai);              //溫度的十位
  109.         DisplayOneChar(8,1,shi);                //溫度的個位
  110.         DisplayOneChar(9,1,ge);              //溫度的十位
  111.         DisplayOneChar(11,1,'u');
  112.         DisplayOneChar(12,1,'g');
  113.         DisplayOneChar(13,1,'/');
  114.         DisplayOneChar(14,1,'m');
  115.         DisplayOneChar(15,1,'3');
  116. }

  117. //void Lcd1602_Show_height()
  118. //{
  119. //        conversion(height);
  120. //        DisplayOneChar(2,0,'H');                //海拔顯示
  121. //        DisplayOneChar(3,0,':');
  122. //        DisplayOneChar(6,0,qian);                //千位
  123. //        DisplayOneChar(8,0,bai);                //百位
  124. //        DisplayOneChar(9,0,shi);                //十位
  125. //        DisplayOneChar(10,0,ge);                //個位
  126. //        DisplayOneChar(13,0,'m');                //海拔單位
  127. //}
復(fù)制代碼

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



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

使用道具 舉報

沙發(fā)
ID:473505 發(fā)表于 2019-4-23 08:26 | 只看該作者
沒有人支持嗎。
回復(fù)

使用道具 舉報

板凳
ID:276433 發(fā)表于 2019-8-16 09:26 來自手機(jī) | 只看該作者
995153087 發(fā)表于 2019-4-23 08:26
沒有人支持嗎!

很好,學(xué)習(xí)一下!
回復(fù)

使用道具 舉報

地板
ID:276433 發(fā)表于 2019-8-28 09:23 | 只看該作者
弱弱的問一下,這是51,還是32?我是初學(xué)者。
回復(fù)

使用道具 舉報

5#
ID:654509 發(fā)表于 2019-12-3 09:36 | 只看該作者
很有學(xué)習(xí)參考
回復(fù)

使用道具 舉報

6#
ID:403916 發(fā)表于 2020-4-18 18:38 | 只看該作者
樓主,這PM2.5和PM10的算法是一樣的嗎?
回復(fù)

使用道具 舉報

7#
ID:1117277 發(fā)表于 2024-4-19 01:28 | 只看該作者
請問要同時顯示PM1的話就加上一段程序就行嗎
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表