{"id":10020465,"date":"2024-12-12T20:13:47","date_gmt":"2024-12-12T12:13:47","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020465"},"modified":"2024-12-12T20:13:47","modified_gmt":"2024-12-12T12:13:47","slug":"%e4%ba%ba%e4%bd%93%e7%ba%a2%e5%a4%96%e6%84%9f%e5%ba%94%e6%a8%a1%e5%9d%97%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020465","title":{"rendered":"\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\u8be6\u89e3"},"content":{"rendered":"<p>\u968f\u7740\u81ea\u52a8\u5316\u548c\u667a\u80fd\u5316\u6280\u672f\u7684\u53d1\u5c55\uff0c\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\u5728\u8bb8\u591a\u9886\u57df\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\uff0c\u6bd4\u5982\u5b89\u9632\u7cfb\u7edf\u3001\u81ea\u52a8\u7167\u660e\u548c\u81ea\u52a8\u95e8\u3002<\/p>\n<p>HC-SR501 \u5c31\u662f\u4e00\u6b3e\u9ad8\u6548\u3001\u7a33\u5b9a\u7684\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\uff0c\u5b83\u57fa\u4e8e\u70ed\u91ca\u7535\u6548\u5e94\uff0c\u80fd\u591f\u7cbe\u786e\u5730\u68c0\u6d4b\u4eba\u4f53\u6216\u52a8\u7269\u7684\u7ea2\u5916\u7ebf\u3002\u5728\u63a5\u4e0b\u6765\u7684\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u4e86\u89e3 HC-SR501 \u6a21\u5757\u7684\u7279\u70b9\u3001\u5de5\u4f5c\u539f\u7406\u4ee5\u53ca\u5982\u4f55\u5e94\u7528\u3002<\/p>\n<h2>1. \u6e90\u7801\u4e0b\u8f7d\u53ca\u524d\u7f6e\u9605\u8bfb<\/h2>\n<p>\u672c\u6587\u9996\u53d1 <strong>\u826f\u8bb8\u5d4c\u5165\u5f0f\u7f51<\/strong> \uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=ApZ9ltGazbX0Qam9K5hmzg%3D%3D.cy2aBriGq5yYuav2djOh96e%2BExQs8AdkdBo6g2ozZcQ%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.lxlinux.net\/e\/<\/a> \uff0c\u6b22\u8fce\u5173\u6ce8\uff01<\/p>\n<p>\u672c\u6587\u6240\u6d89\u53ca\u7684\u6e90\u7801\u53ca\u5b89\u88c5\u5305\u5982\u4e0b\uff08\u7531\u4e8e\u5e73\u53f0\u9650\u5236\uff0c\u8bf7\u70b9\u51fb\u4ee5\u4e0b\u94fe\u63a5\u9605\u8bfb\u539f\u6587\u4e0b\u8f7d\uff09\uff1a<\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=wYHwj3lZmFCogEJX2td%2Bkg%3D%3D.oUuuVG9iCBxC66IvOVKQ6AWq68bwHcf1J8GBEpy%2BEGUUsK8tEEqlB6%2BV7Mgn9urTl3vydq6qPQ8pq5qSnDXTBg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.lxlinux.net\/e\/stm32\/hc-sr501-tutorial.html<\/a><\/p>\n<p>\u8d85\u5168\u7684\u5d4c\u5165\u5f0f\u5165\u95e8\u6559\u7a0b\uff0c\u6b22\u8fce\u5c0f\u767d\u3002<\/p>\n<ul>\n<li>\u4ece\u96f6\u5f00\u59cb\u8f7b\u677e\u638c\u63e1STM32\u5f00\u53d1\u7684\u5fc5\u5907\u6307\u5357\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=eEHthTzaZi52N%2FvcV7TxHQ%3D%3D.bSvfNSQ6Yvf1ZYn9hihBGfSsspDronGbbCgEe0GQjMqLlz8VR5tRlBocMaHkdRf%2BgV5LP13YGXbS2JOQFKrfK5MJ%2FvMvDvVl9AQXgr4K%2FlA%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u96f6\u57fa\u7840\u5feb\u901f\u4e0a\u624bSTM32\u5f00\u53d1\uff08\u624b\u628a\u624b\u4fdd\u59c6\u7ea7\u6559\u7a0b\uff09<\/a><\/li>\n<li>\u4f7f\u7528\u63a5\u6536\u4e2d\u65ad+\u8d85\u65f6\u5224\u65ad\u5b8c\u6210\u4e0d\u5b9a\u957f\u6570\u636e\u7684\u63a5\u6536\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=LgZ6lSHmZQrnQBQ0WikJSQ%3D%3D.C9Fvjot3UaDjGUCVXsqY2CZTUndNjmutDPmfF%2FCqFwoj1Ebt0%2F5RibM2LCr8vePxIZyzN%2FD3jMyqJTp55ifwvd0emiD%2Bq96g35Q4e0bOTQE%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">STM32\u4e32\u53e3\u63a5\u6536\u4e0d\u5b9a\u957f\u6570\u636e\uff08\u7a7a\u95f2\u4e2d\u65ad+DMA\uff09<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=8kMD55lfQcpFbVsuTQUXng%3D%3D.swh3yInWLd12kLbTQXdILYf6vcRFX1tlPGq6dbMY1RAye5HBpxBW9ldzVGJ0Wz8IiuFLBpagf2rXkR2qq1YhlA%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u4e00\u6587\u6559\u4f60\u4f7f\u7528STM32CubeMX\u5f00\u53d1\u5de5\u5177<\/a><\/li>\n<\/ul>\n<p>\u5f80\u671f\u7cbe\u5f69\u6559\u7a0b\uff0c\u6709\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u770b\u770b\u3002<\/p>\n<ul>\n<li>\u5b9e\u73b0\u7269\u8054\u7f51\u6570\u636e\u91c7\u96c6\u4e0e\u8fdc\u7a0b\u76d1\u63a7\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=OPyXk2oeHYNSC89b3mp%2Bzw%3D%3D.kINa05RHnT7mR5Zcf84msbtRAf8YTSLqeR6CtbmC0Xw30UHpc5c1MF8RIJMr9SLaXiAjeMQwQnml8LNmbNxhu9pnLAXAZX80hb6nHZTWTYc%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u5c0f\u9879\u76ee\uff1a\u4f7f\u7528MQTT\u4e0a\u4f20\u6e29\u6e7f\u5ea6\u5230Onenet\u670d\u52a1\u5668<\/a><\/li>\n<li>\u84dd\u7259\u6a21\u5757\u8be6\u89e3\uff0c\u8f7b\u677e\u638c\u63e1\u4e00\u79cd\u65e0\u7ebf\u901a\u4fe1\u6280\u672f\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=gFfOfGrXVEqhAsp7JrHgZg%3D%3D.HWoScmNjKFfH08v82bI3T0B2hZe%2FJw6gGqn2jQRm11%2FJ9jPC76lT4MWPHDenbkV%2BPT53PQeogvsfcx24DR5rHg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u624b\u628a\u624b\u6559\u4f60\u73a9\u8f6c\u84dd\u7259\u6a21\u5757\uff08\u539f\u7406+\u9a71\u52a8\uff09<\/a><\/li>\n<li>\u7b80\u5355\u597d\u7528\uff0c\u4e3a\u4f60\u7684\u667a\u80fd\u8bed\u97f3\u9879\u76ee\u63d0\u4f9b\u6838\u5fc3\u652f\u6301\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=yLsP%2BTYhUHjEJt%2BtYDc8wQ%3D%3D.9IqLmjVKD9KE1v2JHBmCl7BtkjLABSY0PJGUalfSMrJh5su%2FSsdXWq91L%2FTBI%2Bj2TUFuLFlRPAdip2na65qeEg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">SU-03T\u8bed\u97f3\u63a7\u5236\u6a21\u5757\u8be6\u89e3<\/a><\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th align=\"left\">\u4f5c\u8005\u7b80\u4ecb<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\">\u5927\u5bb6\u597d\uff0c\u6211\u662f\u826f\u8bb8\uff0c\u535a\u5ba2\u91cc\u6240\u6709\u7684\u6587\u7ae0\u7686\u4e3a\u6211\u7684\u539f\u521b\u3002<br \/>\u4e0b\u9762\u662f\u6211\u7684\u4e00\u4e9b\u4e2a\u4eba\u4ecb\u7ecd\uff0c\u6b22\u8fce\u4ea4\u4e2a\u670b\u53cb\uff1a<br \/>\u00b7 211\u5de5\u79d1\u7855\u58eb\uff0c\u56fd\u5bb6\u5956\u5b66\u91d1\u83b7\u5f97\u8005\uff1b<br \/>\u00b7 \u6df1\u8015\u5d4c\u5165\u5f0f11\u5e74\uff0c\u524d\u4e16\u754c500\u5f3a\u5916\u4f01\u9ad8\u7ea7\u5d4c\u5165\u5f0f\u5de5\u7a0b\u5e08\uff1b<br \/>\u00b7 \u4e66\u7c4d\u300a\u901f\u5b66Linux\u4f5c\u8005\u300b\uff0c\u673a\u68b0\u5de5\u4e1a\u51fa\u7248\u793e\u4e13\u5bb6\u59d4\u5458\u4f1a\u6210\u5458\uff1b<br \/>\u00b7 \u5168\u7f5160W\u7c89\u4e1d\uff0c\u535a\u5ba2\u5206\u4eab\u5927\u91cf\u539f\u521b\u6210\u4f53\u7cfb\u6587\u7ae0\uff0c\u5168\u7f51\u9605\u8bfb\u91cf\u7d2f\u8ba1\u8d854000\u4e07\uff1b<br \/>\u00b7 \u9760\u81ea\u5a92\u4f53\u8fde\u7eed\u5e74\u5165\u767e\u4e07\uff0c\u9760\u81ea\u5df1\u4e70\u623f\u4e70\u8f66\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u672c\u79d1\u53ca\u7855\u58eb\u90fd\u662f\u5b66\u673a\u68b0\uff0c\u901a\u8fc7\u81ea\u5b66\u6210\u529f\u8fdb\u5165\u4e16\u754c500\u5f3a\u5916\u4f01\u3002\u6211\u5df2\u7ecf\u5c06\u81ea\u5df1\u7684\u5b66\u4e60\u7ecf\u9a8c\u5199\u6210\u4e86\u4e00\u672c\u7535\u5b50\u4e66\uff0c\u8d85\u5343\u4eba\u901a\u8fc7\u6b64\u4e66\u5b66\u4e60\u5e76\u8f6c\u884c\u6210\u529f\u3002\u73b0\u5728\u5c06\u8fd9\u672c\u7535\u5b50\u4e66\u514d\u8d39\u5206\u4eab\u7ed9\u5927\u5bb6\uff0c\u5e0c\u671b\u5bf9\u4f60\u4eec\u6709\u5e2e\u52a9\uff1a<\/p>\n<p>\u7535\u5b50\u4e66\u94fe\u63a5\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=5yWBKzv456zLcLMK1apfug%3D%3D.yZYRvHLtGjpEoSryuqC%2FQ9E8qkjDh28CZ1DSZit7bW5aN74dkwThyUlPymGvM%2BqJ\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.lxlinux.net\/1024.html<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"392\" height=\"836\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfebd\" alt=\"\" title=\"\"><\/p>\n<h2>2. HC-SR501\u4ecb\u7ecd<\/h2>\n<p>\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\u5927\u5bb6\u65cf\u6709\u5f88\u591a\u6210\u5458\uff0c\u7ed9\u5927\u5bb6\u770b\u770b\u90e8\u5206\u6210\u5458\u7684\u6837\u8c8c\u3002HC-SR501 \u84dd\u677f\u548c\u7eff\u677f\u53ea\u662f\u989c\u8272\u4e0d\u540c\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"462\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdftvI\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>HC-SR501\u662f\u57fa\u4e8e\u7ea2\u5916\u7ebf\u6280\u672f\u7684\u81ea\u52a8\u63a7\u5236\u6a21\u5757\uff0c\u91c7\u7528\u5fb7\u56fd\u539f\u88c5\u8fdb\u53e3 LHI778 \u63a2\u5934\u8bbe\u8ba1\uff0c\u7075\u654f\u5ea6\u9ad8\uff0c\u53ef\u9760\u6027\u5f3a\uff0c\u8d85\u4f4e\u7535\u538b\u5de5\u4f5c\u6a21\u5f0f\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u7c7b\u81ea\u52a8\u611f\u5e94\u7535\u5668\u8bbe\u5907\uff0c\u5c24\u5176\u662f\u5e72\u7535\u6c60\u4f9b\u7535\u7684\u81ea\u52a8\u63a7\u5236\u4ea7\u54c1\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"509\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdftvJ\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u767d\u8272\u7684\u534a\u7403\u4f53\u662f\u83f2\u6d85\u8033\u900f\u955c\uff0c\u62c6\u4e0b\u5b83\uff0c\u91cc\u9762\u957f\u8fd9\u6837\u3002\u63a2\u5934\u7528\u4e8e\u68c0\u6d4b\u4eba\u4f53\u7ea2\u5916\uff0c\u9884\u7559\u7684\u4e24\u4e2a\u63a5\u53e3\u5728\u4e0b\u6587\u4f1a\u63d0\u5230\u5e76\u89e3\u91ca\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"619\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdftvK\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>2.1 HC-SR501\u529f\u80fd\u7279\u70b9<\/h3>\n<ol>\n<li>\u5168\u81ea\u52a8\u611f\u5e94\uff1a\u4eba\u8fdb\u5165\u5176\u611f\u5e94\u8303\u56f4\u5219\u8f93\u51fa\u9ad8\u7535\u5e73\uff0c\u4eba\u79bb\u5f00\u611f\u5e94\u8303\u56f4\u5219\u81ea\u52a8\u5ef6\u65f6\u5173\u95ed\u9ad8\u7535\u5e73\uff0c\u8f93\u51fa\u4f4e\u7535\u5e73\u3002<\/li>\n<li>\u5149\u654f\u63a7\u5236\uff08\u53ef\u9009\u62e9\uff0c\u51fa\u5382\u65f6\u672a\u8bbe\uff09\u53ef\u8bbe\u7f6e\u5149\u654f\u63a7\u5236\uff0c\u767d\u5929\u6216\u5149\u7ebf\u5f3a\u65f6\u4e0d\u611f\u5e94\u3002\uff08\u4f7f\u7528\u5149\u654f\u7535\u963b\u63a5\u53e3\uff09<\/li>\n<li>\u6e29\u5ea6\u8865\u507f(\u53ef\u9009\u62e9\uff0c\u51fa\u5382\u65f6\u672a\u8bbe)\uff1a\u5728\u590f\u5929\u5f53\u73af\u5883\u6e29\u5ea6\u5347\u9ad8\u81f330\uff5e32\u2103\uff0c\u63a2\u6d4b\u8ddd\u79bb\u7a0d\u53d8\u77ed\uff0c\u6e29\u5ea6\u8865\u507f\u53ef\u4f5c\u4e00\u5b9a\u7684\u6027\u80fd\u8865\u507f\u3002\uff08\u4f7f\u7528\u70ed\u654f\u7535\u963b\u63a5\u53e3\uff09<\/li>\n<li>\u4e24\u79cd\u89e6\u53d1\u65b9\u5f0f\uff08\u8df3\u7ebf\u9009\u62e9\uff09\uff1a\uff081\uff09\u4e0d\u53ef\u91cd\u590d\u89e6\u53d1\u65b9\u5f0f\uff1a\u5373\u611f\u5e94\u8f93\u51fa\u9ad8\u7535\u5e73\u540e\uff0c\u5ef6\u65f6\u65f6\u95f4\u6bb5\u4e00\u7ed3\u675f\uff0c\u8f93\u51fa\u5c06\u81ea\u52a8\u4ece\u9ad8\u7535\u5e73\u53d8\u6210\u4f4e\u7535\u5e73\uff1b\uff082\uff09\u53ef\u91cd\u590d\u89e6\u53d1\u65b9\u5f0f\uff1a\u5373\u611f\u5e94\u8f93\u51fa\u9ad8\u7535\u5e73\u540e\uff0c\u5728\u5ef6\u65f6\u65f6\u95f4\u6bb5\u5185\uff0c\u5982\u679c\u6709\u4eba\u4f53\u5728\u5176\u611f\u5e94\u8303\u56f4\u6d3b\u52a8\uff0c\u5176\u8f93\u51fa\u5c06\u4e00\u76f4\u4fdd\u6301\u9ad8\u7535\u5e73\uff0c\u76f4\u5230\u4eba\u79bb\u5f00\u540e\u624d\u5ef6\u65f6\u5c06\u9ad8\u7535\u5e73\u53d8\u4e3a\u4f4e\u7535\u5e73\u3002<\/li>\n<li>\u5177\u6709\u611f\u5e94\u5c01\u9501\u65f6\u95f4\uff08\u9ed8\u8ba4\u8bbe\u7f6e\uff1a2.5\u79d2\u5c01\u9501\u65f6\u95f4\uff09\uff1a\u611f\u5e94\u6a21\u5757\u5728\u6bcf\u4e00\u6b21\u611f\u5e94\u8f93\u51fa\u540e\uff08\u9ad8\u7535\u5e73\u53d8\u6210\u4f4e\u7535\u5e73\uff09\uff0c\u53ef\u4ee5\u7d27\u8ddf\u7740\u8bbe\u7f6e\u4e00\u4e2a\u5c01\u9501\u65f6\u95f4\u6bb5\uff0c\u5728\u6b64\u65f6\u95f4\u6bb5\u5185\u611f\u5e94\u5668\u4e0d\u63a5\u53d7\u4efb\u4f55\u611f\u5e94\u4fe1\u53f7\u3002\u6b64\u529f\u80fd\u53ef\u4ee5\u5b9e\u73b0\u201c\u611f\u5e94\u8f93\u51fa\u65f6\u95f4\u201d\u548c\u201c\u5c01\u9501\u65f6\u95f4\u201d\u4e24\u8005\u7684\u95f4\u9694\u5de5\u4f5c\uff0c\u53ef\u5e94\u7528\u4e8e\u95f4\u9694\u63a2\u6d4b\u4ea7\u54c1\uff1b\u540c\u65f6\u6b64\u529f\u80fd\u53ef\u6709\u6548\u6291\u5236\u8d1f\u8f7d\u5207\u6362\u8fc7\u7a0b\u4e2d\u4ea7\u751f\u7684\u5404\u79cd\u5e72\u6270\u3002<\/li>\n<li>\u5de5\u4f5c\u7535\u538b\u8303\u56f4\u5bbd\uff1a\u5de5\u4f5c\u7535\u538b DC4.5V-20V\u3002<\/li>\n<li>\u5fae\u529f\u8017\uff1a\u9759\u6001\u7535\u6d41&lt;50\u5fae\u5b89\u3002<\/li>\n<li>\u8f93\u51fa\u9ad8\u7535\u5e73\u4fe1\u53f7\uff1a\u53ef\u65b9\u4fbf\u4e0e\u5404\u7c7b\u7535\u8def\u5b9e\u73b0\u5bf9\u63a5\u3002<\/li>\n<\/ol>\n<h3>2.2 HC-SR501\u4f7f\u7528\u8bf4\u660e<\/h3>\n<ol>\n<li>\u611f\u5e94\u6a21\u5757\u901a\u7535\u540e\u6709\u4e00\u5206\u949f\u5de6\u53f3\u7684\u521d\u59cb\u5316\u65f6\u95f4\uff0c\u5728\u6b64\u671f\u95f4\u6a21\u5757\u4f1a\u95f4\u9694\u5730\u8f93\u51fa0-3\u6b21\uff0c\u4e00\u5206\u949f\u540e\u8fdb\u5165\u5f85\u673a\u72b6\u6001\u3002<\/li>\n<li>\u907f\u514d\u706f\u5149\u7b49\u5e72\u6270\u6e90\u8fd1\u8ddd\u79bb\u76f4\u5c04\u6a21\u5757\u8868\u9762\u7684\u900f\u955c\uff0c\u4ee5\u514d\u5f15\u8fdb\u5e72\u6270\u4fe1\u53f7\u4ea7\u751f\u8bef\u52a8\u4f5c\uff1b\u5c3d\u91cf\u907f\u514d\u6d41\u52a8\u7684\u98ce\uff0c\u98ce\u4e5f\u4f1a\u5bf9\u611f\u5e94\u5668\u9020\u6210\u5e72\u6270\u3002<\/li>\n<li>\u611f\u5e94\u6a21\u5757\u91c7\u7528\u53cc\u5143\u63a2\u5934\uff0c\u63a2\u5934\u7684\u7a97\u53e3\u4e3a\u957f\u65b9\u5f62\uff0c\u53cc\u5143\uff08A\u5143\u3001B\u5143\uff09\u4f4d\u4e8e\u8f83\u957f\u65b9\u5411\u7684\u4e24\u7aef\uff0c\u5f53\u4eba\u4f53\u4ece\u5de6\u5230\u53f3\u6216\u4ece\u53f3\u5230\u5de6\u8d70\u8fc7\u65f6\uff0c\u7ea2\u5916\u5149\u8c31\u5230\u8fbe\u53cc\u5143\u7684\u65f6\u95f4\u3001\u8ddd\u79bb\u6709\u5dee\u503c\uff0c\u5dee\u503c\u8d8a\u5927\uff0c\u611f\u5e94\u8d8a\u7075\u654f\uff0c\u5f53\u4eba\u4f53\u4ece\u6b63\u9762\u8d70\u5411\u63a2\u5934\u6216\u4ece\u4e0a\u5230\u4e0b\u6216\u4ece\u4e0b\u5230\u4e0a\u65b9\u5411\u8d70\u8fc7\u65f6\uff0c\u53cc\u5143\u68c0\u6d4b\u4e0d\u5230\u7ea2\u5916\u5149\u8c31\u8ddd\u79bb\u7684\u53d8\u5316\uff0c\u65e0\u5dee\u503c\uff0c\u56e0\u6b64\u611f\u5e94\u4e0d\u7075\u654f\u6216\u4e0d\u5de5\u4f5c\uff1b\u6240\u4ee5\u5b89\u88c5\u611f\u5e94\u5668\u65f6\u5e94\u4f7f\u63a2\u5934\u53cc\u5143\u7684\u65b9\u5411\u4e0e\u4eba\u4f53\u6d3b\u52a8\u6700\u591a\u7684\u65b9\u5411\u5c3d\u91cf\u76f8\u5e73\u884c\uff0c\u4fdd\u8bc1\u4eba\u4f53\u7ecf\u8fc7\u65f6\u5148\u540e\u88ab\u63a2\u5934\u53cc\u5143\u6240\u611f\u5e94\u3002\u4e3a\u4e86\u589e\u52a0\u611f\u5e94\u89d2\u5ea6\u8303\u56f4\uff0c\u672c\u6a21\u5757\u91c7\u7528\u5706\u5f62\u900f\u955c\uff0c\u4e5f\u4f7f\u5f97\u63a2\u5934\u56db\u9762\u90fd\u611f\u5e94\uff0c\u4f46\u5de6\u53f3\u4e24\u4fa7\u4ecd\u7136\u6bd4\u4e0a\u4e0b\u4e24\u4e2a\u65b9\u5411\u611f\u5e94\u8303\u56f4\u5927\u3001\u7075\u654f\u5ea6\u5f3a\uff0c\u5b89\u88c5\u65f6\u4ecd\u987b\u5c3d\u91cf\u6309\u4ee5\u4e0a\u8981\u6c42\u3002<\/li>\n<li>\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\u5e94\u79bb\u5730\u97622.0-2.2\u7c73\u3002<\/li>\n<li>\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\u8fdc\u79bb\u7a7a\u8c03\uff0c \u51b0\u7bb1\uff0c\u706b\u7089\u7b49\u7a7a\u6c14\u6e29\u5ea6\u53d8\u5316\u654f\u611f\u7684\u5730\u65b9\u3002<\/li>\n<li>\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\u63a2\u6d4b\u8303\u56f4\u5185\u4e0d\u5f97\u9694\u5c4f\u3001\u5bb6\u5177\u3001\u5927\u578b\u76c6\u666f\u6216\u5176\u4ed6\u9694\u79bb\u7269\u3002<\/li>\n<li>\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\u4e0d\u8981\u76f4\u5bf9\u7a97\u53e3\uff0c\u5426\u5219\u7a97\u5916\u7684\u70ed\u6c14\u6d41\u6270\u52a8\u548c\u4eba\u5458\u8d70\u52a8\u4f1a\u5f15\u8d77\u8bef\u62a5\uff0c\u6709\u6761\u4ef6\u7684\u6700\u597d\u628a\u7a97\u5e18\u62c9\u4e0a\u3002\u7ea2\u5916\u7ebf\u70ed\u91ca\u7535\u4f20\u611f\u5668\u4e5f\u4e0d\u8981\u5b89\u88c5\u5728\u6709\u5f3a\u6c14\u6d41\u6d3b\u52a8\u7684\u5730\u65b9\u3002<\/li>\n<\/ol>\n<p>\u5b89\u88c5\u65b9\u9762\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u8981<strong>\u907f\u5f00\u6e29\u5ea6\u5e72\u6270\u3001\u6c14\u6d41\u5e72\u6270\u548c\u5927\u578b\u969c\u788d<\/strong>\u3002<\/p>\n<h2>3. \u5de5\u4f5c\u539f\u7406<\/h2>\n<p>HC-SR501 \u5de5\u4f5c\u65f6\uff0c\u63a2\u5934\u68c0\u6d4b\u5230\u6709\u4eba\u79fb\u52a8\u65f6\uff0c\u8f93\u51fa1\uff1b\u6ca1\u4eba\u79fb\u52a8\u65f6\uff0c\u8f93\u51fa0\u3002<\/p>\n<p>\u90a3\u4e48\u539f\u7406\u662f\u4ec0\u4e48\u5462\uff1f<\/p>\n<p>\u5728\u89e3\u91ca\u539f\u7406\u524d\uff0c\u6211\u4eec\u5148\u89e3\u91ca\u4e24\u4e2a\u540d\u8bcd\u3002<\/p>\n<ul>\n<li>\u83f2\u6d85\u8033\u900f\u955c<\/li>\n<\/ul>\n<p>\u6839\u636e\u83f2\u6d85\u8033\u539f\u7406\u5236\u6210\uff0c\u6709\u5982\u4e0b\u7279\u70b9\uff1a<\/p>\n<ol>\n<li>\u805a\u7126\u4f5c\u7528\uff1a\u83f2\u6d85\u8033\u900f\u955c\u53ef\u4ee5\u5c06\u5165\u5c04\u5149\u7ebf\u805a\u7126\u5230\u4e00\u4e2a\u70b9\u4e0a\uff0c\u5b9e\u73b0\u5149\u7ebf\u7684\u96c6\u4e2d\u548c\u805a\u7126\u6548\u679c\u3002\u8fd9\u4f7f\u5f97\u83f2\u6d85\u8033\u900f\u955c\u5728\u8bb8\u591a\u5149\u5b66\u7cfb\u7edf\u4e2d\u88ab\u5e7f\u6cdb\u4f7f\u7528\uff0c\u5982\u6444\u5f71\u955c\u5934\u3001\u671b\u8fdc\u955c\u3001\u6295\u5f71\u4eea\u7b49\u3002<\/li>\n<li>\u7ea2\u5916\u611f\u5e94\uff1a\u83f2\u6d85\u8033\u900f\u955c\u4e5f\u5e38\u7528\u4e8e\u7ea2\u5916\u4f20\u611f\u5668\u548c\u4eba\u4f53\u611f\u5e94\u6a21\u5757\u4e2d\u3002\u901a\u8fc7\u5bf9\u7ea2\u5916\u8f90\u5c04\u7684\u805a\u7126\u4f5c\u7528\uff0c\u5b83\u80fd\u591f\u589e\u5f3a\u7ea2\u5916\u4fe1\u53f7\u7684\u63a5\u6536\u7075\u654f\u5ea6\uff0c\u5e76\u63d0\u9ad8\u7ea2\u5916\u4f20\u611f\u5668\u7684\u6027\u80fd\u3002<\/li>\n<li>\u5206\u533a\u63a7\u5236\uff1a\u83f2\u6d85\u8033\u900f\u955c\u7684\u8868\u9762\u901a\u5e38\u88ab\u5212\u5206\u4e3a\u82e5\u5e72\u4e2a\u660e\u6697\u533a\u57df\uff0c\u4f7f\u5f97\u5149\u7ebf\u80fd\u591f\u4ee5\u4e0d\u540c\u7684\u8def\u5f84\u901a\u8fc7\u900f\u955c\u3002\u8fd9\u79cd\u8bbe\u8ba1\u53ef\u4ee5\u7528\u4e8e\u5149\u63a7\u5236\u7cfb\u7edf\u4e2d\uff0c\u4f8b\u5982\u8c03\u8282\u7167\u660e\u4eae\u5ea6\u3001\u9632\u7729\u5149\u7b49\u5e94\u7528\u3002<\/li>\n<\/ol>\n<ul>\n<li>\u70ed\u91ca\u7535\u6548\u5e94<\/li>\n<\/ul>\n<p>\u5f53\u4e00\u4e9b\u6676\u4f53\u53d7\u70ed\u65f6\uff0c\u5728\u6676\u4f53\u4e24\u7aef\u5c06\u4f1a\u4ea7\u751f\u6570\u91cf\u76f8\u7b49\u800c\u7b26\u53f7\u76f8\u53cd\u7684\u7535\u8377\u3002\u8fd9\u79cd\u7531\u4e8e\u70ed\u53d8\u5316\u800c\u4ea7\u751f\u7684\u7535\u6781\u5316\u73b0\u8c61\u79f0\u4e3a\u70ed\u91ca\u7535\u6548\u5e94\u3002<\/p>\n<p>\u77e5\u9053\u4e86\u8fd9\u4e24\u4e2a\u540d\u8bcd\u540e\uff0c\u6211\u4eec\u5c31\u80fd\u7406\u89e3 HC-SR501 \u7684\u5de5\u4f5c\u539f\u7406\u4e86\u3002<\/p>\n<ol>\n<li>\u6211\u4eec\u7684\u4eba\u4f53\u7684\u4f53\u6e29\u5927\u6982\u572837\u5ea6\uff0c\u4f1a\u53d1\u51fa\u7279\u5b9a\u6ce2\u957f 10\u03bcm \u5de6\u53f3\u7684\u7ea2\u5916\u7ebf\uff0cHC-SR501 \u4e0a\u7684\u7ea2\u5916\u63a2\u5934\u5c31\u662f\u9760\u63a2\u6d4b\u4eba\u4f53\u53d1\u5c04\u7684 10\u03bcm \u5de6\u53f3\u7684\u7ea2\u5916\u7ebf\u800c\u8fdb\u884c\u5de5\u4f5c\u7684\u3002\u5f53\u7136\uff0c\u5982\u679c\u662f\u4f53\u6e29\u76f8\u4f3c\u7684\u52a8\u7269\u4e5f\u4f1a\u88ab\u68c0\u6d4b\u5230\u3002<\/li>\n<li>\u4eba\u4f53\u53d1\u5c04\u7684 10\u03bcm \u5de6\u53f3\u7684\u7ea2\u5916\u7ebf\u901a\u8fc7\u83f2\u6ce5\u5c14\u6ee4\u900f\u955c\u589e\u5f3a\u540e\u805a\u96c6\u5230\u7ea2\u5916\u611f\u5e94\u6e90\u4e0a\u3002<\/li>\n<li>\u7ea2\u5916\u611f\u5e94\u6e90\u901a\u5e38\u91c7\u7528\u70ed\u91ca\u7535\u5143\u4ef6\uff0c\u8fd9\u79cd\u5143\u4ef6\u5728\u63a5\u6536\u5230\u4eba\u4f53\u7ea2\u5916\u8f90\u5c04\u6e29\u5ea6\u53d1\u751f\u53d8\u5316\u65f6\u5c31\u4f1a\u5931\u53bb\u7535\u8377\u5e73\u8861\uff0c\u5411\u5916\u91ca\u653e\u7535\u8377\uff0c\u540e\u7eed\u7535\u8def\u7ecf\u68c0\u6d4b\u5904\u7406\u540e\u5c31\u80fd\u4ea7\u751f\u62a5\u8b66\u4fe1\u53f7\u3002<\/li>\n<\/ol>\n<h2>4. \u5de5\u4f5c\u53c2\u6570\u53ca\u5f15\u811a\u4ecb\u7ecd<\/h2>\n<p>HC-SR501 \u6a21\u5757\u5de5\u4f5c\u53c2\u6570\uff0c\u6bcf\u4e2a\u5382\u5bb6\u4f1a\u6709\u70b9\u4e0d\u540c\uff1a<\/p>\n<ol>\n<li>\u5de5\u4f5c\u7535\u538b\uff1aDC 4.5V\u81f320V<\/li>\n<li>\u9759\u6001\u529f\u8017\uff1a&lt;50\u5fae\u5b89<\/li>\n<li>\u7535\u5e73\u8f93\u51fa\uff1a\u9ad83.3V\uff0c\u4f4e0V<\/li>\n<li>\u5ef6\u65f6\u65f6\u95f4\uff1a\u53ef\u8c03\uff088\u79d2~200\u79d2\uff09<\/li>\n<li>\u5c01\u9501\u65f6\u95f4\uff1a2.5\u79d2<\/li>\n<li>\u89e6\u53d1\u65b9\u5f0f\uff1aL\u4e0d\u53ef\u91cd\u590d\uff0cH\u53ef\u91cd\u590d\uff0c\u9ed8\u8ba4\u503c\u4e3aH\uff08\u8df3\u5e3d\u9009\u62e9\uff09<\/li>\n<li>\u611f\u5e94\u8303\u56f4\uff1a\u5c0f\u4e8e120\u5ea6\u9525\u89d2\uff0c7\u7c73\u4ee5\u5185<\/li>\n<li>\u5de5\u4f5c\u6e29\u5ea6\uff1a-15\u00b0 ~ +70\u00b0<\/li>\n<\/ol>\n<p>\u8c03\u8282\u548c\u63a5\u7ebf\u53c2\u8003\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"701\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdftvL\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>5. \u7f16\u7a0b\u5b9e\u6218<\/h2>\n<h3>5.1 \u901a\u4fe1\u793a\u610f\u56fe<\/h3>\n<p>\u6211\u4eec\u7684\u5b9e\u73b0\u76ee\u6807\u662f\uff1a\u5f53\u6709\u4eba\u7ecf\u8fc7\u65f6\uff0c\u7ea2\u706f\u4eae\u8d77\uff0c\u65e0\u4eba\u65f6\uff0c\u7ea2\u706f\u706d\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"301\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdftvM\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>5.2 \u786c\u4ef6\u8fde\u63a5<\/h3>\n<p>\u672c\u6559\u7a0b\u4f7f\u7528\u7684\u786c\u4ef6\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u5355\u7247\u673a\uff1aSTM32F103C8T6<\/li>\n<li>\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\uff1aHC-SR501<\/li>\n<li>\u5c0f\u706f\uff1a\u4e09\u8272 LED \u706f\u6a21\u5757<\/li>\n<li>\u70e7\u5f55\u5668\uff1aST-LINK V2<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th align=\"center\">HC-SR501\u6a21\u5757<\/th>\n<th align=\"center\">STM32<\/th>\n<th align=\"center\">LED<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">5V<\/td>\n<td align=\"center\">5V<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u8f93\u51fa<\/td>\n<td align=\"center\">A4<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\">GND<\/td>\n<td align=\"center\">G<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\">A5<\/td>\n<td align=\"center\">R<\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\">G<\/td>\n<td align=\"center\">GND<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u70e7\u5f55\u7684\u65f6\u5019\u63a5\u7ebf\u5982\u4e0b\u8868\uff0c\u5982\u679c\u4e0d\u4f1a\u70e7\u5f55\u7684\u8bdd\u53ef\u4ee5\u770b\u6211\u4e4b\u524d\u7684\u6587\u7ae0\u3010<a href=\"https:\/\/link.segmentfault.com\/?enc=viGGJhAP0iJquk4qZj2ksw%3D%3D.03VFuCyfQVDl2GX%2BVoBjurM2MfY89AtibGhqKu93Sec6A4fGOEXSKQYYUWwUeGcMuA02lYaOUDvhcDBch8QTRF7VJWnJ7pFlVcw0fh7qudw%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">STM32\u4e0b\u8f7d\u7a0b\u5e8f\u7684\u4e94\u79cd\u65b9\u6cd5<\/a>\u3011\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">ST-Link V2<\/th>\n<th align=\"center\">STM32<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">SWCLK<\/td>\n<td align=\"center\">SWCLK<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">SWDIO<\/td>\n<td align=\"center\">SWDIO<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">GND<\/td>\n<td align=\"center\">GND<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">3.3V<\/td>\n<td align=\"center\">3V3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u63a5\u597d\u5982\u4e0b\u56fe\uff1a<\/p>\n<p>\u5f00\u53d1\u677f\u4f7f\u7528\u7684\u662f\u6211\u4eec\u81ea\u7ed8\u7684\u677f\u5b50\u3002\u5927\u5bb6\u4e5f\u53ef\u4ee5\u7528\u81ea\u5df1\u7684\u677f\u5b50\uff0c\u53ea\u8981\u662f STM32F103C8T6 \u4e3b\u63a7\u82af\u7247\u5c31\u884c\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"562\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdftvN\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>5.3 LED\u521d\u59cb\u5316<\/h3>\n<p>LED \u706f\u7684\u4ee3\u7801\u7b80\u7b80\u5355\u5355\uff0c\u53ea\u8981\u8fdb\u884c\u4e00\u4e0b\u4e09\u4e2a\u706f\u7684\u521d\u59cb\u5316\u5c31\u884c\uff0c\u867d\u7136\u672c\u9879\u76ee\u6211\u4eec\u53ea\u7528\u5230\u7ea2\u706f\uff08LED1\uff09\uff0c\u4f46\u662f\u5176\u4ed6\u4e24\u4e2a\u706f\u5c31\u6211\u4e5f\u5c31\u61d2\u5f97\u5220\u4e86\u3002<\/p>\n<pre><code class=\"c\">void led_init(void)\n{\n    GPIO_InitTypeDef gpio_init_struct;\n    LED1_GPIO_CLK_ENABLE();                                 \/* LED1\u65f6\u949f\u4f7f\u80fd *\/\n    LED2_GPIO_CLK_ENABLE();                                 \/* LED2\u65f6\u949f\u4f7f\u80fd *\/\n    LED3_GPIO_CLK_ENABLE();                                 \/* LED3\u65f6\u949f\u4f7f\u80fd *\/\n\n    gpio_init_struct.Pin = LED1_GPIO_PIN;                   \/* LED1\u5f15\u811a *\/\n    gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP;            \/* \u63a8\u633d\u8f93\u51fa *\/\n    gpio_init_struct.Pull = GPIO_PULLUP;                    \/* \u4e0a\u62c9 *\/\n    gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH;          \/* \u9ad8\u901f *\/\n    HAL_GPIO_Init(LED1_GPIO_PORT, &amp;gpio_init_struct);       \/* \u521d\u59cb\u5316LED1\u5f15\u811a *\/\n\n    gpio_init_struct.Pin = LED2_GPIO_PIN;                   \/* LED2\u5f15\u811a *\/\n    HAL_GPIO_Init(LED2_GPIO_PORT, &amp;gpio_init_struct);       \/* \u521d\u59cb\u5316LED2\u5f15\u811a *\/\n    \n    gpio_init_struct.Pin = LED3_GPIO_PIN;                   \/* LED3\u5f15\u811a *\/\n    HAL_GPIO_Init(LED3_GPIO_PORT, &amp;gpio_init_struct);       \/* \u521d\u59cb\u5316LED3\u5f15\u811a *\/\n\n    LED1(0);                                                \/* \u5173\u95ed LED1 *\/\n    LED2(0);                                                \/* \u5173\u95ed LED2 *\/\n    LED3(0);                                                \/* \u5173\u95ed LED3 *\/\n}<\/code><\/pre>\n<p>LED \u7684 .h\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"c\">#ifndef _LED_H\n#define _LED_H\n#include &quot;sys.h&quot;\n\n\n\/******************************************************************************************\/\n\/* \u5f15\u811a \u5b9a\u4e49 *\/\n\n#define LED1_GPIO_PORT                  GPIOA\n#define LED1_GPIO_PIN                   GPIO_PIN_5\n#define LED1_GPIO_CLK_ENABLE()          do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0)             \/* PA\u53e3\u65f6\u949f\u4f7f\u80fd *\/\n\n#define LED2_GPIO_PORT                  GPIOA\n#define LED2_GPIO_PIN                   GPIO_PIN_6\n#define LED2_GPIO_CLK_ENABLE()          do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0)             \/* PA\u53e3\u65f6\u949f\u4f7f\u80fd *\/\n\n#define LED3_GPIO_PORT                  GPIOA\n#define LED3_GPIO_PIN                   GPIO_PIN_7\n#define LED3_GPIO_CLK_ENABLE()          do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0)             \/* PA\u53e3\u65f6\u949f\u4f7f\u80fd *\/\n\n\/******************************************************************************************\/\n\/* LED\u7aef\u53e3\u5b9a\u4e49 *\/\n#define LED1(x)   do{ x ? \/\n                      HAL_GPIO_WritePin(LED1_GPIO_PORT, LED1_GPIO_PIN, GPIO_PIN_SET) : \/\n                      HAL_GPIO_WritePin(LED1_GPIO_PORT, LED1_GPIO_PIN, GPIO_PIN_RESET); \/\n                  }while(0)\n\n#define LED2(x)   do{ x ? \/\n                      HAL_GPIO_WritePin(LED2_GPIO_PORT, LED2_GPIO_PIN, GPIO_PIN_SET) : \/\n                      HAL_GPIO_WritePin(LED2_GPIO_PORT, LED2_GPIO_PIN, GPIO_PIN_RESET); \/\n                  }while(0)\n\n#define LED3(x)   do{ x ? \/\n                      HAL_GPIO_WritePin(LED3_GPIO_PORT, LED3_GPIO_PIN, GPIO_PIN_SET) : \/\n                      HAL_GPIO_WritePin(LED3_GPIO_PORT, LED3_GPIO_PIN, GPIO_PIN_RESET); \/\n                  }while(0)\n\n\/* LED\u53d6\u53cd\u5b9a\u4e49 *\/\n#define LED1_TOGGLE()   do{ HAL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_GPIO_PIN); }while(0)        \/* \u7ffb\u8f6cLED1 *\/\n#define LED2_TOGGLE()   do{ HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_GPIO_PIN); }while(0)        \/* \u7ffb\u8f6cLED2 *\/\n#define LED3_TOGGLE()   do{ HAL_GPIO_TogglePin(LED3_GPIO_PORT, LED3_GPIO_PIN); }while(0)        \/* \u7ffb\u8f6cLED3 *\/\n\n\/******************************************************************************************\/\n\/* \u5916\u90e8\u63a5\u53e3\u51fd\u6570*\/\nvoid led_init(void);                                                                            \/* LED\u521d\u59cb\u5316 *\/\n\n#endif<\/code><\/pre>\n<h3>5.4 HC-SR501\u521d\u59cb\u5316<\/h3>\n<p>\u4ee3\u7801\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u521d\u59cb\u5316\u4e00\u4e0b\u8f93\u51fa\u5f15\u811a\uff0cPA4\u3002<\/p>\n<p>\u6211\u4eec\u91c7\u7528\u4e2d\u65ad\u7684\u65b9\u5f0f\u70b9\u706f\uff0c\u9700\u8981\u521d\u59cb\u5316\u548c\u4f7f\u80fd\u4e00\u4e0b EXTI\u3002<\/p>\n<pre><code class=\"c\">void hs_gpio_init(void)\n{\n    GPIO_InitTypeDef GPIO_InitStruct = {0};\n\n    \/* GPIO Ports Clock Enable *\/\n    __HAL_RCC_GPIOA_CLK_ENABLE();\n\n    \/*Configure GPIO pins : PA4 *\/\n    GPIO_InitStruct.Pin = GPIO_PIN_4;\n    GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;             \/\/\u4e2d\u65ad\u4e0a\u5347\u6cbf\n    GPIO_InitStruct.Pull = GPIO_NOPULL;                     \/\/\u65e0\u7535\u963b\n    HAL_GPIO_Init(GPIOA, &amp;GPIO_InitStruct);\n\n    \/* EXTI interrupt init*\/\n    HAL_NVIC_SetPriority(EXTI4_IRQn, 2, 0);                 \/\/\u62a2\u53602\uff0c\u5b50\u4f18\u5148\u7ea70\n    HAL_NVIC_EnableIRQ(EXTI4_IRQn);\n}<\/code><\/pre>\n<h3>5.5 \u4e2d\u65ad\u670d\u52a1\u51fd\u6570<\/h3>\n<p>\u8bbe\u8ba1\u4e2d\u65ad\u670d\u52a1\u51fd\u6570\uff0cPA4 \u68c0\u6d4b\u5230\u4e0a\u5347\u6cbf\uff0c\u9ad8\u7535\u5e73\uff0c\u300chsflag\u300d\u7f6e1\u3002<\/p>\n<pre><code class=\"c\">uint16_t get_hsflag(void)\n{\n    return hsflag;\n}\n\nvoid set_hsflag(uint16_t value)\n{\n    hsflag = value;\n}\n\nvoid EXTI4_IRQHandler(void)\n{\n    HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);         \/* \u8c03\u7528\u4e2d\u65ad\u5904\u7406\u516c\u7528\u51fd\u6570 \u6e05\u9664\u4e2d\u65ad\u7ebf \u7684\u4e2d\u65ad\u6807\u5fd7\u4f4d *\/\n    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_4);         \/* HAL\u5e93\u9ed8\u8ba4\u5148\u6e05\u4e2d\u65ad\u518d\u5904\u7406\u56de\u8c03\uff0c\u9000\u51fa\u65f6\u518d\u6e05\u4e00\u6b21\u4e2d\u65ad\uff0c\u907f\u514d\u6309\u952e\u6296\u52a8\u8bef\u89e6\u53d1 *\/\n}\n\nvoid HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)\n{\n    switch(GPIO_Pin)\n    {\n        case GPIO_PIN_4:\n        if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_4) ==  GPIO_PIN_SET)\n        {\n            hsflag = 1;\n        }\n        break;\n    }\n}<\/code><\/pre>\n<h3>5.6 \u4e3b\u51fd\u6570<\/h3>\n<p>\u4e3b\u51fd\u6570\u5982\u4e0b\uff1a<\/p>\n<p>\u4f9d\u636e\u300chsflag\u300d\uff0c\u4e3a0\u65f6\u8868\u793a\u65e0\u4eba\u7ecf\u8fc7\uff0c\u7ea2\u706f\u706d\uff1b\u4e3a1\u65f6\u8868\u793a\u6709\u4eba\u7ecf\u8fc7\uff0c\u7ea2\u706f\u4eae\u3002<\/p>\n<pre><code class=\"c\">int main(void)\n{\n    HAL_Init();                         \/* \u521d\u59cb\u5316HAL\u5e93 *\/\n    sys_stm32_clock_init(RCC_PLL_MUL9); \/* \u8bbe\u7f6e\u65f6\u949f, 72Mhz *\/\n    delay_init(72);                     \/* \u5ef6\u65f6\u521d\u59cb\u5316 *\/\n    led_init();                         \/* LED\u521d\u59cb\u5316 *\/\n    hs_gpio_init();                     \/* HC-SR501\u521d\u59cb\u5316 *\/\n\n    while(1)\n    {\n        if (get_hsflag())               \/\/\u6709\u4eba\u7ecf\u8fc7\u65f6\uff0c\u4eae\u706f1\u79d2\n        {\n            LED1(1);\n            delay_ms(1000);\n            set_hsflag(0);\n        }else{                          \/\/\u6709\u4eba\u7ecf\u8fc7\u65f6\uff0c\u706f\u706d\n            LED1(0);\n        }\n    }\n}<\/code><\/pre>\n<h3>5.7 \u6548\u679c\u5c55\u793a<\/h3>\n<p>HC-SR501 \u611f\u53d7\u5230\u4eba\u4f53\uff0c\u7ea2\u706f\u4eae\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"535\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdftvO\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>6. \u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u6df1\u5165\u4e86\u89e3 HC-SR501 \u7684\u5de5\u4f5c\u539f\u7406\u548c\u7279\u70b9\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u5730\u53d1\u6398\u5176\u6f5c\u529b\uff0c\u4e3a\u667a\u80fd\u5316\u548c\u81ea\u52a8\u5316\u7684\u672a\u6765\u53d1\u5c55\u5960\u5b9a\u575a\u5b9e\u57fa\u7840\u3002\u65e0\u8bba\u662f\u6784\u5efa\u667a\u80fd\u5bb6\u5c45\u7cfb\u7edf\u3001\u8bbe\u8ba1\u5b89\u5168\u8b66\u62a5\u7cfb\u7edf\u8fd8\u662f\u5f00\u53d1\u81ea\u52a8\u63a7\u5236\u8bbe\u5907\uff0cHC-SR501 \u90fd\u662f\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n<h2>\u5e0c\u671b\u672c\u6587\u80fd\u591f\u4e3a\u4f60\u63d0\u4f9b\u5168\u9762\u800c\u6e05\u6670\u7684\u6307\u5bfc\uff0c\u8ba9\u4f60\u8f7b\u677e\u638c\u63e1 HC-SR501 \u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\uff0c\u5e76\u5c06\u5176\u5e94\u7528\u4e8e\u4f60\u7684\u521b\u610f\u9879\u76ee\u4e2d\u3002\u611f\u8c22\u5404\u4f4d\u770b\u5b98\uff0c peace and love\uff01<\/h2>\n<p><strong>\u53e6\u5916\uff0c\u60f3\u8fdb\u5927\u5382\u7684\u540c\u5b66\uff0c\u4e00\u5b9a\u8981\u597d\u597d\u5b66\u7b97\u6cd5\uff0c\u8fd9\u662f\u9762\u8bd5\u5fc5\u5907\u7684\u3002\u8fd9\u91cc\u51c6\u5907\u4e86\u4e00\u4efd BAT \u5927\u4f6c\u603b\u7ed3\u7684 LeetCode \u5237\u9898\u5b9d\u5178\uff0c\u5f88\u591a\u4eba\u9760\u5b83\u4eec\u8fdb\u4e86\u5927\u5382\u3002<\/strong><\/p>\n<p><img decoding=\"async\" width=\"286\" height=\"83\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdaCCY\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=ls6PY9OczuTehSVmwqKmyA%3D%3D.6ClzVRbv%2Bj6Jr3t38z5zX4tqyNr%2B%2B98YuePKfGni%2BxrK%2BwRgSpamd8JXbO%2BolWoF\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u5237\u9898 | LeetCode\u7b97\u6cd5\u5237\u9898\u795e\u5668\uff0c\u770b\u5b8c BAT \u968f\u4f60\u6311\uff01<\/a><\/p>\n<h3>\u6709\u6536\u83b7\uff1f\u5e0c\u671b\u8001\u94c1\u4eec\u6765\u4e2a\u4e09\u8fde\u51fb\uff0c\u7ed9\u66f4\u591a\u7684\u4eba\u770b\u5230\u8fd9\u7bc7\u6587\u7ae0<\/h3>\n<p><strong>\u63a8\u8350\u9605\u8bfb\uff1a<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=9Zy1yPA%2BOcyIe2hh2019gg%3D%3D.tLBXAO%2B3nl%2BIX%2FvtsHP8MzBDs1mCv4ZBUhZtafn1u57hR4SGxb%2BX45lln7WSsS1b\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u7f16\u7a0b\u8d44\u6599\u5927\u5168<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=b42Io4xlnGpwWGK%2Fe4WoVQ%3D%3D.ee83h%2F%2FhN4RRQSz0hPhdR6Tz2qWK1q2nmQa9TxsszDIdNT3DmQ5nUjdWhrbb%2FYs6\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u8f6f\u4ef6\u8d44\u6e90<\/a><\/li>\n<\/ul>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u535a\u5ba2\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=teJPP2TdYGXsExpjY04TYw%3D%3D.%2FrSxFkXb7Q0phbjLMhxIUvob7Piir701NI%2Bb0m1O5Xk%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u826f\u8bb8\u5d4c\u5165\u5f0f\u6559\u7a0b\u7f51<\/a>\uff0c\u6ee1\u6ee1\u90fd\u662f\u5e72\u8d27\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000045595027\">https:\/\/segmentfault.com\/a\/1190000045595027<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740\u81ea\u52a8\u5316\u548c\u667a\u80fd\u5316\u6280\u672f\u7684\u53d1\u5c55\uff0c\u4eba\u4f53\u7ea2\u5916\u611f\u5e94\u6a21\u5757\u5728\u8bb8\u591a\u9886\u57df\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\uff0c\u6bd4\u5982\u5b89\u9632\u7cfb\u7edf\u3001\u81ea\u52a8\u7167\u660e\u548c\u81ea\u52a8\u95e8\u3002 HC [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020465","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020465"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020465\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}