{"id":1109,"date":"2023-09-07T22:28:20","date_gmt":"2023-09-07T14:28:20","guid":{"rendered":"https:\/\/www.alextwl.idv.tw\/memo\/?p=1109"},"modified":"2023-09-09T17:30:33","modified_gmt":"2023-09-09T09:30:33","slug":"pomodoro-timer-lcd1602-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.alextwl.idv.tw\/memo\/2023\/09\/pomodoro-timer-lcd1602-raspberry-pi\/","title":{"rendered":"\u88fd\u4f5c LCD \u756a\u8304\u9418\uff1a\u7528 Raspberry Pi GPIO \u63a7\u5236 16&#215;2 LCD \u986f\u793a\u5668"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/pomodoro_lcd.gif\" alt=\"\" width=\"480\" height=\"480\" class=\"alignnone size-full wp-image-1110\" \/><\/p>\n<p>\u6700\u8fd1\u770b\u7684\u66f8\u53cd\u8986\u63d0\u5230\u756a\u8304\u5de5\u4f5c\u6cd5\uff0c\u60f3\u8a66\u8a66\u770b\uff0c\u65bc\u662f\u5c31\u7528\u624b\u4e0a\u7684\u6a39\u8393\u6d3e\u8207\u96f6\u4ef6\u88fd\u4f5c\u4e86\ud83c\udf45 LCD \u756a\u8304\u9418\u4f86\u7528\uff01<\/p>\n<p>\u7528 Python \u5beb\u4e86\u4e00\u96bb <a href=\"https:\/\/github.com\/alextwl\/lcd1602gpio\/blob\/main\/examples\/pomodoro_timer.py\">pomodoro_timer.py<\/a> \u4f86\u8b80\u79d2\uff0c\u4e5f\u70ba\u4e86\u628a\u5b57\u5370\u5230 16&#215;2 \u7684\u6db2\u6676\u986f\u793a\u5668\u4e0a\uff0c\u5beb\u4e86 <a href=\"https:\/\/pypi.org\/project\/lcd1602gpio\/\">lcd1602gpio<\/a> \u6a21\u7d44\u5f9e Raspberry Pi 3 Model B \u7684 GPIO \u64cd\u4f5c\u5b83\u3002<br \/>\n<!--more--><\/p>\n<p>\u756a\u8304\u9418\u7a0b\u5f0f\u7684\u90e8\u4efd\u6bd4\u8f03\u55ae\u7d14\uff0c\u7528\u8ff4\u5708\u53cd\u8986\u505a 25 \u5206\u9418 + 5 \u5206\u9418\u7684\u8b80\u79d2\u3002\u8003\u616e\u5230 Raspberry Pi \u6c92\u6709\u5167\u5efa\u53ef\u9760\u7684\u7cfb\u7d71\u6642\u9418\uff0c\u65bc\u662f\u7528 Python \u7684 <a href=\"https:\/\/docs.python.org\/3\/library\/time.html#time.monotonic\"><code>time.monotonic()<\/code><\/a> \u7b97\u5dee\u503c\uff0c\u505a\u51fa\u6bcf\u79d2\u9418\u90fd\u80fd\u8f38\u51fa\u4e00\u6b21\u5b57\u4e32\u5230 LCD \u7684\u6548\u679c\u3002<\/p>\n<p>\u64cd\u4f5c LCD \u7684\u90e8\u4efd\u96d6\u7136\u7db2\u8def\u4e0a\u5df2\u7d93\u6709\u8a31\u591a\u7bc4\u4f8b\u53ef\u770b\uff0c\u4f46\u5be6\u969b\u6bd4\u60f3\u50cf\u4e2d\u9ebb\u7169\u8a31\u591a\u3002\u624b\u4e0a\u6709\u4e00\u9846\u5341\u5e7e\u5e74\u524d\u5357\u4e9e\u5851\u81a0\u51fa\u7684 16&#215;2 LCD \u6a21\u7d44\uff1a<\/p>\n<p><a href=\"https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/4d986ff4-437d-4c1f-8e5a-d712ebc9470b.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/4d986ff4-437d-4c1f-8e5a-d712ebc9470b-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" class=\"alignnone size-medium wp-image-1112\" srcset=\"https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/4d986ff4-437d-4c1f-8e5a-d712ebc9470b-300x300.jpg 300w, https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/4d986ff4-437d-4c1f-8e5a-d712ebc9470b-1024x1024.jpg 1024w, https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/4d986ff4-437d-4c1f-8e5a-d712ebc9470b-150x150.jpg 150w, https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/4d986ff4-437d-4c1f-8e5a-d712ebc9470b-768x768.jpg 768w, https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/4d986ff4-437d-4c1f-8e5a-d712ebc9470b-1536x1536.jpg 1536w, https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/4d986ff4-437d-4c1f-8e5a-d712ebc9470b.jpg 2048w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u6c92\u6709\u65b9\u4fbf\u7684 I\u00b2C \u4ecb\u9762\u53ef\u4ee5\u7528\uff0c\u53ea\u597d\u81ea\u5df1\u63a5\u7dda\uff0c\u5728 <a href=\"https:\/\/github.com\/alextwl\/lcd1602gpio#examples\">lcd1602gpio README \u7684 Examples<\/a> \u6709\u6574\u7406\u6211\u4f7f\u7528\u7684\u8173\u4f4d\uff0c\u5149\u662f\u8173\u4f4d\u7684\u7528\u6cd5\u8ddf\u9806\u5e8f\u5c31\u8ddf\u5225\u4eba\u5bb6\u4e0d\u4e00\u6a23\u3002<\/p>\n<ul>\n<li>\u9019\u500b LCD \u6a21\u7d44\u6709\u80cc\u5149\uff0c\u4f46\u5c08\u7528\u8173\u4f4d\u662f\u653e\u5728 LCD \u4e3b\u6a21\u7d44\u7684\u63a5\u5730\u7dda(\u540d\u7fa9\u4e0a\u7684\u7b2c\u4e00\u500b\u8173\u4f4d)\u65c1\u908a\uff0c\u4e0d\u662f\u50cf\u5b83\u5ee0\u653e\u5728 Data bus \u4e4b\u5f8c\u3002<\/li>\n<li>\u8b93\u80cc\u5149\u7684\u967d\u6975\u8ddf LCD \u5f9e\u9eb5\u5305\u677f\u5403\u4e00\u6a23\u7684 5V \u5c31\u4eae\u4e0d\u8d77\u4f86\uff0c\u63a5\u53e6\u4e00\u96bb 5V \u7d66\u80cc\u5149\u624d\u4eae\u8d77\u4f86\uff0c\u7136\u5f8c\u60f3\u8aaa\u4e32\u96fb\u963b\u505a\u9ede\u4fdd\u8b77\u537b\u53c8\u4eae\u4e0d\u8d77\u4f86\uff0c\u65bc\u662f\u5c31\u6c92\u4e32\u4e86\u76f4\u4e0a +5V\u3002<\/li>\n<li>Contrast \u76f4\u63a5\u63a5\u5730\uff0c\u56e0\u70ba\u5c0d\u6bd4\u5df2\u7d93\u4f4e\u5230\u6709\u4e9b\u5b57\u90fd\u5feb\u770b\u4e0d\u5230\uff0c\u65bc\u662f\u4e5f\u6c92\u6709\u4e32\u53ef\u8b8a\u96fb\u963b\u53bb\u8abf\u3002<\/li>\n<\/ul>\n<p>\u63a5\u597d\u7684\u96fb\u8def\u9577\u5f97\u50cf\u9019\u6a23\uff1a(Data bus DB0 ~ DB7 \u516b\u96bb\u8173\u5168\u4e0a)<\/p>\n<p><a href=\"https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/LCD1602_RPi_bb.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/LCD1602_RPi_bb-1008x1024.png\" alt=\"\" width=\"640\" height=\"650\" class=\"alignnone size-large wp-image-1111\" srcset=\"https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/LCD1602_RPi_bb-1008x1024.png 1008w, https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/LCD1602_RPi_bb-295x300.png 295w, https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/LCD1602_RPi_bb-768x780.png 768w, https:\/\/www.alextwl.idv.tw\/memo\/media\/2023\/09\/LCD1602_RPi_bb.png 1365w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>\u7531\u65bc\u76ee\u6a19\u53ea\u60f3\u5148\u5728 LCD \u986f\u793a\u4e00\u4e9b\u5b57\uff0c\u53ea\u505a\u4e86\u5beb\u5165\u6307\u4ee4\u5230 LCD \u7684\u529f\u80fd\uff0c\u6240\u4ee5 R\/W \u8173\u4f4d\u76f4\u63a5\u63a5\u5730\uff0c\u6c92\u6709\u505a\u5f9e LCD \u8b80\u53d6\u8cc7\u6599\u7684\u529f\u80fd\uff0c\u52a0\u4e0a\u6c92\u53bb\u8b80 Busy Flag (BF) \u5c31\u628a delay \u62c9\u5f97\u5f88\u9577\u4ee5\u78ba\u4fdd LCD \u6709\u8db3\u5920\u6642\u9593\u8dd1\u5b8c\u6307\u4ee4\u3002<\/p>\n<p>\u904e\u7a0b\u4e2d\u70ba\u4e86\u641e\u61c2 LCD \u6307\u4ee4\u7684\u610f\u7fa9\uff0c\u627e\u5230\u4e86 <a href=\"https:\/\/cdn-shop.adafruit.com\/datasheets\/HD44780.pdf\">HD44780 \u63a7\u5236\u5668\u7684\u8aaa\u660e\u6587\u4ef6<\/a>\u5617\u8a66\u81ea\u5df1\u64cd\u4f5c\u770b\u770b\uff0c\u537b\u767c\u73fe\u88e1\u982d\u6709\u5f88\u591a\u8070\u660e\u7684\u8a2d\u8a08\u3002<\/p>\n<p>\u50cf\u662f\u5728\u521d\u59cb\u5316 LCD \u7684\u6642\u5019\uff0c\u6709\u4e9b\u4eba\u6703\u8aaa\u7e3d\u4e4b\u5148\u9001 <code>0x33 (0b00110011)<\/code> \u8ddf <code>0x32 (0b00110010)<\/code> \u5169\u7d44 instruction \u5230 data bus\uff0c\u4e4b\u5f8c\u518d\u505a\u4e00\u6b21 Function Set \u8a2d\u5b9a\u884c\u5217\u6578\u8207\u5b57\u578b\u3002\u521d\u59cb\u5316\u7684\u6307\u4ee4\u90fd\u662f\u5c6c\u65bc Function Set \u6307\u4ee4\uff0c\u4f46\u6703\u9700\u8981\u9001\u9019\u9ebc\u591a\u6b21\u662f\u6709\u610f\u7fa9\u7684\uff0c\u539f\u56e0\u5728\u65bc\u8a2d\u8a08\u96fb\u8def\u7684\u6211\u5011\u7121\u6cd5\u5f97\u77e5 LCD \u6a21\u7d44\u5728\u4efb\u4f55\u6642\u5019\u662f\u8655\u5728\u4f55\u7a2e\u6a21\u5f0f (8-bit \u6216 4-bit)\uff0c\u6bcf\u500b Enable cycle \u9001\u9032\u53bb\u7684\u8cc7\u6599\u3001LCD \u6703\u7576\u4f5c 1 cycle per instruction \u9084\u662f 2 cycles per instruction \u662f\u8aaa\u4e0d\u6e96\u7684\u3002\u65bc\u662f\u624d\u6709 <code>0x33 & 0x32<\/code> \u5169\u6307\u4ee4\uff0c\u5c0d 8-bit \u96fb\u8def\u4f86\u8aaa\u5c31\u662f 2 cycles \u9001\u5b8c\uff0c\u96d6\u7136\u6700\u5f8c\u5169\u4f4d\u4f4e\u4f4d\u5143\u4e0d\u4e00\u6a23\uff0c\u4f46\u56e0\u70ba\u662f Don&#8217;t care bits \u6240\u4ee5\u6703\u88ab LCD \u5ffd\u7565\uff0c\u4e0d\u7ba1 LCD \u662f\u8655\u5728 4-bit \u6216 8-bit \u6a21\u5f0f\u4e0b\uff0c\u6700\u5f8c\u5b8c\u6210\u521d\u59cb\u5316\u7684\u6642\u5019\u90fd\u6703\u662f 8-bit \u6a21\u5f0f\u3002\u9047\u5230 4-bit \u96fb\u8def\u7684\u8a71\uff0c\u9019\u5169\u500b\u6307\u4ee4\u6703\u4ee5 Nibble sending logic \u88ab\u62c6\u6210 4 cycles\uff0c\u539f\u672c\u6703\u88ab\u5ffd\u7565\u7684\u4f4e\u4f4d\u5143\u5c31\u53ef\u80fd\u88ab LCD \u7576\u6210\u9ad8\u4f4d\u5143\u6307\u4ee4\u5403\u9032\u53bb\uff0c\u4e0d\u7ba1 LCD \u662f\u8655\u5728 4-bit \u6216 8-bit \u6a21\u5f0f\u4e0b\uff0c\u6700\u5f8c\u5b8c\u6210\u521d\u59cb\u5316\u7684\u6642\u5019\u90fd\u6703\u9032\u5165 4-bit \u6a21\u5f0f\u3002\u50cf\u9019\u6a23\u7684\u8a2d\u8a08\u5be6\u5728\u5145\u6eff\u5de7\u601d\u3002<\/p>\n<p>\u6700\u5f8c\uff0c\u96d6\u7136\u5beb\u4e86\u9019\u9ebc\u591a\u90fd\u662f\u96c6\u4e2d\u5728 LCD \u7684\u8a71\u984c\u4e0a\uff0c\u4e5f\u8d81\u9019\u500b\u6a5f\u6703\u5c0d Raspberry Pi \u505a\u4e86\u6bd4\u8f03\u8a73\u7d30\u7684\u8a8d\u8b58\u3002\u9019\u6b21\u7528\u5230\u7684 LCD module \u525b\u597d\u53ea\u9700\u8981 GPIO \u505a\u9ad8\u4f4e\u96fb\u4f4d\u5dee\u5c31\u80fd\u64cd\u4f5c\uff0c\u82e5\u662f\u8981\u7528\u5230\u611f\u6e2c\u5668\u4e00\u985e\u7684\u985e\u6bd4\u5143\u4ef6\u5c31\u5f97\u6e96\u5099 ADC \u4e86(\u6216\u6539\u7528\u50cf\u662f Arduino \u80fd\u8b80\u985e\u6bd4\u7684\u63a7\u5236\u5668)\uff0c\u6211\u60f3 Raspberry Pi \u7684\u5f37\u9805\u5728\u8655\u7406\u6578\u4f4d\u8a0a\u865f\u3001\u62ff\u4f86\u67b6\u8a2d\u5c0f server\u3001\u4ee5\u53ca\u7528 HDMI \u8f38\u51fa\u756b\u9762\u505a\u96fb\u5b50\u770b\u677f\u4e4b\u985e\u7684\u61c9\u7528\u6bd4\u8f03\u5408\u9069\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u770b\u7684\u66f8\u53cd\u8986\u63d0\u5230\u756a\u8304\u5de5\u4f5c\u6cd5\uff0c\u60f3\u8a66\u8a66\u770b\uff0c\u65bc\u662f\u5c31\u7528\u624b\u4e0a\u7684\u6a39\u8393\u6d3e\u8207\u96f6\u4ef6\u88fd\u4f5c\u4e86\ud83c\udf45 LCD \u756a\u8304\u9418\u4f86\u7528\uff01 \u7528 Pyth [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[91,90,92,89],"class_list":["post-1109","post","type-post","status-publish","format-standard","hentry","category-1","tag-lcd1602","tag-pomodoro-timer","tag-python","tag-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/posts\/1109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/comments?post=1109"}],"version-history":[{"count":16,"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/posts\/1109\/revisions"}],"predecessor-version":[{"id":1131,"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/posts\/1109\/revisions\/1131"}],"wp:attachment":[{"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/media?parent=1109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/categories?post=1109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.alextwl.idv.tw\/memo\/wp-json\/wp\/v2\/tags?post=1109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}