{"id":1484,"date":"2024-11-22T21:46:04","date_gmt":"2024-11-22T13:46:04","guid":{"rendered":"https:\/\/aoofoo.com\/?p=1484"},"modified":"2024-11-22T21:46:04","modified_gmt":"2024-11-22T13:46:04","slug":"%e4%bc%a0%e6%84%9f%e5%99%a8ds18b20%e6%b8%a9%e5%ba%a6%e4%bc%a0%e6%84%9f%e5%99%a8%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/aoofoo.com\/index.php\/2024\/11\/22\/%e4%bc%a0%e6%84%9f%e5%99%a8ds18b20%e6%b8%a9%e5%ba%a6%e4%bc%a0%e6%84%9f%e5%99%a8%e5%8e%9f%e7%90%86\/","title":{"rendered":"[\u4f20\u611f\u5668]DS18B20\u6e29\u5ea6\u4f20\u611f\u5668\u539f\u7406"},"content":{"rendered":"<h2>DS18B20\u4f20\u611f\u5668<\/h2>\n<p>DS18B20\u662f\u4e00\u4e2a\u4f7f\u7528\u5355\u603b\u7ebf\u534f\u8bae\u7684\u6e29\u5ea6\u4f20\u611f\u5668\uff0c\u4f9b\u7535\u7535\u538b\u662f3~5V\u4e4b\u95f4\uff0c\u6211\u4eec\u4f7f\u7528\u7684\u662fSTM32\uff0c\u6240\u4ee5\u4f7f\u75283.3V\u8fdb\u884c\u4f9b\u7535\u3002<\/p>\n<p>DS18B20 \u662f\u4e00\u6b3e\u6570\u5b57\u5f0f\u6e29\u5ea6\u4f20\u611f\u5668\uff0c\u8f93\u51fa\u4e3a\u6570\u5b57\u4fe1\u53f7\uff0c\u65e0\u9700\u5916\u63a5 A\/D \u8f6c\u6362\u5668\u3002<\/p>\n<p>\u6bcf\u4e2aDS18B20\u90fd\u6709\u72ec\u7acb\u552f\u4e00\u768464\u4f4d-ID\uff0c\u6b64\u7279\u6027\u51b3\u5b9a\u4e86\u5b83\u53ef\u4ee5\u5c06\u4efb\u610f\u591a\u7684DS18b20\u6302\u8f7d\u5230\u4e00\u6839\u603b\u7ebf\u4e0a\uff0c\u901a\u8fc7ROM\u641c\u7d22\u8bfb\u53d6\u76f8\u5e94DS18B20\u7684\u6e29\u5ea6\u503c\u3002<\/p>\n<h3>\u539f\u7406\u56fe<\/h3>\n<p>\u6570\u5b57\u4fe1\u53f7\u8f93\u5165\u8f93\u51fa\u7aef\uff08DQ\uff09\u9700\u8981\u4e00\u4e2a\u4e0a\u62c9\u7535\u963b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-1485\" src=\"https:\/\/aoofoo.com\/wp-content\/uploads\/2024\/11\/\u5c4f\u5e55\u622a\u56fe-2024-11-22-160235.png\" alt=\"\" width=\"731\" height=\"337\" \/><\/p>\n<p>\u4e3a\u4ec0\u4e48\u4f7f\u7528\u4e0a\u62c9\u7535\u963b\uff1f<\/p>\n<p>\u4e0a\u62c9\u7535\u963b \u5728\u5355\u603b\u7ebf\u901a\u4fe1\u4e2d\u8d77\u7740\u5173\u952e\u4f5c\u7528\uff0c\u5b83\u786e\u4fdd\u603b\u7ebf\u5728\u7a7a\u95f2\u65f6\u4fdd\u6301\u9ad8\u7535\u5e73\uff0c\u5e76\u5141\u8bb8\u591a\u4e2a\u8bbe\u5907\u5171\u4eab\u540c\u4e00\u6761\u603b\u7ebf\u3002<\/p>\n<h3>\u9ad8\u901f\u7f13\u5b58\u5668<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-1486\" src=\"https:\/\/aoofoo.com\/wp-content\/uploads\/2024\/11\/\u5c4f\u5e55\u622a\u56fe-2024-11-22-162738.png\" alt=\"\" width=\"615\" height=\"258\" \/><\/p>\n<p>DS18B20\u9ad8\u901f\u6682\u5b58\u5668\u75319\u4e2a\u5b57\u8282\u7ec4\u6210\uff1a<\/p>\n<p>\u5b57\u82820~1 \u662f\u6e29\u5ea6\u5b58\u50a8\u5668\uff0c\u7528\u6765\u5b58\u50a8\u8f6c\u6362\u597d\u7684\u6e29\u5ea6\u3002\u7b2c0\u4e2a\u5b57\u8282\u5b58\u50a8\u6e29\u5ea6\u4f4e8\u4f4d\uff0c\u7b2c\u4e00\u4e2a\u5b57\u8282\u5b58\u50a8\u6e29\u5ea6\u9ad88\u4f4d<br \/>\n\u5b57\u82822~3 \u662f\u7528\u6237\u7528\u6765\u8bbe\u7f6e\u6700\u9ad8\u62a5\u8b66\u548c\u6700\u4f4e\u62a5\u8b66\u503c(TH\u548cTL)\u3002<br \/>\n\u5b57\u82824 \u662f\u914d\u7f6e\u5bc4\u5b58\u5668\uff0c\u7528\u6765\u914d\u7f6e\u8f6c\u6362\u7cbe\u5ea6\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3a9~12 \u4f4d\u3002<br \/>\n\u5b57\u82825~7 \u4fdd\u7559\u4f4d\u3002\u82af\u7247\u5185\u90e8\u4f7f\u7528<br \/>\n\u5b57\u82828 CRC\u6821\u9a8c\u4f4d\u3002\u662f64\u4f4dROM\u4e2d\u7684\u524d56\u4f4d\u7f16\u7801\u7684\u6821\u9a8c\u7801\u3002\u7531CRC\u53d1\u751f\u5668\u4ea7\u751f\u3002<\/p>\n<p>DS18B20\u91c7\u7528<strong>16\u4f4d\u8865\u7801\u7684\u5f62\u5f0f\u6765\u5b58\u50a8\u6e29\u5ea6\u6570\u636e<\/strong>\uff0c<strong>\u6e29\u5ea6\u662f\u6444\u6c0f\u5ea6<\/strong>\u3002\u5f53\u6e29\u5ea6\u8f6c\u6362\u547d\u4ee4\u53d1\u5e03\u540e\uff0c\u7ecf\u8f6c\u6362\u6240\u5f97\u7684\u6e29\u5ea6\u503c\u4ee5\u4e8c\u5b57\u8282\u8865\u7801\u5f62\u5f0f\u5b58\u653e\u5728\u9ad8\u901f\u6682\u5b58\u5b58\u50a8\u5668\u7684\u7b2c0\u548c\u7b2c1\u4e2a\u5b57\u8282\u3002<\/p>\n<p>DS18B20\u91c7\u752816\u4f4d\u8865\u7801\u7684\u5f62\u5f0f\u6765\u5b58\u50a8\u6e29\u5ea6\u6570\u636e\uff0c\u6e29\u5ea6\u662f\u6444\u6c0f\u5ea6\u3002\u5f53\u6e29\u5ea6\u8f6c\u6362\u547d\u4ee4\u53d1\u5e03\u540e\uff0c\u7ecf\u8f6c\u6362\u6240\u5f97\u7684\u6e29\u5ea6\u503c\u4ee5\u4e8c\u5b57\u8282\u8865\u7801\u5f62\u5f0f\u5b58\u653e\u5728\u9ad8\u901f\u6682\u5b58\u5b58\u50a8\u5668\u7684\u7b2c0\u548c\u7b2c1\u4e2a\u5b57\u8282\u3002<\/p>\n<p>\u9ad8\u5b57\u8282\u7684\u4e94\u4e2aS\u4e3a\u7b26\u53f7\u4f4d\uff0c\u6e29\u5ea6\u4e3a\u6b63\u503c\u65f6S=1,\u6e29\u5ea6\u4e3a\u8d1f\u503c\u65f6S=0\u3002<\/p>\n<p>\u5269\u4e0b\u768411\u4f4d\u4e3a\u6e29\u5ea6\u6570\u636e\u4f4d\uff0c\u5bf9\u4e8e12\u4f4d\u5206\u8fa8\u7387\uff0c\u6240\u6709\u4f4d\u5168\u90e8\u6709\u6548\uff0c\u5bf9\u4e8e11\u4f4d\u5206\u8fa8\u7387\uff0c\u4f4d0(bit0)\u65e0\u5b9a\u4e49\uff0c\u5bf9\u4e8e10\u4f4d\u5206\u8fa8\u7387\uff0c\u4f4d0\u548c\u4f4d1\u65e0\u5b9a\u4e49,\u5bf9\u4e8e9\u4f4d\u5206\u8fa8\u7387\uff0c\u4f4d0\uff0c\u4f4d1\uff0c\u548c\u4f4d2\u65e0\u5b9a\u4e49\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1487\" src=\"https:\/\/aoofoo.com\/wp-content\/uploads\/2024\/11\/\u5c4f\u5e55\u622a\u56fe-2024-11-22-172239.png\" alt=\"\" width=\"1082\" height=\"224\" \/><\/p>\n<h3>\u914d\u7f6e\u5bc4\u5b58\u5668<\/h3>\n<p>\u5728\u914d\u7f6e\u5bc4\u5b58\u5668\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7R0\u548cR1\u8bbe\u7f6eDS18B20\u7684\u8f6c\u6362\u5206\u8fa8\u7387\uff0cDS18B20\u5728\u4e0a\u7535\u540e\u9ed8\u8ba4R0=1\u548cR1=1(12\u5206\u8fa8\u7387)\uff0c\u5bc4\u5b58\u5668\u4e2d\u7684\u7b2c7\u4f4d\u548c\u7b2c0\u4f4d\u52304\u4f4d\u4fdd\u7559\u7ed9\u8bbe\u5907\u5185\u90e8\u4f7f\u7528\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1488\" src=\"https:\/\/aoofoo.com\/wp-content\/uploads\/2024\/11\/\u5c4f\u5e55\u622a\u56fe-2024-11-22-172450.png\" alt=\"\" width=\"1093\" height=\"612\" \/><\/p>\n<h2>\u5de5\u4f5c\u4ee3\u7801\u90e8\u5206<\/h2>\n<p>DS18B20\u7684\u5de5\u4f5c\u6b65\u9aa4\u53ef\u4ee5\u5206\u4e3a\u4e09\u6b65\uff1a<\/p>\n<p>1.\u521d\u59cb\u5316DS18B20<br \/>\n2.\u6267\u884cROM\u6307\u4ee4<br \/>\n3.\u6267\u884cDS18B20\u529f\u80fd\u6307\u4ee4<\/p>\n<p>\u5176\u4e2d\u7b2c\u4e8c\u6b65\u6267\u884cROM\u6307\u4ee4\uff0c\u4e5f\u5c31\u662f\u8bbf\u95ee\u6bcf\u4e2aDS18B20\uff0c\u641c\u7d2264\u4f4d\u5e8f\u5217\u53f7\uff0c\u8bfb\u53d6\u5339\u914d\u7684\u5e8f\u5217\u53f7\u503c\uff0c\u7136\u540e\u5339\u914d\u5bf9\u5e94\u7684DS18B20\uff0c\u5982\u679c\u6211\u4eec\u4ec5\u4ec5\u4f7f\u7528\u5355\u4e2aDS18B20\uff0c\u53ef\u4ee5\u76f4\u63a5\u8df3\u8fc7ROM\u6307\u4ee4\u3002\u800c\u8df3\u8fc7ROM\u6307\u4ee4\u7684\u5b57\u8282\u662f0xCC\u3002<\/p>\n<h3>\u521d\u59cb\u5316<\/h3>\n<p>\u9996\u5148\u521d\u59cb\u5316\u5355\u603b\u7ebf\u4e3a\u9ad8\u7535\u5e73\uff0c\u7136\u540e\u603b\u7ebf\u5f00\u59cb\u4e5f\u9700\u8981\u68c0\u6d4b\u8fd9\u6761\u603b\u7ebf\u4e0a\u662f\u5426\u5b58\u5728DS18B20\u8fd9\u4e2a\u5668\u4ef6\u3002\u5982\u679c\u8fd9\u6761\u603b\u7ebf\u4e0a\u5b58\u5728DS18B20\uff0c\u603b\u7ebf\u4f1a\u6839\u636e\u65f6\u5e8f\u8981\u6c42\u8fd4\u56de\u4e00\u4e2a\u4f4e\u7535\u5e73\u8109\u51b2\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u7684\u8bdd\uff0c\u4e5f\u5c31\u4e0d\u4f1a\u8fd4\u56de\u8109\u51b2\uff0c\u5373\u603b\u7ebf\u4fdd\u6301\u4e3a\u9ad8\u7535\u5e73\u3002\u5373\u4e3b\u673a\u53d1\u9001\u590d\u4f4d\u8109\u51b2\uff0c\u4ece\u673a\u54cd\u5e94\u5b58\u5728\u8109\u51b2\u3002<\/p>\n<p>GPIO\u5f15\u811a\u914d\u7f6e\u6210\u5f00\u6f0f\u8f93\u51fa\uff0c\u5f00\u6f0f\u8f93\u51fa\u7684\u7279\u70b9\u4fbf\u662f\u53ea\u6709\u4f4e\u7535\u5e73\u548c\u9ad8\u963b\u6001\u4e24\u79cd\u72b6\u6001\uff0c\u7f6e0\u662f\u4f4e\u7535\u5e73\uff0c\u7f6e1\u662f\u9ad8\u963b\u6001\u800c\u4e0d\u662f\u9ad8\u7535\u5e73\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>void DS18B20_Init()\r\n{\r\n\t\/\/\u5f00\u542fGPIOG\u65f6\u949f\r\n\tRCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOGEN,ENABLE);\r\n\t\r\n\t\/\/\u914d\u7f6ePG9\u4e3a\u5f00\u6f0f\u8f93\u51fa\r\n\tGPIO_InitTypeDef GPIO_InitStructure;\r\n\tGPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;\r\n\tGPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;        \/\/ \u8f93\u51fa\u6a21\u5f0f\r\n\tGPIO_InitStructure.GPIO_OType = GPIO_OType_OD;       \/\/ \u5f00\u6f0f\u8f93\u51fa\r\n\tGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;\r\n\tGPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;         \/\/ \u4e0a\u62c9\r\n\tGPIO_Init(GPIOG, &amp;GPIO_InitStructure);\r\n\t\r\n}<\/code><\/pre>\n<ul>\n<li>\u00a0\u4e3b\u673a\u62c9\u4f4e\u603b\u7ebf\u81f3\u5c11480us\uff0c\u4ea7\u751f\u590d\u4f4d\u8109\u51b2\uff0c\u7136\u540e\u91ca\u653e\u603b\u7ebf\uff08\u62c9\u9ad8\u7535\u5e73\uff09\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li>\u8fd9\u65f6DS8B20\u68c0\u6d4b\u5230\u8bf7\u6c42\u4e4b\u540e\uff0c\u4f1a\u62c9\u4f4e\u4fe1\u53f7\uff0c\u5927\u7ea660~240us\u8868\u793a\u5e94\u7b54\u3002<\/li>\n<li>DS8B20\u62c9\u4f4e\u7535\u5e73\u768460~240us\u4e4b\u95f4\uff0c\u5355\u7247\u673a\u8bfb\u53d6\u603b\u7ebf\u7684\u7535\u5e73\uff0c\u5982\u679c\u662f\u4f4e\u7535\u5e73\uff0c\u90a3\u4e48\u8868\u793a\u521d\u59cb\u5316\u6210\u529f\u3002<\/li>\n<li>DS18B20\u62c9\u4f4e\u7535\u5e7360~240us\u4e4b\u540e\uff0c\u4f1a\u91ca\u653e\u603b\u7ebf(\u62c9\u9ad8\u7535\u5e73)\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-1489\" src=\"https:\/\/aoofoo.com\/wp-content\/uploads\/2024\/11\/\u5c4f\u5e55\u622a\u56fe-2024-11-22-173708.png\" alt=\"\" width=\"939\" height=\"330\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DS18B20\u4f20\u611f\u5668 DS18B20\u662f\u4e00\u4e2a\u4f7f\u7528\u5355\u603b\u7ebf\u534f\u8bae\u7684\u6e29\u5ea6\u4f20\u611f\u5668\uff0c\u4f9b\u7535\u7535\u538b\u662f3~5V\u4e4b\u95f4\uff0c\u6211\u4eec\u4f7f\u7528\u7684\u662fST [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-1484","post","type-post","status-publish","format-standard","hentry","category-issue"],"_links":{"self":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts\/1484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/comments?post=1484"}],"version-history":[{"count":1,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts\/1484\/revisions"}],"predecessor-version":[{"id":1490,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/posts\/1484\/revisions\/1490"}],"wp:attachment":[{"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/media?parent=1484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/categories?post=1484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aoofoo.com\/index.php\/wp-json\/wp\/v2\/tags?post=1484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}