{"id":83,"date":"2026-02-27T00:40:07","date_gmt":"2026-02-26T16:40:07","guid":{"rendered":"https:\/\/xlweb.icu\/?p=83"},"modified":"2026-04-22T21:54:37","modified_gmt":"2026-04-22T13:54:37","slug":"pcf8591%e7%a8%8b%e5%ba%8f%e8%ae%be%e8%ae%a1","status":"publish","type":"post","link":"https:\/\/xlweb.icu\/index.php\/2026\/02\/27\/pcf8591%e7%a8%8b%e5%ba%8f%e8%ae%be%e8%ae%a1\/","title":{"rendered":"PCF8591\u7a0b\u5e8f\u8bbe\u8ba1"},"content":{"rendered":"\n<p class=\"has-vivid-green-cyan-color has-text-color has-link-color wp-elements-1f6dd509c16c07d23adb876a80d8abf5 wp-block-paragraph\"><strong>\u901a\u8fc7\u672c\u7a0b\u5e8f\u8bbe\u8ba1\uff0c\u5bf9IIC\u65f6\u5e8f\u6709\u4e86\u66f4\u6df1\u523b\u7684\u7406\u89e3<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;STC15F2K60S2.H&gt;\n#include \"INit.h\"\n#include \"LED.h\"\n#include \"smg.h\"\n#include \"Key.h\"\n#include \"iic.h\"\nunsigned char key_slow_down;\nunsigned char key_old,key_val,key_down,key_up;\nunsigned int smg_slow_down;\nunsigned char smg_pos;\nunsigned char smg_buf&#91;8] = {11,11,11,11,11,11,11,11};\nunsigned char smg_point&#91;8] = {0,0,0,0,0,0,0,0};\nunsigned char led_buf&#91;8] = {0,0,0,0,0,0,0,0};\nfloat Voltage,Voltage_output;\n\nbit smg_mode;\nbit smg_flag = 1;\nbit output_mode;\n\nvoid Key_Function()\n{\n\tif(key_slow_down)return;\n\tkey_slow_down = 1;\n\tkey_val = Key_Get();\n\tkey_down =  key_val &amp; (key_val ^ key_old);\n\tkey_up = ~key_val &amp; (key_val ^ key_old);\n\tkey_old = key_val;\n\t\n\tif(key_down==4){\n\t\tsmg_mode ^=1;\n\t}\n\tif(smg_mode==1){\n\t\tif(key_down==5)output_mode ^=1;\n\t}\n\tif(key_down==7){\n\t\tsmg_flag ^=1;\n\t}\n\t\n}\nvoid smg_Function()\n{\n\tif(smg_slow_down)return;\n\tsmg_slow_down = 1;\n\tVoltage = Ad_Read(0x43)\/51.0;\n\t\n\tif(smg_mode ==0)\n\t{\n\t\tsmg_buf&#91;0]= 12;\n\t\tsmg_buf&#91;5]= (unsigned int)(Voltage *100) \/100 %10;\n\t\tsmg_buf&#91;6]= (unsigned int)(Voltage *100) \/10  %10;\n\t\tsmg_buf&#91;7]= (unsigned int)(Voltage *100)     %10;\n\t\tsmg_point&#91;5] = 1;\n\t}\n\telse\n\t{\n\t\tif(output_mode==0){\n\t\t\tVoltage_output=2.0;\n\t\t}\n\t\telse{\n\t\t\tVoltage_output = Voltage;\n\t\t}\n\t\tsmg_buf&#91;0]= 13;\n\t\tsmg_buf&#91;5]= (unsigned int)(Voltage_output *100) \/100 %10;\n\t\tsmg_buf&#91;6]= (unsigned int)(Voltage_output *100) \/10  %10;\n\t\tsmg_buf&#91;7]= (unsigned int)(Voltage_output *100)     %10;\n\t\tsmg_point&#91;5] = 1;\n\t}\n\t\n}\n\nvoid LED_Function()\n{\n\t\/\/Da_Write(Voltage_output*51);\n\tunsigned char i=0;\n\tfor(i=0;i&lt;2;i++)\n\t{\n\t\tled_buf&#91;i] = (i == smg_mode);\n\t\t\n\t}\n\tif(Voltage&lt;1.5 || Voltage&gt;=2.5 &amp;&amp; Voltage&lt;3.5){\n\t\tled_buf&#91;2] = 0;\n\t}\n\telse{\n\t\tled_buf&#91;2] = 1;\n\t}\n\tled_buf&#91;3] = output_mode;\n}\nvoid Timer0_Init(void)\t\t\/\/1\u6beb\u79d2@12.000MHz\n{\n\tAUXR &amp;= 0x7F;\t\t\t\/\/\u5b9a\u65f6\u5668\u65f6\u949f12T\u6a21\u5f0f\n\tTMOD &amp;= 0xF0;\t\t\t\/\/\u8bbe\u7f6e\u5b9a\u65f6\u5668\u6a21\u5f0f\n\tTL0 = 0x18;\t\t\t\t\/\/\u8bbe\u7f6e\u5b9a\u65f6\u521d\u59cb\u503c\n\tTH0 = 0xFC;\t\t\t\t\/\/\u8bbe\u7f6e\u5b9a\u65f6\u521d\u59cb\u503c\n\tTF0 = 0;\t\t\t\t\/\/\u6e05\u9664TF0\u6807\u5fd7\n\tTR0 = 1;\t\t\t\t\/\/\u5b9a\u65f6\u56680\u5f00\u59cb\u8ba1\u65f6\n\t\n\tET0 = 1;\n\tEA=1;\n}\n\nvoid Timer0_Function() interrupt 1\n{\n\tif(++key_slow_down==25)key_slow_down=0;\n\tif(++smg_slow_down==50)smg_slow_down=0;\n\tif(++smg_pos==8)smg_pos = 0;\n\tif(smg_flag==1){\n\t\tSmg_Set(smg_pos,smg_buf&#91;smg_pos],smg_point&#91;smg_pos]);\n\t}\n\telse{\n\t\tSmg_Set(smg_pos,11,0);\n\t}\n\t\n\tLED_Set(smg_pos,led_buf&#91;smg_pos]);\n}\nvoid main()\n{\n\tSystem_Init();\n\tTimer0_Init();\n\twhile(1)\n\t{\n\t\tKey_Function();\n\t\tsmg_Function();\n\t\tLED_Function();\n\t}\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u672c\u7a0b\u5e8f\u8bbe\u8ba1\uff0c\u5bf9IIC\u65f6\u5e8f\u6709\u4e86\u66f4\u6df1\u523b\u7684\u7406\u89e3<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-article"],"_links":{"self":[{"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":2,"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":88,"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/posts\/83\/revisions\/88"}],"wp:attachment":[{"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlweb.icu\/index.php\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}