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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

兩路am2302溫濕度傳感器單片機程序 ds1307時鐘芯片 12864顯示

[復制鏈接]
跳轉到指定樓層
樓主
本帖最后由 accumulation 于 2019-8-20 23:39 編輯

制作出來的實物圖如下:


單片機源程序如下:
  1. #include<STC15W408AS.H>
  2. #include<intrins.h>
  3. extern void InitLcd12864();
  4. extern void LcdAreaClean(unsigned char x,unsigned char y,unsigned char len);
  5. extern void LcdShowStr(unsigned char x,unsigned char y,unsigned char *str);
  6. extern bit ReadSensor(unsigned char *buf,unsigned char *flag);
  7. extern bit ReadSensorb(unsigned char *buf,unsigned char *flag);
  8. extern void InitUART();
  9. extern void InitDS1307();
  10. extern void Ds1307Read(unsigned char *buf);
  11. extern void SendString(char *s);
  12. extern void KeyScan();
  13. extern bit KeyDrive();
  14. void ConfigTimer0();
  15. bit flag2s = 0;
  16. bit flag200ms = 0;

  17. void main()
  18. {
  19.         bit ack=0;
  20.         bit flagset;
  21.         unsigned char addr;
  22.         unsigned int humidity;
  23.         unsigned int temperature;
  24.         unsigned char showbuf[13];
  25.         unsigned char buf[8];
  26.         unsigned char flag;
  27.         unsigned char psec=0xAA;
  28.         InitLcd12864();
  29.         InitUART();
  30.         InitDS1307();
  31.         ConfigTimer0();
  32.         LcdShowStr(0,0,"濕度");
  33.         LcdShowStr(0,1,"溫度");
  34.         LcdShowStr(4,0,"濕度");
  35.         LcdShowStr(4,1,"溫度");
  36.         while(1)
  37.         {
  38.                 flagset=KeyDrive();
  39.                 if(flag200ms&&flagset)
  40.                 {
  41.                         flag200ms=0;        
  42.                         Ds1307Read(buf);
  43.                         if(psec!=buf[0])        
  44.                         {        
  45.                                 showbuf[0] = '2';
  46.                                 showbuf[1] = '0';
  47.                                 showbuf[2] = (buf[6]>>4) + '0';
  48.                                 showbuf[3] = (buf[6]&0x0F) + '0';
  49.                                 showbuf[4] = '-';
  50.                                 showbuf[5] = '-';
  51.                                 showbuf[6] = (buf[5]>>4) + '0';
  52.                                 showbuf[7] = (buf[5]&0x0F) + '0';
  53.                                 showbuf[8] = '-';
  54.                                 showbuf[9] = '-';
  55.                                 showbuf[10] = (buf[4]>>4) + '0';
  56.                                 showbuf[11] = (buf[4]&0x0F) + '0';
  57.                                 showbuf[12] = '\0';
  58.                                 SendString(showbuf);
  59.                                 SendString("\r\n");
  60.                                 LcdShowStr(1,2,showbuf);
  61.                                 
  62.                                 showbuf[0] = (buf[3]>>4) + '0';
  63.                                 showbuf[1] = (buf[3]&0x0F) + '0';
  64.                                 showbuf[2] = '\0';
  65.                                 SendString(showbuf);
  66.                                 SendString("\r\n");
  67.                                 LcdShowStr(7,3,showbuf);
  68.                                 
  69.                                 showbuf[0] = (buf[2]>>4) + '0';
  70.                                 showbuf[1] = (buf[2]&0x0F) + '0';
  71.                                 showbuf[2] = ':';
  72.                                 showbuf[3] = ':';
  73.                                 showbuf[4] = (buf[1]>>4) + '0';
  74.                                 showbuf[5] = (buf[1]&0x0F) + '0';
  75.                                 showbuf[6] = ':';
  76.                                 showbuf[7] = ':';
  77.                                 showbuf[8] = (buf[0]>>4) + '0';
  78.                                 showbuf[9] = (buf[0]&0x0F) + '0';
  79.                                 showbuf[10] = '\0';
  80.                                 SendString(showbuf);
  81.                                 SendString("\r\n");
  82.                                 LcdShowStr(1,3,showbuf);
  83.                                 psec=buf[0];
  84.                         }
  85.                 }
  86.         
  87.                 if(flag2s&&flagset)
  88.                 {        
  89.                 flag2s = 0;
  90.                
  91.                 ack=ReadSensor(buf,&flag);
  92.                 switch (flag)
  93.                         {
  94.                         case 0: SendString("傳感器A發送開始信號\r\n");break;
  95.                         case 1: SendString("傳感器A收到起始信號\r\n");break;
  96.                         case 2: SendString("傳感器A起始1信號超時\r\n");break;
  97.                         case 3: SendString("傳感器A起始2信號超時\r\n");break;
  98.                         case 4: SendString("傳感器A未收到起始信號\r\n");break;
  99.                         default : break;
  100.                         }
  101.                 if(ack)
  102.                         {
  103.                                 ack=0;
  104.                                 addr = buf[0]+buf[1]+buf[2]+buf[3];
  105.                                 if(addr==buf[4])
  106.                                 {
  107.                                         humidity=buf[0]*256+buf[1];
  108.                                         showbuf[0] = '0'+((humidity/100)%10);
  109.                                         showbuf[1] = '0'+((humidity/10)%10);
  110.                                         showbuf[2] = '.';
  111.                                         showbuf[3] = '0'+(humidity%10);
  112.                                         showbuf[4] = '\0';
  113.                                         SendString(showbuf);
  114.                                         SendString("\r\n");
  115.                                         LcdShowStr(2,0,showbuf);
  116.                                        
  117.                                         temperature = (buf[2]*256)+buf[3];        
  118.                                         showbuf[0] = '0'+((temperature/100)%10);
  119.                                         showbuf[1] = '0'+((temperature/10)%10);
  120.                                         showbuf[2] = '.';
  121.                                         showbuf[3] = '0'+(temperature%10);
  122.                                         showbuf[4] = '\0';
  123.                                         SendString(showbuf);
  124.                                         SendString("\r\n");
  125.                                         LcdShowStr(2,1,showbuf);
  126.                                        
  127.                                 }
  128.                                 else
  129.                                         SendString("傳感器A效驗錯誤\r\n");
  130.                                 }
  131.                 else
  132.                         SendString("傳感器A無返回值\r\n");
  133.                 ack=ReadSensorb(buf,&flag);
  134.                 switch (flag)
  135.                 {
  136.                         case 0: SendString("傳感器B發送開始信號\r\n");break;
  137.                         case 1: SendString("傳感器B收到起始信號\r\n");break;
  138.                         case 2: SendString("傳感器B起始1信號超時\r\n");break;
  139.                         case 3: SendString("傳感器B起始2信號超時\r\n");break;
  140.                         case 4: SendString("傳感器B未收到起始信號\r\n");break;
  141.                         default : break;
  142.                 }
  143.                 if(ack)
  144.                 {
  145.                         ack=0;
  146.                
  147.                         addr = buf[0]+buf[1]+buf[2]+buf[3];
  148.                         if(addr==buf[4])
  149.                         {
  150.                                 humidity=buf[0]*256+buf[1];
  151.                                 showbuf[0] = '0'+((humidity/100)%10);
  152.                                 showbuf[1] = '0'+((humidity/10)%10);
  153.                                 showbuf[2] = '.';
  154.                                 showbuf[3] = '0'+(humidity%10);
  155.                                 showbuf[4] = '\0';
  156.                                 SendString(showbuf);
  157.                                 SendString("\r\n");
  158.                                 LcdShowStr(6,0,showbuf);
  159.                                 temperature = (buf[2]*256)+buf[3];        
  160.                                 showbuf[0] = '0'+((temperature/100)%10);
  161.                                 showbuf[1] = '0'+((temperature/10)%10);
  162.                                 showbuf[2] = '.';
  163.                                 showbuf[3] = '0'+(temperature%10);
  164.                                 showbuf[4] = '\0';
  165.                                 SendString(showbuf);
  166.                                 SendString("\r\n");
  167.                                 LcdShowStr(6,1,showbuf);
  168.                         }
  169.                         else
  170.                                 SendString("傳感器B效驗錯誤\r\n");
  171.                 }
  172.                 else
  173.                         SendString("傳感器B無返回值\r\n");
  174.                 }
  175.         }
  176. }

  177. void ConfigTimer0()
  178. {
  179.         AUXR |= 0x80;
  180.         TMOD &= 0xF0;
  181.         TH0 = (65536-33177600/1000)>>8;
  182.         TL0 = 65536-33177600/1000;
  183.         TR0 = 1;
  184.         ET0 = 1;
  185.         EA = 1;
  186. }
  187. void InterruptTimer0() interrupt 1
  188. {
  189.         static unsigned int time2s = 0;
  190.         static unsigned char time200ms = 0;
  191.         time2s++;
  192.         time200ms++;
  193.         if(time200ms >= 200)
  194.         {
  195.                 time200ms = 0;
  196.                 flag200ms = 1;
  197.         }
  198.         if(time2s >= 2000)
  199.         {
  200.                 time2s = 0;
  201.                 flag2s = 1;
  202.         }
  203.         KeyScan();
  204. }
復制代碼

所有程序資料51hei提供下載:
15w.rar (94.58 KB, 下載次數: 51)



評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

沙發
ID:601639 發表于 2020-6-30 18:59 | 只看該作者
很好,功能強大。
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 日韩一级| 亚洲成人精品 | 丁香五月网久久综合 | 久久综合久 | 亚洲免费在线播放 | 成人a网 | 精品国产乱码久久久久久88av | 久久99这里只有精品 | 日本在线精品视频 | 亚洲欧美一区二区三区视频 | 一级黄色毛片 | 免费福利视频一区二区三区 | 91精品中文字幕一区二区三区 | 日韩第一页 | 日日日色 | 日韩第一夜 | 欧洲亚洲精品久久久久 | 日本精品一区二区三区在线观看视频 | 欧美亚州 | 国产精品美女久久久久久免费 | 91精品国产麻豆 | 中文字幕第十一页 | 久久久久久久国产精品视频 | 欧美一区二区三 | 日本理论片好看理论片 | 欧美一区二区三区的 | 欧美精品一区二区免费 | 日韩欧美成人一区二区三区 | 欧美a v在线| 在线观看国产精品一区二区 | 日本精品一区二区三区在线观看 | 精品久久国产 | 国产日产久久高清欧美一区 | 精品91久久 | 男女免费在线观看视频 | 色综合天天天天做夜夜夜夜做 | 亚洲精品久久久久avwww潮水 | 午夜丁香视频在线观看 | 欧美电影大全 | 精品国产不卡一区二区三区 | 狠狠视频 |