{"id":70609,"date":"2026-02-02T05:05:50","date_gmt":"2026-02-01T21:05:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/70609.html"},"modified":"2026-02-02T05:05:50","modified_gmt":"2026-02-01T21:05:50","slug":"%e5%88%86%e6%9e%90%e4%b8%80%e6%ae%b5ds18b20%e6%b8%a9%e5%ba%a6%e6%98%be%e7%a4%ba%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/70609.html","title":{"rendered":"\u5206\u6790\u4e00\u6bb5DS18B20\u6e29\u5ea6\u663e\u793a\u4ee3\u7801"},"content":{"rendered":"<p>\u4e3b\u51fd\u6570<\/p>\n<p>#include &#034;public.h&#034;<\/p>\n<p>void main()<br \/>\n{<br \/>\nu8 i&#061;0;<br \/>\n   int temp_value;<br \/>\nu8 temp_buf[5];<\/p>\n<p>ds18b20_init();\/\/\u521d\u59cb\u5316DS18B20<\/p>\n<p>while(1)<br \/>\n{<br \/>\ni&#043;&#043;;<br \/>\nif(i%50&#061;&#061;0)\/\/\u95f4\u9694\u4e00\u6bb5\u65f6\u95f4\u8bfb\u53d6\u6e29\u5ea6\u503c&#xff0c;\u95f4\u9694\u65f6\u95f4\u8981\u5927\u4e8e\u6e29\u5ea6\u4f20\u611f\u5668\u8f6c\u6362\u6e29\u5ea6\u65f6\u95f4<br \/>\ntemp_value&#061;ds18b20_read_temperture()*10;\/\/\u4fdd\u7559\u6e29\u5ea6\u503c\u5c0f\u6570\u540e\u4e00\u4f4d<br \/>\nif(temp_value&lt;0)\/\/\u8d1f\u6e29\u5ea6<br \/>\n{<br \/>\ntemp_value&#061;-temp_value;<br \/>\ntemp_buf[0]&#061;0x40;\/\/\u663e\u793a\u8d1f\u53f7<br \/>\n}<br \/>\nelse<br \/>\ntemp_buf[0]&#061;0x00;\/\/\u4e0d\u663e\u793a<br \/>\ntemp_buf[1]&#061;gsmg_code[temp_value\/1000];\/\/\u767e\u4f4d<br \/>\ntemp_buf[2]&#061;gsmg_code[temp_value%1000\/100];\/\/\u5341\u4f4d<br \/>\ntemp_buf[3]&#061;gsmg_code[temp_value%1000%100\/10]|0x80;\/\/\u4e2a\u4f4d&#043;\u5c0f\u6570\u70b9<br \/>\ntemp_buf[4]&#061;gsmg_code[temp_value%1000%100%10];\/\/\u5c0f\u6570\u70b9\u540e\u4e00\u4f4d<br \/>\nsmg_display(temp_buf,4);<br \/>\n}<br \/>\n}<\/p>\n<p>\u6570\u7801\u7ba1\u51fd\u6570<\/p>\n<p>#define SMG_A_DP_PORTP0\/\/\u4f7f\u7528\u5b8f\u5b9a\u4e49\u6570\u7801\u7ba1\u6bb5\u7801\u53e3<\/p>\n<p>\/\/\u5b9a\u4e49\u6570\u7801\u7ba1\u4f4d\u9009\u4fe1\u53f7\u63a7\u5236\u811a<br \/>\nsbit LSA&#061;P2^2;<br \/>\nsbit LSB&#061;P2^3;<br \/>\nsbit LSC&#061;P2^4;<br \/>\n\/\/\u5171\u9634\u6781\u6570\u7801\u7ba1\u663e\u793a0~F\u7684\u6bb5\u7801\u6570\u636e<br \/>\nu8 gsmg_code[17]&#061;{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,<br \/>\n0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};<\/p>\n<p>void smg_display(u8 dat[],u8 pos)<br \/>\n{<br \/>\nu8 i&#061;0;<br \/>\nu8 pos_temp&#061;pos-1;<\/p>\n<p>for(i&#061;pos_temp;i&lt;8;i&#043;&#043;)<br \/>\n{<br \/>\n   switch(i)\/\/\u4f4d\u9009<br \/>\n{<br \/>\ncase 0: LSC&#061;1;LSB&#061;1;LSA&#061;1;break;<br \/>\ncase 1: LSC&#061;1;LSB&#061;1;LSA&#061;0;break;<br \/>\ncase 2: LSC&#061;1;LSB&#061;0;LSA&#061;1;break;<br \/>\ncase 3: LSC&#061;1;LSB&#061;0;LSA&#061;0;break;<br \/>\ncase 4: LSC&#061;0;LSB&#061;1;LSA&#061;1;break;<br \/>\ncase 5: LSC&#061;0;LSB&#061;1;LSA&#061;0;break;<br \/>\ncase 6: LSC&#061;0;LSB&#061;0;LSA&#061;1;break;<br \/>\ncase 7: LSC&#061;0;LSB&#061;0;LSA&#061;0;break;<br \/>\n}<br \/>\nSMG_A_DP_PORT&#061;dat[i-pos_temp];\/\/\u4f20\u9001\u6bb5\u9009\u6570\u636e<br \/>\ndelay_10us(100);\/\/\u5ef6\u65f6\u4e00\u6bb5\u65f6\u95f4&#xff0c;\u7b49\u5f85\u663e\u793a\u7a33\u5b9a<br \/>\nSMG_A_DP_PORT&#061;0x00;\/\/\u6d88\u97f3<br \/>\n}<br \/>\n}<\/p>\n<p>DS18B20\u51fd\u6570<\/p>\n<p>sbit DS18B20_PORT&#061;P3^7;\/\/DS18B20\u6570\u636e\u53e3\u5b9a\u4e49<\/p>\n<p>void ds18b20_reset(void)<br \/>\n{<br \/>\nDS18B20_PORT&#061;0;\/\/\u62c9\u4f4eDQ<br \/>\ndelay_10us(75);\/\/\u62c9\u4f4e750us,<br \/>\nDS18B20_PORT&#061;1;\/\/DQ&#061;1<br \/>\ndelay_10us(2);\/\/20US<br \/>\n}<\/p>\n<p>u8 ds18b20_check(void)<br \/>\n{<br \/>\nu8 time_temp&#061;0;<\/p>\n<p>while(DS18B20_PORT&amp;&amp;time_temp&lt;10)<br \/>\n{<br \/>\ntime_temp&#043;&#043;;<br \/>\ndelay_10us(1);<br \/>\n}<br \/>\nif(time_temp&gt;&#061;10)return 1;<br \/>\nelse time_temp&#061;0;<br \/>\nwhile((!DS18B20_PORT)&amp;&amp;time_temp&lt;20)<br \/>\n{<br \/>\ntime_temp&#043;&#043;;<br \/>\ndelay_10us(1);<br \/>\n}<br \/>\nif(time_temp&gt;&#061;20)return 1;<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>u8 ds18b20_read_bit(void)<br \/>\n{<br \/>\nu8 dat&#061;0;<\/p>\n<p>DS18B20_PORT&#061;0;<br \/>\n_nop_();_nop_();<br \/>\nDS18B20_PORT&#061;1;<br \/>\n_nop_();_nop_();<br \/>\nif(DS18B20_PORT)dat&#061;1;<br \/>\nelse dat&#061;0;<br \/>\ndelay_10us(5);<br \/>\nreturn dat;<br \/>\n} <\/p>\n<p>u8 ds18b20_read_byte(void)<br \/>\n{<br \/>\nu8 i&#061;0;<br \/>\nu8 dat&#061;0;<br \/>\nu8 temp&#061;0;<\/p>\n<p>for(i&#061;0;i&lt;8;i&#043;&#043;)<br \/>\n{<br \/>\ntemp&#061;ds18b20_read_bit();<br \/>\ndat&#061;(temp&lt;&lt;7)|(dat&gt;&gt;1);<br \/>\n}<br \/>\nreturn dat;<br \/>\n}<\/p>\n<p>void ds18b20_write_byte(u8 dat)<br \/>\n{<br \/>\nu8 i&#061;0;<br \/>\nu8 temp&#061;0;<\/p>\n<p>for(i&#061;0;i&lt;8;i&#043;&#043;)<br \/>\n{<br \/>\ntemp&#061;dat&amp;0x01;<br \/>\ndat&gt;&gt;&#061;1;<br \/>\nif(temp)<br \/>\n{<br \/>\nDS18B20_PORT&#061;0;<br \/>\n_nop_();_nop_();<br \/>\nDS18B20_PORT&#061;1;<br \/>\ndelay_10us(6);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nDS18B20_PORT&#061;0;<br \/>\ndelay_10us(6);<br \/>\nDS18B20_PORT&#061;1;<br \/>\n_nop_();_nop_();<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>void ds18b20_start(void)<br \/>\n{<br \/>\nds18b20_reset();<br \/>\nds18b20_check();<br \/>\nds18b20_write_byte(0xcc);<br \/>\n    ds18b20_write_byte(0x44);<br \/>\n}<\/p>\n<p>u8 ds18b20_init(void)<br \/>\n{<br \/>\nds18b20_reset();<br \/>\nreturn ds18b20_check();<br \/>\n}<\/p>\n<p>float ds18b20_read_temperture(void)<br \/>\n{<br \/>\nfloat temp;<br \/>\nu8 dath&#061;0;<br \/>\nu8 datl&#061;0;<br \/>\nu16 value&#061;0;<\/p>\n<p>ds18b20_start();<br \/>\nds18b20_reset();<br \/>\nds18b20_check();<br \/>\nds18b20_write_byte(0xcc);<br \/>\n    ds18b20_write_byte(0xbe);<\/p>\n<p>datl&#061;ds18b20_read_byte();<br \/>\ndath&#061;ds18b20_read_byte();<br \/>\nvalue&#061;(dath&lt;&lt;8)&#043;datl;<\/p>\n<p>if((value&amp;0xf800)&#061;&#061;0xf800)<br \/>\n{<br \/>\nvalue&#061;(~value)&#043;1;<br \/>\ntemp&#061;value*(-0.0625);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\ntemp&#061;value*0.0625;<br \/>\n}<br \/>\nreturn temp;<br \/>\n}<\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5b9e\u73b0\u7684\u529f\u80fd\u662f&#xff0c;\u5728\u52a8\u6001\u6570\u7801\u7ba1\u4e0a\u663e\u793a4\u4f4d\u6e29\u5ea6\u503c&#xff0c;\u5305\u62ec3\u4f4d\u6574\u6570\u548c1\u4f4d\u5c0f\u6570\u3002<\/p>\n<p>\u76f4\u63a5\u770b\u4ee3\u7801\u53ef\u80fd\u6709\u4e9b\u7e41\u6742&#xff0c;\u5982\u679c\u6211\u4eec\u628a\u5b83\u4eec\u6309\u529f\u80fd\u6a21\u5757\u5212\u5206&#xff0c;\u5c31\u50cf\u6469\u6258\u8f66\u5305\u62ec\u6838\u5fc3\u90e8\u5206\u2014\u2014\u53d1\u52a8\u673a\u3001\u63a7\u5236\u90e8\u5206\u2014\u2014\u9f99\u5934\u3001\u9a71\u52a8\u90e8\u5206\u2014\u2014\u8f6e\u80ce&#xff0c;\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u96c6\u4e2d\u4e00\u70b9\u3002<\/p>\n<p>\u7531\u4e8eDS18B20\u5728\u6e29\u5ea6\u68c0\u6d4b\u8d77\u5230\u5341\u5206\u91cd\u8981\u7684\u4f5c\u7528&#xff0c;\u672c\u6587\u51e0\u4e4e80%\u7684\u5185\u5bb9\u90fd\u662f\u4ecb\u7ecd\u5b83&#xff0c;\u7136\u540e\u82b1\u8d39\u8f83\u5c11\u7684\u7b14\u58a8\u4ecb\u7ecd\u6570\u7801\u7ba1\u6309\u663e\u793a\u4e2a\u5341\u767e\u4ee5\u53ca\u5c0f\u6570\u70b9\u4f4d\u7684\u539f\u7406&#xff0c;\u6700\u540e\u4f1a\u6574\u5408\u524d\u9762\u4e24\u8005&#xff0c;\u518d\u5206\u6790\u4e00\u4e0b\u4e3b\u51fd\u6570\u7684\u542b\u4e49\u3002\u524d\u8a00\u5c31\u8bb2\u8fd9\u4e48\u591a&#xff0c;\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u770b\u770b\u8fd9\u7bc7\u6587\u7ae0\u7684\u4e3b\u89d2\u2014\u2014DS18B20<\/p>\n<h2>\u4e00\u3001DS18B20\u90e8\u5206<\/h2>\n<p>\u4ec0\u4e48\u662fDS18B20&#xff1f;\u4f60\u7684\u76f4\u89c9\u4e00\u5b9a\u662f\u201c\u6e29\u5ea6\u4f20\u611f\u5668\u201d&#xff0c;\u5b9e\u9645\u4e0a\u5b83\u8fd8\u6709\u5f88\u591a\u4f60\u4e0d\u77e5\u9053\u7684\u672c\u4e8b\u3002<\/p>\n<p>\u9996\u5148&#xff0c;DS18B20\u5e76\u4e0d\u5168\u662f\u6211\u4eec\u719f\u77e5\u7684\u4e09\u5f15\u811a&#xff0c;\u5b83\u8fd8\u6709\u5176\u4ed6\u4e24\u79cd\u5f62\u6001<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"254\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210546-697fc02a157d5.png\" width=\"268\" \/><\/p>\n<p>\u6211\u4eec\u4f7f\u7528\u7684DS18B20\u91c7\u7528\u7684TO-92\u5c01\u88c5&#xff0c;\u53ea\u6709\u4e09\u4e2a\u5f15\u811a\u3002<\/p>\n<p>\u5176\u6b21&#xff0c;\u8fd9\u5757\u5c0f\u5c0f\u7684\u6e29\u5ea6\u4f20\u611f\u5668\u5e76\u4e0d\u53ea\u8d1f\u8d23\u6d4b\u6e29&#xff0c;\u5176\u5185\u90e8\u8fd8\u5d4c\u5165\u4e86\u4e00\u4e2aAD\u8f6c\u6362\u5668&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;DS18B20\u5728\u81ea\u5df1\u6d4b\u5f97\u6e29\u5ea6\u6a21\u62df\u91cf\u540e&#xff0c;\u53c8\u81ea\u5df1\u5c06\u5176\u8f6c\u6362\u6210\u6570\u5b57\u91cf\u8f93\u51fa&#xff0c;\u4e00\u6c14\u5475\u6210\u3002<\/p>\n<p>\u6700\u540e&#xff0c;\u522b\u770bDS18B20\u5f15\u811a\u5f88\u5c11&#xff0c;\u5b9e\u9645\u4e0a&#xff0c;\u53ef\u4ee5\u66f4\u5c11\u3002\u5728\u5bc4\u751f\u7535\u6e90\u6a21\u5f0f\u4e0b&#xff0c;VDD\u5f15\u811a\u90fd\u53ef\u4ee5\u4e0d\u9700\u8981&#xff0c;\u53ea\u9760DQ\u5f15\u811a\u5728\u63a5\u6536\u6570\u636e\u7684\u540c\u65f6&#xff0c;\u987a\u4fbf\u7ed9DS18B20\u4f9b\u7535\u3002<\/p>\n<hr \/>\n<h3>1.\u6982\u8ff0<\/h3>\n<p>DS18B20\u6570\u5b57\u6e29\u5ea6\u8ba1&#xff0c;\u53ef\u63d0\u4f9b9~12\u4f4d\u5206\u8fa8\u7387\u7684\u6444\u6c0f\u6e29\u5ea6\u6d4b\u91cf&#xff0c;\u53ef\u914d\u7f6e\u4e0a\u4e0b\u9650\u62a5\u8b66\u529f\u80fd&#xff08;\u65ad\u7535\u540e\u4e0d\u64e6\u9664&#xff09;&#xff0c;\u53ef\u901a\u8fc7DQ\u5f15\u811a\u4e0e\u4e2d\u592eMCU\u8fde\u63a5\u3002\u6b64\u5916&#xff0c;\u6bcf\u4e00\u5757DS18B20\u90fd\u6709\u4e00\u4e2a\u72ec\u4e00\u65e0\u4e8c\u7684\u201c\u8eab\u4efd\u8bc1\u201d\u2014\u2014\u5b58\u50a8\u4e8eROM\u76848\u4f4d\u5bb6\u65cf\u7801&#xff0c;\u7406\u8bba\u4e0a\u5355\u7247\u673a\u53ef\u4ee5\u540c\u65f6\u63a7\u52362\u76848\u6b21\u65b9\u4e2aDS18B20\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u628a\u76ee\u5149\u8f6c\u5411\u90a3\u4e2a\u4f20\u5947\u5f15\u811a\u2014\u2014DQ&#xff0c;\u5b83\u90fd\u80fd\u4f20\u8f93\u54ea\u4e9b\u6570\u636e&#xff1f;\u8fd9\u53d6\u51b3\u4e8eDS18B20\u91cc\u9762\u653e\u4e86\u4ec0\u4e48\u6570\u636e<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"208\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210546-697fc02a47d57.png\" width=\"538\" \/><\/p>\n<p>\u5ffd\u7565\u5de6\u8fb9\u7684\u7535\u8def&#xff0c;\u53f3\u8fb9\u5c31\u662fDS18B20\u7684\u4e09\u4e2a\u5b58\u50a8\u5668\u2014\u201464\u4f4d\u7684ROM\u3001Scratchpad&#xff08;\u6682\u5b58\u5668&#xff09;\u3001EEPROM&#xff08;\u975e\u6613\u5931\u6027\u5b58\u50a8\u5668&#xff09;&#xff0c;\u6211\u4eec\u770b\u770b\u90fd\u653e\u4e86\u4e9b\u4ec0\u4e48\u5728\u91cc\u9762<\/p>\n<h4>64\u4f4d\u5149\u523bROM<\/h4>\n<p>ROM\u53ea\u53ef\u8bfb&#xff0c;\u4e0d\u53ef\u5199\u5165\u300264\u4f4dROM\u5206\u6210\u4e09\u90e8\u5206&#xff0c;\u5206\u522b\u662f<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tr>\u5b57\u8282\u5185\u5bb9\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>Byte 0<\/td>\n<td>8\u4f4d\u5bb6\u65cf\u7801&#xff08;family code&#xff09;<\/td>\n<td>\u56fa\u5b9a\u4e3a0x28(DS18B20\u7684\u6807\u8bc6)<\/td>\n<\/tr>\n<tr>\n<td>Byte 1~6<\/td>\n<td>48\u4f4d\u552f\u4e00\u5e8f\u5217\u53f7<\/td>\n<td>\u5168\u7403\u552f\u4e00\u7684\u8bbe\u5907ID&#xff0c;\u7531\u5382\u5bb6\u5149\u523b\u5199\u5165<\/td>\n<\/tr>\n<tr>\n<td>Byte 7<\/td>\n<td>8\u4f4dCRC\u6821\u9a8c\u7801<\/td>\n<td>\u5faa\u73af\u5197\u4f59\u6821\u9a8c\u5197\u4f59<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5355\u7247\u673a\u901a\u8fc7Read Rom[0x33]\u6216Search Rom[0xf0]\u547d\u4ee4\u8bfb\u53d6ROM\u4e2d\u768464\u4f4d\u6570\u636e<\/p>\n<h4>\u6682\u5b58\u5668&#xff08;Scatchpad&#xff09;<\/h4>\n<p>\u8fd9\u91cc\u662f\u6e29\u5ea6\u6d4b\u91cf\u548c\u901a\u4fe1\u7684\u6838\u5fc3\u7f13\u51b2\u533a&#xff0c;\u65ad\u7535\u540e\u6570\u636e\u4e22\u5931&#xff0c;\u6240\u6709\u6e29\u5ea6\u8f6c\u6362\u7ed3\u679c\u548c\u914d\u7f6e\u6570\u636e\u9996\u5148\u5199\u5165\u6b64\u5904&#xff08;\u6ce8\u610f\u8fd9\u4e2a\u201c\u9996\u5148\u201d&#xff09;\u3002\u6682\u5b58\u5668\u51719\u4e2a\u5b57\u8282&#xff0c;72\u4f4d&#xff0c;\u53ef\u5206\u6210\u4e94\u90e8\u5206<\/p>\n<table align=\"center\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:592px\">\n<tr>\u5b57\u8282\u5730\u5740\u540d\u79f0\u529f\u80fd\u662f\u5426\u53ef\u6620\u5c04\u5230EEPROM<\/tr>\n<tbody>\n<tr>\n<td style=\"text-align:center\">Byte 0<\/td>\n<td style=\"text-align:center;width:91px\">\u6e29\u5ea6LSB<\/td>\n<td style=\"text-align:center;width:214px\">\u6e29\u5ea6\u503c\u4f4e\u56db\u4f4d(\u5305\u542b\u5c0f\u6570\u90e8\u5206)<\/td>\n<td style=\"text-align:center;width:217px\">\u5426&#xff08;\u8fd0\u884c\u65f6\u6570\u636e&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 1<\/td>\n<td style=\"text-align:center;width:91px\">\u6e29\u5ea6MSB<\/td>\n<td style=\"text-align:center;width:214px\">\u6e29\u5ea6\u503c\u9ad8 8 \u4f4d&#xff08;\u5305\u542b\u7b26\u53f7\u4f4d&#xff09;<\/td>\n<td style=\"text-align:center;width:217px\">\u5426&#xff08;\u8fd0\u884c\u65f6\u6570\u636e&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 2<\/td>\n<td style=\"text-align:center;width:91px\">TH\u5bc4\u5b58\u5668<\/td>\n<td style=\"text-align:center;width:214px\">\u9ad8\u6e29\u62a5\u8b66\u9608\u503c<\/td>\n<td style=\"text-align:center;width:217px\">\u662f&#xff08;\u5b57\u8282 2 \u7684 EEPROM \u5907\u4efd&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 3<\/td>\n<td style=\"text-align:center;width:91px\">TL\u5bc4\u5b58\u5668<\/td>\n<td style=\"text-align:center;width:214px\">\u4f4e\u6e29\u62a5\u8b66\u9608\u503c<\/td>\n<td style=\"text-align:center;width:217px\">\u662f&#xff08;\u5b57\u8282 3 \u7684 EEPROM \u5907\u4efd&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 4<\/td>\n<td style=\"text-align:center;width:91px\">\u914d\u7f6e\u5bc4\u5b58\u5668<\/td>\n<td style=\"text-align:center;width:214px\">\u5206\u8fa8\u7387\u8bbe\u7f6e<\/td>\n<td style=\"text-align:center;width:217px\">\u662f&#xff08;\u5b57\u8282 4 \u7684 EEPROM \u5907\u4efd&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 5<\/td>\n<td style=\"text-align:center;width:91px\">\u4fdd\u7559<\/td>\n<td style=\"text-align:center;width:214px\"><\/td>\n<td style=\"text-align:center;width:217px\">\u5426<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 6<\/td>\n<td style=\"text-align:center;width:91px\">\u4fdd\u7559<\/td>\n<td style=\"text-align:center;width:214px\"><\/td>\n<td style=\"text-align:center;width:217px\">\u5426<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 7<\/td>\n<td style=\"text-align:center;width:91px\">\u4fdd\u7559<\/td>\n<td style=\"text-align:center;width:214px\"><\/td>\n<td style=\"text-align:center;width:217px\">\u5426<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 8<\/td>\n<td style=\"text-align:center;width:91px\">CRC\u5b57\u8282<\/td>\n<td style=\"text-align:center;width:214px\">\u5bf9Byte0~7\u7684\u5faa\u73af\u5197\u4f59\u6821\u9a8c\u7801<\/td>\n<td style=\"text-align:center;width:217px\">\u5426<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f\u5230&#xff0c;\u4e0a\u8868\u4e2d\u589e\u52a0\u4e86\u4e00\u5217\u201c\u662f\u5426\u53ef\u6620\u5c04\u5230EEPROM\u201d&#xff0c;\u53ef\u4ee5\u628a\u8fd9\u4e2aEEPROM\u7406\u89e3\u6210\u4fdd\u9669\u7bb1&#xff0c;\u6211\u4eec\u628a\u6bd4\u8f83\u91cd\u8981\u7684\u6570\u636e\u5b58\u8fdb\u53bb&#xff0c;\u65ad\u7535\u540e\u5176\u4ed6\u6570\u636e\u88ab\u6e05\u9664&#xff0c;\u4fdd\u9669\u7bb1\u7684\u6570\u636e\u4f9d\u7136\u4fdd\u7559&#xff0c;\u8fd9\u6837\u4e0b\u6b21\u4e0a\u7535\u65f6\u8fd9\u4e9b\u6570\u636e\u5c31\u53ef\u4ee5\u76f4\u63a5\u53d6\u51fa\u6765\u7528\u4e86\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u7528DS\u81ea\u5df1\u7684\u8bed\u8a00\u8868\u8ff0\u5982\u4e0b&#xff1a;<\/p>\n<p>Write Scratchpad[0x4e]&#xff1a;\u5355\u7247\u673a\u901a\u8fc7 \u5411\u6682\u5b58\u5668\u4e2d\u5199\u5165TH\u3001TL\u548c\u914d\u7f6e\u6570\u636e&#xff1b;<span style=\"color:#956fe7\">&#xff08;\u52aa\u529b\u6323\u94b1&#xff09;<\/span><\/p>\n<p>Read\u00a0Scratchpad[0xbe]&#xff1a;\u5355\u7247\u673a\u901a\u8fc7 \u5411\u6682\u5b58\u5668\u4e2d\u8bfb\u53d6TH\u3001TL\u548c\u914d\u7f6e\u6570\u636e&#xff0c;\u4f46\u53ef\u4ee5\u968f\u65f6\u901a\u8fc7\u590d\u4f4d\u4fe1\u53f7\u7ec8\u6b62\u8bfb\u53d6&#xff1b;<span style=\"color:#4da8ee\">&#xff08;\u5408\u7406\u82b1\u94b1&#xff09;<\/span><\/p>\n<p>Copy\u00a0Scratchpad[0x48] &#xff1a;\u628a\u6682\u5b58\u5668\u4e2d\u7684TH\u3001TL\u548c\u914d\u7f6e\u6570\u636e\u590d\u5236\u5230EEPROM&#xff1b;<span style=\"color:#1c7331\">&#xff08;\u5f80\u4fdd\u9669\u7bb1\u5b58\u94b1&#xff09;<\/span><\/p>\n<p>Recall EE[0xb8] &#xff1a;&#xff08;\u518d\u6b21\u4e0a\u7535\u540e&#xff09;\u628aEEPROM\u4e2d\u7684TH\u3001TL\u548c\u914d\u7f6e\u6570\u636e\u590d\u5236\u5230\u6682\u5b58\u5668<span style=\"color:#ff9900\">&#xff08;\u4ece\u4fdd\u9669\u7bb1\u53d6\u94b1&#xff09;<\/span><\/p>\n<h4>EEPROM&#xff08;\u975e\u6613\u5931\u6027\u5b58\u50a8\u5668&#xff09;<\/h4>\n<p>\u8fd9\u4e2a\u5b58\u50a8\u5668\u76f8\u5f53\u4e8e\u4fdd\u9669\u7bb1&#xff0c;\u7528\u4e8e\u4fdd\u62a4\u62a5\u8b66\u9608\u503c\u548c\u5206\u8fa8\u7387\u914d\u7f6e&#xff0c;\u6389\u7535\u4e5f\u4e0d\u4e22\u5931\u3002\u8fd9\u4e2a\u4fdd\u9669\u7bb1\u5f88\u5c0f&#xff0c;\u53ea\u5b58\u4e86\u4e09\u6837\u4e1c\u897f<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tr>EEPROM\u5730\u5740\u6620\u5c04\u7684\u6682\u5b58\u5668\u5b57\u8282\u5b58\u50a8\u5185\u5bb9<\/tr>\n<tbody>\n<tr>\n<td>Address 0<\/td>\n<td>Byte2 (TH)<\/td>\n<td>\u9ad8\u6e29\u62a5\u8b66\u5668<\/td>\n<\/tr>\n<tr>\n<td>Address 1<\/td>\n<td>Byte 3(TL)<\/td>\n<td>\u4f4e\u6e29\u62a5\u8b66\u5668<\/td>\n<\/tr>\n<tr>\n<td>Address 2<\/td>\n<td>Byte 4(Configuration)<\/td>\n<td>\u5206\u8fa8\u7387\u914d\u7f6e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>EEPROM\u7684\u4e3b\u8981\u529f\u80fd\u5728\u4ecb\u7ecd\u6682\u5b58\u5668\u4e2d\u5c31\u63d0\u8fc7\u4e86&#xff0c;\u5206\u522b\u662f\u5b58\u94b1\u548c\u53d6\u94b1<\/p>\n<p>Copy\u00a0Scratchpad[0x48] &#xff1a;\u628a\u6682\u5b58\u5668\u4e2d\u7684TH\u3001TL\u548c\u914d\u7f6e\u6570\u636e\u590d\u5236\u5230EEPROM&#xff1b;<span style=\"color:#1c7331\">&#xff08;\u5b58\u94b1&#xff09;<\/span><\/p>\n<p>Recall EE[0xb8] &#xff1a;&#xff08;\u518d\u6b21\u4e0a\u7535\u540e&#xff09;\u628aEEPROM\u4e2d\u7684TH\u3001TL\u548c\u914d\u7f6e\u6570\u636e\u590d\u5236\u5230\u6682\u5b58\u5668<span style=\"color:#ff9900\">&#xff08;\u53d6\u94b1&#xff09;<\/span><\/p>\n<hr \/>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u6e05\u695a\u4e86DS18B20\u4e09\u4e2a\u5b58\u50a8\u5668\u4e2d&#xff0c;ROM\u5b58\u653e\u201c\u8eab\u4efd\u8bc1\u53f7\u201d&#xff0c;\u6682\u5b58\u5668\u5b58\u653e\u6e29\u5ea6\u6570\u636e\u3001\u62a5\u8b66\u9608\u503c\u548c\u914d\u7f6e\u6570\u636e&#xff0c;EEPROM\u201c\u5b58\u94b1\u201d&#xff0c;\u5982\u6b64\u591a\u529f\u80fd&#xff0c;\u5982\u6b64\u591a\u6570\u636e&#xff0c;\u6211\u4eec\u6765\u770b\u770b\u52bf\u5355\u529b\u8584\u7684DQ\u5f15\u811a\u662f\u5982\u4f55\u8fde\u63a5\u4e24\u8005\u7684\u3002<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"272\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210546-697fc02ab1563.png\" width=\"594\" \/><\/p>\n<h3>2.\u4ee3\u7801\u5206\u6790<\/h3>\n<h4>\u590d\u4f4d\u51fd\u6570<\/h4>\n<p>void ds18b20_reset(void)<br \/>\n{<br \/>\nDS18B20_PORT&#061;0;\/\/\u62c9\u4f4eDQ<br \/>\ndelay_10us(75);\/\/\u62c9\u4f4e750us,<br \/>\nDS18B20_PORT&#061;1;\/\/DQ&#061;1<br \/>\ndelay_10us(2);\/\/20US<br \/>\n}<\/p>\n<p>DS18B20\u7684\u901a\u4fe1\u6d41\u7a0b\u59cb\u4e8e\u521d\u59cb\u5316\u5e8f\u5217&#xff0c;\u8be5\u5e8f\u5217\u7531\u4e3b\u8bbe\u5907\u53d1\u9001\u7684\u590d\u4f4d\u8109\u51b2\u548cDS18B20\u53d1\u51fa\u7684\u5e94\u7b54\u8109\u51b2\u7ec4\u6210&#xff0c;\u4e0a\u9762\u4ee3\u7801\u4f53\u73b0\u7684\u662f\u590d\u4f4d\u8109\u51b2\u90e8\u5206\u3002\u4e3a\u4ec0\u4e48\u8981\u5148\u62c9\u4f4eDQ\u4e00\u6bb5\u65f6\u95f4\u518d\u62c9\u9ad8\u5462&#xff1f;\u6211\u4eec\u770b\u4e00\u4e0bDS\u624b\u518c\u91cc\u7684\u521d\u59cb\u5316\u65f6\u5e8f\u56fe<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"210\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210548-697fc02c0adaa.png\" width=\"551\" \/><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"147\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210548-697fc02c7a978.png\" width=\"352\" \/><\/p>\n<p>\u5de6\u8fb9\u90e8\u5206\u662f\u590d\u4f4d\u8109\u51b2&#xff0c;\u5148\u62c9\u4f4e\u603b\u7ebf&#xff08;DQ&#xff09;\u6700\u5c11480\u5fae\u79d2&#xff0c;\u4ee3\u7801\u4e2d\u62c9\u4f4e\u4e86750\u5fae\u79d2&#xff1b;\u4e4b\u540e\u518d\u7f13\u6162\u62c9\u9ad8<\/p>\n<hr \/>\n<h4>\u68c0\u6d4b\u51fd\u6570<\/h4>\n<p>u8 ds18b20_check(void)<br \/>\n{<br \/>\nu8 time_temp&#061;0;<\/p>\n<p>while(DS18B20_PORT&amp;&amp;time_temp&lt;10)\/\/\u7b49\u5f85DQ\u4e3a\u4f4e\u7535\u5e73&#xff0c;\u5faa\u73af\u68c0\u6d4bDQ\u5f15\u811a&#xff08;DS_PORT&#xff09;\u662f\u5426\u4e3a\u4f4e\u7535\u5e73<br \/>\n{<br \/>\ntime_temp&#043;&#043;;<br \/>\ndelay_10us(1);<br \/>\n}<br \/>\nif(time_temp&gt;&#061;10)return 1;\/\/\u5982\u679c\u8d85\u65f6\u5219\u5f3a\u5236\u8fd4\u56de1<br \/>\nelse time_temp&#061;0;\/\/\u5982\u679c\u6ca1\u8d85\u65f6&#xff0c;\u5c31\u628atime_temp\u590d\u4f4d<br \/>\nwhile((!DS18B20_PORT)&amp;&amp;time_temp&lt;20)\/\/\u7b49\u5f85DQ\u4e3a\u9ad8\u7535\u5e73<br \/>\n{<br \/>\ntime_temp&#043;&#043;;<br \/>\ndelay_10us(1);<br \/>\n}<br \/>\nif(time_temp&gt;&#061;20)return 1;\/\/\u5982\u679c\u8d85\u65f6\u5219\u5f3a\u5236\u8fd4\u56de1<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>\u5728\u590d\u4f4d\u5b8c\u6210\u4e4b\u540e&#xff0c;DS\u8fd8\u9700\u8981\u4ea7\u751f\u4e00\u4e2a60~240\u5fae\u79d2\u7684\u4f4e\u7535\u5e73&#xff0c;\u4ee5\u6b64\u5411\u5355\u7247\u673a\u8868\u660e <span style=\"color:#38d8f0\">\u201c\u6211\u6d3b\u7740\u5462\u201d<\/span><span style=\"color:null\">\u3002\u4e0a\u9762\u4ee3\u7801\u7684\u76ee\u7684\u5c31\u662f\u4ea7\u751f\u8fd9\u4e2a60~240\u5fae\u79d2\u7684\u4f4e\u5e73\u3002\u5982\u4f55\u4ea7\u751f\u5462&#xff1f;<\/span><\/p>\n<p>while(DS18B20_PORT&amp;&amp;time_temp&lt;10)\/\/\u7b49\u5f85DQ\u4e3a\u4f4e\u7535\u5e73&#xff0c;\u5faa\u73af\u68c0\u6d4bDQ\u5f15\u811a&#xff08;DS_PORT&#xff09;\u662f\u5426\u4e3a\u4f4e\u7535\u5e73<br \/>\n{<br \/>\ntime_temp&#043;&#043;;<br \/>\ndelay_10us(1);<br \/>\n}<\/p>\n<p>DS18B20_PORT\u5c31\u662fDQ&#xff0c;\u5faa\u73af\u68c0\u6d4b10\u6b21DQ\u662f\u5426\u662f\u4f4e\u7535\u5e73&#xff0c;\u5373\u662f\u5426\u6709100\u5fae\u79d2\u7684\u4f4e\u7535\u5e73\u72b6\u6001<\/p>\n<p>if(time_temp&gt;&#061;10)return 1;\/\/\u5982\u679c\u8d85\u65f6\u5219\u5f3a\u5236\u8fd4\u56de1<br \/>\nelse time_temp&#061;0;\/\/\u5982\u679c\u6ca1\u8d85\u65f6&#xff0c;\u5c31\u628atime_temp\u590d\u4f4d<\/p>\n<p>\u5982\u679c\u68c0\u6d4b10\u6b21\u4e4b\u540e\u7b2c11\u6b21DQ\u8fd8\u662f\u4f4e\u7535\u5e73&#xff0c;\u4e00\u5b9a\u662f\u8fd9\u5b69\u5b50\u7761\u7740\u4e86&#xff0c;\u5c31\u5f3a\u5236\u8fd4\u56de1&#xff1b;<\/p>\n<p>\u5982\u679c\u68c0\u6d4b\u5341\u6b21\u4e4b\u5185DQ\u80fd\u81ea\u5df1\u62c9\u9ad8&#xff0c;\u5c31\u628a\u8ba1\u6570\u5668time_temp\u91cd\u542f&#xff0c;\u4ee5\u5907\u4e0b\u4e00\u6b21\u68c0\u6d4b\u3002<\/p>\n<p>while((!DS18B20_PORT)&amp;&amp;time_temp&lt;20)\/\/\u7b49\u5f85DQ\u4e3a\u9ad8\u7535\u5e73<br \/>\n{<br \/>\ntime_temp&#043;&#043;;<br \/>\ndelay_10us(1);<br \/>\n}<br \/>\nif(time_temp&gt;&#061;20)return 1;\/\/\u5982\u679c\u8d85\u65f6\u5219\u5f3a\u5236\u8fd4\u56de1<\/p>\n<p>DQ\u81ea\u5df1\u62c9\u9ad8\u540e&#xff0c;\u8fd8\u8981\u68c0\u6d4b\u5b83\u62c9\u9ad8\u4e86\u591a\u5c11\u5fae\u79d2&#xff0c;\u56e0\u4e3a\u4e0a\u5347\u6cbf\u8981\u4fdd\u6301\u81f3\u5c11200\u5fae\u79d2<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"153\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210548-697fc02c98e24.png\" width=\"374\" \/><\/p>\n<hr \/>\n<h4>\u6309\u4f4d\u8bfb\u53d6<\/h4>\n<p>u8 ds18b20_read_bit(void)<br \/>\n{<br \/>\nu8 dat&#061;0;<\/p>\n<p>DS18B20_PORT&#061;0;<br \/>\n_nop_();_nop_();<br \/>\nDS18B20_PORT&#061;1;<br \/>\n_nop_();_nop_();<br \/>\nif(DS18B20_PORT)dat&#061;1;<br \/>\nelse dat&#061;0;<br \/>\ndelay_10us(5);\/\/\u786e\u4fdd\u6574\u4e2a\u65f6\u9699\u957f\u5ea6<br \/>\nreturn dat;<br \/>\n} <\/p>\n<p>DS18\u521d\u59cb\u5316\u5b8c\u6210\u540e&#xff0c;\u5c31\u8981\u8fdb\u884c\u6570\u636e\u4f20\u8f93&#xff0c;\u4ee5\u4e0a\u4ee3\u7801\u4e2d&#xff0c;\u5355\u7247\u673a\u901a\u8fc7DQ\u4eceDS18\u4e2d\u8bfb\u4e00\u4e2a\u4f4d\u3002\u6211\u4eec\u6ce8\u610f\u5230&#xff0c;\u8fd9\u91cc\u51fa\u73b0\u4e86\u548c\u521d\u59cb\u5316\u7684\u590d\u4f4d\u5f88\u50cf\u7684\u62c9\u4f4e\u5ef6\u65f6\u518d\u62c9\u9ad8\u7684\u64cd\u4f5c&#xff0c;\u6211\u4eec\u770b\u770b\u5199\u6570\u636e\u7684\u65f6\u5e8f\u56fe<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"174\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210548-697fc02cb2dde.png\" width=\"612\" \/><\/p>\n<p>\u5355\u7247\u673a\u8981\u4eceDS18\u4e2d\u8bfb\u53d6\u6570\u636e&#xff0c;\u9700\u8981\u81ea\u5df1\u4ea7\u751f\u4e00\u4e2a60\u5fae\u79d2\u7684\u201c\u8bfb\u53d6\u65f6\u9699\u201d&#xff0c;\u4e14\u65f6\u9699\u4e4b\u95f4\u9700\u9884\u7559\u81f3\u5c11 1\u00b5s \u7684\u6062\u590d\u65f6\u95f4\u3002\u4e3b\u8bbe\u5907\u901a\u8fc7\u5c06\u5355\u7ebf\u603b\u7ebf\u62c9\u4f4e\u81f3\u5c11 1\u00b5s \u6765\u89e6\u53d1\u8bfb\u53d6\u65f6\u9699&#xff08;\u5373\u4e0a\u56fe\u7684\u201cL\u201d\u9ed1\u7ebf&#xff09;<\/p>\n<p>DS18B20_PORT&#061;0;<br \/>\n_nop_();_nop_();\/\/_nop_()\u901a\u5e38\u4ea7\u751f1~2\u5fae\u79d2\u5ef6\u65f6&#xff0c;\u4e24\u4e2anop\u6ee1\u8db3\u5927\u4e8e1\u5fae\u79d2\u7684\u6761\u4ef6<br \/>\nDS18B20_PORT&#061;1;<br \/>\n_nop_();_nop_(); <\/p>\n<p>\u968f\u540e\u5355\u7247\u673a\u4eceDS18\u4e2d\u8bfb\u53d6\u4f4d\u6570\u636e&#xff0c;\u82e5\u8bfb\u53d6\u4f4e\u4f4d&#xff0c;\u5c31\u5982\u5de6\u56fe&#xff1b;\u82e5\u8bfb\u53d6\u9ad8\u4f4d&#xff0c;\u5c31\u5982\u53f3\u56fe\u3002\u65e0\u8bba\u8bfb\u53d6\u5230\u4ec0\u4e48\u6570\u636e&#xff0c;\u8bfb\u53d6\u6240\u82b1\u7684\u65f6\u95f4\u5fc5\u987b\u4fdd\u6301\u572815\u5fae\u79d2\u4e4b\u5185<\/p>\n<p>if(DS18B20_PORT)dat&#061;1;<br \/>\nelse dat&#061;0;<\/p>\n<p>\u6700\u540e\u518d\u8865\u4e0a\u4e00\u6bb5\u5ef6\u65f6&#xff08;50\u5fae\u79d2&#xff09;&#xff0c;\u786e\u4fdd\u6574\u4e2a\u8bfb\u53d6\u65f6\u9699\u7684\u65f6\u957f\u3002<\/p>\n<hr \/>\n<h4>\u5b57\u8282\u8bfb\u53d6<\/h4>\n<p>u8 ds18b20_read_byte(void)<br \/>\n{<br \/>\nu8 i&#061;0;<br \/>\nu8 dat&#061;0;<br \/>\nu8 temp&#061;0;<\/p>\n<p>for(i&#061;0;i&lt;8;i&#043;&#043;)\/\/\u5faa\u73af8\u6b21&#xff0c;\u6bcf\u6b21\u8bfb\u53d6\u4e00\u4f4d&#xff0c;\u4e14\u5148\u8bfb\u4f4e\u4f4d\u518d\u8bfb\u9ad8\u4f4d&#xff0c;\u8bfb\u53d6\u516b\u6b21\u4f4d\u5c31\u5f62\u6210\u4e00\u4e2a\u5b57\u8282<br \/>\n{<br \/>\ntemp&#061;ds18b20_read_bit();<br \/>\ndat&#061;(temp&lt;&lt;7)|(dat&gt;&gt;1);\/\/dat\u53f3\u79fb1\u4f4d&#xff0c;\u5e76\u5c06temp\u7684\u7b2c0\u4f4d\u586b\u5165dat\u7684\u6700\u9ad8\u4f4d<br \/>\n}<br \/>\nreturn dat;<br \/>\n}<\/p>\n<p>\u8fd9\u90e8\u5206\u5c31\u4e0eDS18\u5185\u90e8\u7279\u6027\u6ca1\u4ec0\u4e48\u5173\u7cfb\u4e86&#xff0c;\u539f\u7406\u662f\u75288\u6b21\u5faa\u73af\u8bfb\u53d68\u4e2a\u4f4d&#xff0c;\u7136\u540e\u628a\u4e32\u884c\u8f93\u5165\u5e76\u884c\u8f93\u51fa\u62108\u4f4d\u7684dat<\/p>\n<hr \/>\n<h4>\u5b57\u8282\u5199\u5165<\/h4>\n<p>void ds18b20_write_byte(u8 dat)<br \/>\n{<br \/>\nu8 i&#061;0;<br \/>\nu8 temp&#061;0;<\/p>\n<p>for(i&#061;0;i&lt;8;i&#043;&#043;)\/\/\u5faa\u73af8\u6b21&#xff0c;\u6bcf\u6b21\u5199\u4e00\u4f4d&#xff0c;\u4e14\u5148\u5199\u4f4e\u4f4d\u518d\u5199\u9ad8\u4f4d<br \/>\n{<br \/>\ntemp&#061;dat&amp;0x01;\/\/\u9009\u62e9\u4f4e\u4f4d\u51c6\u5907\u5199\u5165&#xff0c;\u8fd9\u90e8\u5206\u5c5e\u4e8e\u91c7\u6837\u7a97\u53e3<br \/>\ndat&gt;&gt;&#061;1;\/\/\u5c06\u6b21\u9ad8\u4f4d\u79fb\u5230\u4f4e\u4f4d<br \/>\nif(temp)<br \/>\n{<br \/>\nDS18B20_PORT&#061;0;<br \/>\n_nop_();_nop_();<br \/>\nDS18B20_PORT&#061;1;<br \/>\ndelay_10us(6);\/\/\u8fdb\u884c\u4e00\u6b21\u8bfb\u53d6\u65f6\u9699<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nDS18B20_PORT&#061;0;<br \/>\ndelay_10us(6);<br \/>\nDS18B20_PORT&#061;1;<br \/>\n_nop_();_nop_();<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>\u8fd9\u90e8\u5206\u539f\u7406\u662f&#xff0c;\u4ece\u6700\u4f4e\u4f4d\u5f00\u59cb\u8bfb\u53d6dat&#xff08;dat\u662f8\u4f4d\u6570\u636e&#xff09;&#xff0c;\u82e5\u8bfb\u53d6\u5230\u9ad8\u4f4d&#xff0c;\u5219\u5411DS18\u4e2d\u5199\u51651&#xff1b;\u82e5\u8bfb\u53d6\u5230\u4f4e\u4f4d&#xff0c;\u5219\u5411DS18\u4e2d\u5199\u51650\u3002\u4e00\u5171\u5faa\u73af8\u6b21&#xff08;\u521a\u597d\u4e00\u4e2a\u5b57\u8282&#xff09;&#xff0c;\u6bcf\u6b21\u8bfb\u53d6\u540e&#xff0c;dat\u5c31\u53f3\u79fb\u4e00\u4f4d&#xff0c;\u539f\u6765\u7684\u6b21\u4f4e\u4f4d\u5c31\u53d8\u6210\u4f4e\u4f4d\u7ee7\u7eed\u88ab\u8bfb\u53d6\u3002<\/p>\n<hr \/>\n<h4>\u5f00\u542f\u6e29\u8f6c<\/h4>\n<p>void ds18b20_start(void)<br \/>\n{<br \/>\nds18b20_reset();\/\/\u590d\u4f4d<br \/>\nds18b20_check();\/\/\u68c0\u67e5DS18B20<br \/>\nds18b20_write_byte(0xcc);\/\/\u540c\u65f6\u63a7\u5236\u603b\u7ebf\u6240\u6709\u8bbe\u5907<br \/>\n    ds18b20_write_byte(0x44);\/\/\u8f6c\u6362\u547d\u4ee4<br \/>\n}<\/p>\n<p>\u6587\u7ae0\u5f00\u5934\u63d0\u8fc7&#xff0c;DS18\u662f\u6570\u5b57\u6e29\u5ea6\u8ba1&#xff0c;\u56e0\u4e3a\u5b83\u80fd\u81ea\u5df1\u8fdb\u884c\u6a21\u6570\u8f6c\u6362&#xff0c;\u4e0a\u9762\u4ee3\u7801\u5c31\u662f\u542f\u52a8\u6a21\u6570\u8f6c\u6362<\/p>\n<p>\u9996\u5148\u521d\u59cb\u5316&#xff08;\u590d\u4f4d\u548c\u68c0\u6d4b&#xff09;&#xff1b;\u7136\u540e\u8df3\u8fc7Read ROM\u6307\u4ee4&#xff0c;\u4e5f\u5c31\u662f\u4e0d\u770b\u8eab\u4efd\u8bc1&#xff0c;\u76f4\u63a5\u63a7\u5236DS18&#xff1b;\u6700\u540e\u5411DS18\u8f93\u5165AD\u8f6c\u6362\u547d\u4ee4&#xff0c;\u8fd9\u6837DS18\u5185\u90e8\u5c31\u4f1a\u81ea\u52a8\u628a\u91c7\u96c6\u7684\u6a21\u62df\u91cf\u6e29\u5ea6\u8f6c\u6362\u6210\u6570\u5b57\u91cf\u3002<\/p>\n<hr \/>\n<h4>\u521d\u59cb\u5316<\/h4>\n<p>u8 ds18b20_init(void)<br \/>\n{<br \/>\nds18b20_reset();<br \/>\nreturn ds18b20_check();<br \/>\n}<\/p>\n<p>\u4e3a\u4ec0\u4e48DS18\u4e5f\u9700\u8981\u521d\u59cb\u5316&#xff1f;\u56e0\u4e3a\u8fd9\u662f1-Wire\u534f\u8bae\u7684\u6807\u51c6\u6d41\u7a0b<\/p>\n<p><span style=\"color:#956fe7\">\u6bcf\u6b21\u65b0\u7684\u901a\u4fe1\u4f1a\u8bdd\u90fd\u5fc5\u987b\u4ee5\u590d\u4f4d\u548c\u5b58\u5728\u68c0\u6d4b\u5f00\u59cb<\/span><\/p>\n<hr \/>\n<h4>\u6e29\u5ea6\u8bfb\u53d6<\/h4>\n<p>float ds18b20_read_temperture(void)<br \/>\n{<br \/>\nfloat temp;<br \/>\nu8 dath&#061;0;<br \/>\nu8 datl&#061;0;<br \/>\nu16 value&#061;0;<\/p>\n<p>ds18b20_start();<br \/>\nds18b20_reset();<br \/>\nds18b20_check();<br \/>\nds18b20_write_byte(0xcc);<br \/>\n    ds18b20_write_byte(0xbe);<\/p>\n<p>datl&#061;ds18b20_read_byte();<br \/>\ndath&#061;ds18b20_read_byte();<br \/>\nvalue&#061;(dath&lt;&lt;8)&#043;datl;<br \/>\nif((value&amp;0xf800)&#061;&#061;0xf800)<br \/>\n{<br \/>\nvalue&#061;(~value)&#043;1;<br \/>\ntemp&#061;value*(-0.0625);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\ntemp&#061;value*0.0625;<br \/>\n}<br \/>\nreturn temp;<br \/>\n}<\/p>\n<p>\u8fd9\u90e8\u5206\u5c31\u662f\u4eceDS18\u83b7\u53d6\u6570\u5b57\u6e29\u5ea6\u503c\u7684\u51fd\u6570&#xff0c;\u6211\u4eec\u6765\u770b\u770b\u5b83\u662f\u5982\u4f55\u8fd0\u4f5c\u7684<\/p>\n<p>\u9996\u5148\u5b9a\u4e49\u6e29\u5ea6\u503c\u4e3a\u6d6e\u70b9\u6570&#xff08;\u56e0\u4e3a\u6e29\u5ea6\u6709\u96f6\u6709\u6574&#xff0c;\u6709\u6b63\u6709\u8d1f&#xff09;&#xff1b;<\/p>\n<p>\u7136\u540e\u4f9d\u6b21\u5f00\u542fAD\u8f6c\u6362\u3001\u521d\u59cb\u5316\u3001\u8df3\u8fc7ROM&#xff08;\u4e0d\u770b\u8eab\u4efd\u8bc1&#xff09;\u3002\u5b8c\u6210\u51c6\u5907\u5de5\u4f5c\u540e&#xff0c;\u53ef\u4ee5\u8fdb\u884c\u8bfb\u53d6\u4e86<\/p>\n<p>   ds18b20_write_byte(0xbe);<\/p>\n<p>\u4ee5\u4e0a\u547d\u4ee4\u662fRead Scratchpad[0xbe]&#xff0c;\u901a\u8fc7DQ\u4ece\u6682\u5b58\u5668\u5b57\u82820\u7684\u6700\u4f4e\u6709\u6548\u4f4d\u5f00\u59cb&#xff0c;\u76f4\u5230\u5b57\u82829&#xff08;\u5373CRC\u5b57\u8282&#xff09;<\/p>\n<table align=\"center\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:592px\">\n<tr>\u5b57\u8282\u5730\u5740\u540d\u79f0\u529f\u80fd\u662f\u5426\u53ef\u6620\u5c04\u5230EEPROM<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 0<\/td>\n<td style=\"text-align:center;width:91px\">\u6e29\u5ea6LSB<\/td>\n<td style=\"text-align:center;width:214px\">\u6e29\u5ea6\u503c\u4f4e\u56db\u4f4d(\u5305\u542b\u5c0f\u6570\u90e8\u5206)<\/td>\n<td style=\"text-align:center;width:217px\">\u5426&#xff08;\u8fd0\u884c\u65f6\u6570\u636e&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 1<\/td>\n<td style=\"text-align:center;width:91px\">\u6e29\u5ea6MSB<\/td>\n<td style=\"text-align:center;width:214px\">\u6e29\u5ea6\u503c\u9ad8 8 \u4f4d&#xff08;\u5305\u542b\u7b26\u53f7\u4f4d&#xff09;<\/td>\n<td style=\"text-align:center;width:217px\">\u5426&#xff08;\u8fd0\u884c\u65f6\u6570\u636e&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 2<\/td>\n<td style=\"text-align:center;width:91px\">TH\u5bc4\u5b58\u5668<\/td>\n<td style=\"text-align:center;width:214px\">\u9ad8\u6e29\u62a5\u8b66\u9608\u503c<\/td>\n<td style=\"text-align:center;width:217px\">\u662f&#xff08;\u5b57\u8282 2 \u7684 EEPROM \u5907\u4efd&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 3<\/td>\n<td style=\"text-align:center;width:91px\">TL\u5bc4\u5b58\u5668<\/td>\n<td style=\"text-align:center;width:214px\">\u4f4e\u6e29\u62a5\u8b66\u9608\u503c<\/td>\n<td style=\"text-align:center;width:217px\">\u662f&#xff08;\u5b57\u8282 3 \u7684 EEPROM \u5907\u4efd&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 4<\/td>\n<td style=\"text-align:center;width:91px\">\u914d\u7f6e\u5bc4\u5b58\u5668<\/td>\n<td style=\"text-align:center;width:214px\">\u5206\u8fa8\u7387\u8bbe\u7f6e<\/td>\n<td style=\"text-align:center;width:217px\">\u662f&#xff08;\u5b57\u8282 4 \u7684 EEPROM \u5907\u4efd&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 5<\/td>\n<td style=\"text-align:center;width:91px\">\u4fdd\u7559<\/td>\n<td style=\"text-align:center;width:214px\"><\/td>\n<td style=\"text-align:center;width:217px\">\u5426<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 6<\/td>\n<td style=\"text-align:center;width:91px\">\u4fdd\u7559<\/td>\n<td style=\"text-align:center;width:214px\"><\/td>\n<td style=\"text-align:center;width:217px\">\u5426<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 7<\/td>\n<td style=\"text-align:center;width:91px\">\u4fdd\u7559<\/td>\n<td style=\"text-align:center;width:214px\"><\/td>\n<td style=\"text-align:center;width:217px\">\u5426<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Byte 8<\/td>\n<td style=\"text-align:center;width:91px\">CRC\u5b57\u8282<\/td>\n<td style=\"text-align:center;width:214px\">\u5bf9Byte0~7\u7684\u5faa\u73af\u5197\u4f59\u6821\u9a8c\u7801<\/td>\n<td style=\"text-align:center;width:217px\">\u5426<\/td>\n<\/tr>\n<\/table>\n<p>\u4ece\u4e0a\u8868\u4e5f\u53ef\u4ee5\u770b\u51fa&#xff0c;\u6e29\u5ea6\u6570\u636e\u662f\u5148\u4f20\u4f4e\u4f4d\u518d\u4f20\u9ad8\u4f4d\u7684&#xff0c;\u6240\u4ee5\u53ef\u4ee5\u501f\u52a9\u65f6\u5e8f\u7279\u70b9\u628a\u9ad8\u4f4d\u548c\u4f4e\u4f4d\u5206\u522b\u5b58\u50a8\u8d77\u6765&#xff1a;<\/p>\n<p>    datl&#061;ds18b20_read_byte();<br \/>\ndath&#061;ds18b20_read_byte();<\/p>\n<p>\u7136\u540e\u5c31\u662f\u7d22\u7136\u65e0\u5473\u7684\u79fb\u4f4d\u3001\u5408\u5e76\u6d41\u7a0b\u3002\u6700\u540e\u901a\u8fc7(value&amp;0xf800)&#061;&#061;0xf800\u786e\u5b9a\u6e29\u5ea6\u503c\u662f\u6b63\u503c\u8fd8\u662f\u8d1f\u503c&#xff0c;\u628a\u8f6c\u7801\u5f97\u5230\u7684\u6e29\u5ea6\u503c&#xff08;DS18\u7684\u6e29\u5ea6\u503c\u662f\u4ee516\u4f4d\u4e8c\u8fdb\u5236\u8865\u7801\u5f62\u5f0f\u5b58\u50a8&#xff0c;\u6240\u4ee5\u9700\u8981\u8f6c\u7801&#xff09;\u4e58\u4ee5\u7cbe\u5ea6&#xff08;0.0625&#xff09;\u5f97\u5230\u5bf9\u5e94\u5206\u8fa8\u7387\u4e0b\u7684\u6e29\u5ea6\u503c\u3002<\/p>\n<hr \/>\n<p>\u81f3\u6b64&#xff0c;\u6211\u4eec\u5df2\u7ecf\u5206\u6790\u5b8c\u62108\u4e2aDS18B20\u51fd\u6570\u7684\u529f\u80fd&#xff0c;\u8fd9\u90e8\u5206\u5b9e\u9645\u4e0a\u5df2\u7ecf\u7b97\u662f\u6a21\u5757\u5316\u4e86&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u6e29\u5ea6\u68c0\u6d4b\u90e8\u5206&#xff0c;\u5269\u4e0b\u7684\u663e\u793a&#xff0c;\u65e0\u8bba\u662f\u6570\u7801\u7ba1\u3001LCD1602&#xff0c;\u53c8\u6216\u8005\u662fLCD12864&#xff0c;\u90fd\u53ef\u4ee5\u5b8c\u6210&#xff0c;\u4f46\u8003\u8651\u5230\u6570\u7801\u7ba1\u539f\u7406\u6bd4\u8f83\u7b80\u5355&#xff0c;\u6240\u4ee5\u8fd9\u91cc\u6211\u4eec\u9009\u62e9\u6570\u7801\u7ba1\u663e\u793a\u6e29\u5ea6\u3002<\/p>\n<h2>\u4e8c\u3001\u6570\u7801\u7ba1\u90e8\u5206<\/h2>\n<p>\/\/\u5171\u9634\u6781\u6570\u7801\u7ba1\u663e\u793a0~F\u7684\u6bb5\u7801\u6570\u636e<br \/>\nu8 gsmg_code[17]&#061;{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};<\/p>\n<p>void smg_display(u8 dat[],u8 pos)<br \/>\n{<br \/>\nu8 i&#061;0;<br \/>\nu8 pos_temp&#061;pos-1;<\/p>\n<p>for(i&#061;pos_temp;i&lt;8;i&#043;&#043;)<br \/>\n{<br \/>\n   switch(i)\/\/\u4f4d\u9009<br \/>\n{<br \/>\ncase 0: LSC&#061;1;LSB&#061;1;LSA&#061;1;break;<br \/>\ncase 1: LSC&#061;1;LSB&#061;1;LSA&#061;0;break;<br \/>\ncase 2: LSC&#061;1;LSB&#061;0;LSA&#061;1;break;<br \/>\ncase 3: LSC&#061;1;LSB&#061;0;LSA&#061;0;break;<br \/>\ncase 4: LSC&#061;0;LSB&#061;1;LSA&#061;1;break;<br \/>\ncase 5: LSC&#061;0;LSB&#061;1;LSA&#061;0;break;<br \/>\ncase 6: LSC&#061;0;LSB&#061;0;LSA&#061;1;break;<br \/>\ncase 7: LSC&#061;0;LSB&#061;0;LSA&#061;0;break;<br \/>\n}<br \/>\nSMG_A_DP_PORT&#061;dat[i-pos_temp];\/\/\u4f20\u9001\u6bb5\u9009\u6570\u636e<br \/>\ndelay_10us(100);\/\/\u5ef6\u65f6\u4e00\u6bb5\u65f6\u95f4&#xff0c;\u7b49\u5f85\u663e\u793a\u7a33\u5b9a<br \/>\nSMG_A_DP_PORT&#061;0x00;\/\/\u6d88\u97f3<br \/>\n}<br \/>\n}<\/p>\n<p>\u5f00\u5934\u7684gsmg_code\u6570\u7ec4\u5b9e\u9645\u4e0a\u5b58\u50a8\u4e86\u5171\u9634\u6781\u6570\u7801\u7ba10~F\u5f62\u72b6\u7684\u6bb5\u9009\u6570\u636e\u3002\u7136\u540e\u8f93\u5165\u8d77\u59cb\u4f4d\u7f6e&#xff08;pos&#xff09;&#xff0c;8\u4f4d\u6570\u7801\u7ba1\u5c31\u4f1a\u4ece\u8fd9\u4e00\u4f4d\u5f00\u59cb&#xff0c;\u4f9d\u6b21\u5411\u53f3\u79fb\u52a8&#xff0c;\u79fb\u52a8\u7684\u540c\u65f6\u4f1a\u586b\u5165\u76f8\u5e94\u7684\u6bb5\u9009\u6570\u636e<\/p>\n<h2>\u4e09\u3001\u4e3b\u51fd\u6570\u90e8\u5206<\/h2>\n<p>#include &#034;public.h&#034;<br \/>\n#include &#034;smg.h&#034;<br \/>\n#include &#034;ds18b20.h&#034;<\/p>\n<p>void main()<br \/>\n{<br \/>\nu8 i&#061;0;<br \/>\n   int temp_value;<br \/>\nu8 temp_buf[5];<\/p>\n<p>ds18b20_init();\/\/\u521d\u59cb\u5316DS18B20<\/p>\n<p>while(1)<br \/>\n{<br \/>\ni&#043;&#043;;<br \/>\nif(i%50&#061;&#061;0)\/\/\u95f4\u9694\u4e00\u6bb5\u65f6\u95f4\u8bfb\u53d6\u6e29\u5ea6\u503c&#xff0c;\u95f4\u9694\u65f6\u95f4\u8981\u5927\u4e8e\u6e29\u5ea6\u4f20\u611f\u5668\u8f6c\u6362\u6e29\u5ea6\u65f6\u95f4<br \/>\ntemp_value&#061;ds18b20_read_temperture()*10;\/\/\u4fdd\u7559\u6e29\u5ea6\u503c\u5c0f\u6570\u540e\u4e00\u4f4d<br \/>\nif(temp_value&lt;0)\/\/\u8d1f\u6e29\u5ea6<br \/>\n{<br \/>\ntemp_value&#061;-temp_value;<br \/>\ntemp_buf[0]&#061;0x40;\/\/\u663e\u793a\u8d1f\u53f7<br \/>\n}<br \/>\nelse temp_buf[0]&#061;0x00;\/\/\u4e0d\u663e\u793a<\/p>\n<p>temp_buf[1]&#061;gsmg_code[temp_value\/1000];\/\/\u767e\u4f4d<br \/>\ntemp_buf[2]&#061;gsmg_code[temp_value%1000\/100];\/\/\u5341\u4f4d<br \/>\ntemp_buf[3]&#061;gsmg_code[temp_value%1000%100\/10]|0x80;\/\/\u4e2a\u4f4d&#043;\u5c0f\u6570\u70b9<br \/>\ntemp_buf[4]&#061;gsmg_code[temp_value%1000%100%10];\/\/\u5c0f\u6570\u70b9\u540e\u4e00\u4f4d<br \/>\nsmg_display(temp_buf,4);<br \/>\n}<br \/>\n}<\/p>\n<p>\u76f8\u8f83\u4e8eDS18&#xff0c;\u4e3b\u51fd\u6570\u90e8\u5206\u5c31\u5f88\u597d\u89e3\u91ca\u4e86&#xff0c;\u53ef\u4ee5\u6309\u4f5c\u7528\u5206\u6210\u51e0\u4e2a\u90e8\u5206&#xff1a;\u663e\u793a\u4f4d\u6570\u5b9a\u4e49\u3001\u8bfb\u53d6\u6e29\u5ea6\u503c\u3001\u8fdb\u4f4d\u663e\u793a<\/p>\n<h4>\u663e\u793a\u4f4d\u6570\u5b9a\u4e49<\/h4>\n<p>u8 temp_buf[5];<\/p>\n<p>\u5b9a\u4e49\u4e00\u4e2a5\u4f4d\u6570\u7ec4&#xff0c;\u5305\u62ec\u7b26\u53f7\u4f4d\u3001\u767e\u4f4d\u3001\u5341\u4f4d\u3001\u4e2a\u4f4d&#xff08;\u5c0f\u6570\u70b9\u4e0e\u4e2a\u4f4d\u5171\u7528\u4e00\u4f4d&#xff09;\u3001\u5c0f\u6570\u70b9\u540e\u4e00\u4f4d\u3002<\/p>\n<h4>\u8bfb\u53d6\u6e29\u5ea6\u503c<\/h4>\n<p>if(i%50&#061;&#061;0)\/\/\u95f4\u9694\u4e00\u6bb5\u65f6\u95f4\u8bfb\u53d6\u6e29\u5ea6\u503c&#xff0c;\u95f4\u9694\u65f6\u95f4\u8981\u5927\u4e8e\u6e29\u5ea6\u4f20\u611f\u5668\u8f6c\u6362\u6e29\u5ea6\u65f6\u95f4<br \/>\ntemp_value&#061;ds18b20_read_temperture()*10;\/\/\u4fdd\u7559\u6e29\u5ea6\u503c\u5c0f\u6570\u540e\u4e00\u4f4d<br \/>\nif(temp_value&lt;0)\/\/\u8d1f\u6e29\u5ea6<br \/>\n{<br \/>\ntemp_value&#061;-temp_value;<br \/>\ntemp_buf[0]&#061;0x40;\/\/\u663e\u793a\u8d1f\u53f7<br \/>\n}<br \/>\nelse temp_buf[0]&#061;0x00;\/\/\u4e0d\u663e\u793a<\/p>\n<p>\u8bfb\u53d6\u6e29\u5ea6\u95f4\u9699\u4e0d\u80fd\u8fc7\u77ed&#xff0c;\u6240\u4ee5\u8bbe\u7f6ei\u4f5c\u4e3a\u8ba1\u65f6\u5668\u3001\u6bcf50\u6b21\u5faa\u73af\u8bfb\u53d6\u4e00\u6b21\u6e29\u5ea6&#xff1b;\u7136\u540e\u68c0\u6d4b\u6e29\u5ea6\u6b63\u8d1f\u503c&#xff1a;\u82e5\u4e3a\u6b63&#xff0c;\u76f4\u63a5\u663e\u793a&#xff1b;\u82e5\u4e3a\u8d1f&#xff0c;\u7ffb\u8f6c\u540e\u52a0\u4e2a\u8d1f\u53f7\u518d\u663e\u793a\u3002<\/p>\n<h4>\u8fdb\u4f4d\u663e\u793a<\/h4>\n<p>temp_buf[1]&#061;gsmg_code[temp_value\/1000];\/\/\u767e\u4f4d<br \/>\ntemp_buf[2]&#061;gsmg_code[temp_value%1000\/100];\/\/\u5341\u4f4d<br \/>\ntemp_buf[3]&#061;gsmg_code[temp_value%1000%100\/10]|0x80;\/\/\u4e2a\u4f4d&#043;\u5c0f\u6570\u70b9<br \/>\ntemp_buf[4]&#061;gsmg_code[temp_value%1000%100%10];\/\/\u5c0f\u6570\u70b9\u540e\u4e00\u4f4d<br \/>\nsmg_display(temp_buf,4);<\/p>\n<p>\u56e0\u4e3a\u524d\u9762\u5728\u8bfb\u53d6\u6e29\u5ea6\u65f6\u4e58\u4e8610&#xff0c;\u76f8\u5f53\u4e8e\u53ea\u4fdd\u7559\u4e00\u4f4d\u5c0f\u6570&#xff0c;\u6240\u4ee5\u8fd9\u91cc\u7684\u767e\u4f4d\u5c31\u4ece\u539f\u6765\u7684value\/100\u53d8\u6210value\/1000&#xff0c;\u540e\u9762\u540c\u7406\u3002\u5728\u5c06\u6e29\u5ea6\u503c\u56db\u4f4d\u6570\u636e\u90fd\u5199\u8fdb\u6570\u7ec4tem_buf[]\u540e&#xff0c;\u6570\u7801\u7ba1\u663e\u793a\u51fd\u6570\u4ece8\u4f4d\u6570\u7801\u7ba1\u7684\u7b2c\u56db\u4f4d\u5f00\u59cb\u4f9d\u6b21\u663e\u793a\u3002<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"207\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210549-697fc02d114e6.jpg\" width=\"511\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3b\u51fd\u6570#include \\&#8221;public.h\\&#8221;void main()<br \/>\n{<br \/>\nu8 i0;int temp_value;<br \/>\nu8 temp_buf[5];ds18b20_init();\/\/\u521d\u59cb\u5316DS18B20while(1)<br \/>\n{<br \/>\ni;<br \/>\nif(i%500)\/\/\u95f4\u9694\u4e00\u6bb5\u65f6\u95f4\u8bfb\u53d6\u6e29\u5ea6\u503c&#xff0c;\u95f4\u9694\u65f6\u95f4\u8981\u5927\u4e8e\u6e29\u5ea6\u4f20\u611f\u5668\u8f6c\u6362\u6e29\u5ea6\u65f6\u95f4<br \/>\ntemp_valueds18b20_read_temperture()*10;\/\/\u4fdd\u7559\u6e29\u5ea6\u503c\u5c0f\u6570\u540e\u4e00\u4f4d<br \/>\nif(temp_value&lt;0)\/\/\u8d1f\u6e29\u5ea6<br \/>\n{<br \/>\nt<\/p>\n","protected":false},"author":2,"featured_media":70601,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[270,123,269,1100,427],"topic":[],"class_list":["post-70609","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-270","tag-123","tag-269","tag-1100","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5206\u6790\u4e00\u6bb5DS18B20\u6e29\u5ea6\u663e\u793a\u4ee3\u7801 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/70609.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5206\u6790\u4e00\u6bb5DS18B20\u6e29\u5ea6\u663e\u793a\u4ee3\u7801 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e3b\u51fd\u6570#include &quot;public.h&quot;void main() { u8 i0;int temp_value; u8 temp_buf[5];ds18b20_init();\/\/\u521d\u59cb\u5316DS18B20while(1) { i; if(i%500)\/\/\u95f4\u9694\u4e00\u6bb5\u65f6\u95f4\u8bfb\u53d6\u6e29\u5ea6\u503c&#xff0c;\u95f4\u9694\u65f6\u95f4\u8981\u5927\u4e8e\u6e29\u5ea6\u4f20\u611f\u5668\u8f6c\u6362\u6e29\u5ea6\u65f6\u95f4 temp_valueds18b20_read_temperture()*10;\/\/\u4fdd\u7559\u6e29\u5ea6\u503c\u5c0f\u6570\u540e\u4e00\u4f4d if(temp_value&lt;0)\/\/\u8d1f\u6e29\u5ea6 { t\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/70609.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-01T21:05:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210546-697fc02a157d5.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/70609.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/70609.html\",\"name\":\"\u5206\u6790\u4e00\u6bb5DS18B20\u6e29\u5ea6\u663e\u793a\u4ee3\u7801 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-01T21:05:50+00:00\",\"dateModified\":\"2026-02-01T21:05:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/70609.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/70609.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/70609.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5206\u6790\u4e00\u6bb5DS18B20\u6e29\u5ea6\u663e\u793a\u4ee3\u7801\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5206\u6790\u4e00\u6bb5DS18B20\u6e29\u5ea6\u663e\u793a\u4ee3\u7801 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/70609.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5206\u6790\u4e00\u6bb5DS18B20\u6e29\u5ea6\u663e\u793a\u4ee3\u7801 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e3b\u51fd\u6570#include \"public.h\"void main() { u8 i0;int temp_value; u8 temp_buf[5];ds18b20_init();\/\/\u521d\u59cb\u5316DS18B20while(1) { i; if(i%500)\/\/\u95f4\u9694\u4e00\u6bb5\u65f6\u95f4\u8bfb\u53d6\u6e29\u5ea6\u503c&#xff0c;\u95f4\u9694\u65f6\u95f4\u8981\u5927\u4e8e\u6e29\u5ea6\u4f20\u611f\u5668\u8f6c\u6362\u6e29\u5ea6\u65f6\u95f4 temp_valueds18b20_read_temperture()*10;\/\/\u4fdd\u7559\u6e29\u5ea6\u503c\u5c0f\u6570\u540e\u4e00\u4f4d if(temp_value&lt;0)\/\/\u8d1f\u6e29\u5ea6 { t","og_url":"https:\/\/www.wsisp.com\/helps\/70609.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-01T21:05:50+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201210546-697fc02a157d5.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/70609.html","url":"https:\/\/www.wsisp.com\/helps\/70609.html","name":"\u5206\u6790\u4e00\u6bb5DS18B20\u6e29\u5ea6\u663e\u793a\u4ee3\u7801 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-01T21:05:50+00:00","dateModified":"2026-02-01T21:05:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/70609.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/70609.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/70609.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5206\u6790\u4e00\u6bb5DS18B20\u6e29\u5ea6\u663e\u793a\u4ee3\u7801"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/70609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=70609"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/70609\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/70601"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=70609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=70609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=70609"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=70609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}