{"id":309848,"date":"2020-09-13T03:00:16","date_gmt":"2020-09-13T03:00:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=309848"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=309848","title":{"rendered":"\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438: STM32 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/518878\/\">\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f:<br \/>  <a href=\"https:\/\/m.habr.com\/ru\/post\/518832\/\">\u041e\u0447\u0435\u0440\u0435\u0434\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f: STM32 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445<\/a><\/p>\n<h3>\u0418 \u043a\u0430\u043a \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f?<\/h3>\n<p>  \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0440\u0442\u0430\u043c\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b\u0438. \u0418 \u0447\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435? \u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441?<br \/>  \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u043e\u043f\u0440\u043e\u0441 \u043a\u043d\u043e\u043f\u043e\u043a:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/nr\/ti\/-d\/nrti-dk7bu2puph-pdtha29krvg.jpeg\"><br \/>  \u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u0432 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a  <\/p>\n<pre><code class=\"cpp\">int GetKey() {   volatile uint32_t* addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_IDR);   uint32_t ret_val = *addr;   return ret_val &amp; 0x0F; }<\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a>\u041d\u043e, \u0435\u0441\u043b\u0438 \u0432 \u0441\u0445\u0435\u043c\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u0442\u044b, \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u043d\u044b\u0435 \u043a \u043a\u043d\u043e\u043f\u043a\u0430\u043c, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044f\u0442\u044c \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u043f\u0440\u043e\u0441\u0430. \u0418 \u0442\u0430\u043a \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u042d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u043e\u0431\u043d\u043e. \u0425\u043e\u0447\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c, \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<br \/>  \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0434 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:  <\/p>\n<pre><code class=\"cpp\">int GetKey(Pin* p0, Pin* p1, Pin* p2, Pin* p3) {   int ret_val = p0-&gt;Get() + (p1-&gt;Get() &lt;&lt; 1) + (p2-&gt;Get() &lt;&lt; 2) + (p3-&gt;Get() &lt;&lt; 3);   return ret_val; }<\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0440\u0442\u044b \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e:  <\/p>\n<pre><code class=\"cpp\">... using namespace STM32F1xx; Pin key0('a', 0); Pin key1('a', 1); Pin key2('a', 2); Pin key3('a', 3); ... int main() {   key0.ModeInput();   key1.ModeInput();   key2.ModeInput();   key3.ModeInput();   int key_code = GetKey(&amp;key0, &amp;key1, &amp;key2, &amp;key3); ...   return 0; } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0410 \u0433\u0434\u0435 \u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b?<\/h3>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0437\u0430\u043a\u043e\u043d\u0438\u043b\u0438\u0441\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0441\u0435\u0440\u0438\u0438 f10x, \u043d\u043e \u0435\u0441\u0442\u044c \u043a\u0443\u0447\u0430 f030. \u041f\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0432\u044b\u0432\u043e\u0434\u043e\u0432 \u0445\u0432\u0430\u0442\u0430\u0435\u0442, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0434\u043e \u0445\u0435\u0434\u0435\u0440 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GetKey \u0438\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f\u2026 #ifdef. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u043f\u0438\u0441\u0442\u044c \u0442\u0438\u043f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 (\u0447\u0442\u043e \u0442\u043e \u0442\u0438\u043f\u0430 #define STM32F030) \u0438 \u043d\u0430\u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u043a\u0443\u0447\u0443 \u0434\u0435\u0444\u0430\u0439\u043d\u043e\u0432. \u041d\u0435\u0442, \u043d\u0435 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u044f\u0437\u044b\u043a\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0447\u0442\u043e \u0431\u044b \u043f\u0443\u0442\u0430\u0442\u044c\u0441\u044f \u0432 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u0445!<br \/>  \u041f\u043e\u0439\u0434\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u043e\u0440\u043e\u0433\u043e\u0439. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u043c \u043f\u043e \u0436\u0438\u0437\u043d\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0440\u0442\u0430\u043c\u0438:  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">iPin.h<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once  class iPin { public:   virtual void ModeInput()              = 0;   virtual void ModeAnalogInput()        = 0;   virtual void ModeInputPulled()        = 0;   virtual void ModeOutput()             = 0;   virtual void ModeOutputOpenDrain()    = 0;    virtual void Set(bool st) = 0;   virtual bool Get() = 0;    virtual void Reverse() { Set(!Get());}    void On()              { Set(true);  }   void Off()             { Set(false); } };<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  (\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0440\u0430\u0432\u043d\u0435\u043d\u044b 0, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435!)<br \/>  \u0438 \u0431\u0443\u0434\u0435\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 Pin:  <\/p>\n<pre><code class=\"cpp\">... #include &quot;iPin.h&quot; ... class Pin : public iPin ...<\/code><\/pre>\n<p>  \u0442\u043e\u0433\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f GetKey \u0447\u0443\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f:  <\/p>\n<pre><code class=\"cpp\">int GetKey(iPin* p0, iPin* p1, iPin* p2, iPin* p3) {   int ret_val = p0-&gt;Get() + (p1-&gt;Get() &lt;&lt; 1) + (p2-&gt;Get() &lt;&lt; 2) + (p3-&gt;Get() &lt;&lt; 3);   return ret_val; } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043d\u0438\u043f\u043e\u0447\u0435\u043c! \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0448\u0438\u043d\u043d\u044b\u0439 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u0435\u043b\u044c, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043f\u043e SPI \u0438\u043b\u0438 I2C. \u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445. <\/p>\n<h3>\u0418 \u0447\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h3>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u0434\u043e \u043e\u0444\u043e\u0440\u043c\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u043c. \u041d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/518878\/\"> https:\/\/habr.com\/ru\/post\/518878\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/518878\/\">\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f:<br \/>  <a href=\"https:\/\/m.habr.com\/ru\/post\/518832\/\">\u041e\u0447\u0435\u0440\u0435\u0434\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f: STM32 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445<\/a><\/p>\n<h3>\u0418 \u043a\u0430\u043a \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f?<\/h3>\n<p>  \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0440\u0442\u0430\u043c\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b\u0438. \u0418 \u0447\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435? \u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441?<br \/>  \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u043e\u043f\u0440\u043e\u0441 \u043a\u043d\u043e\u043f\u043e\u043a:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/nr\/ti\/-d\/nrti-dk7bu2puph-pdtha29krvg.jpeg\"><br \/>  \u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u0432 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a  <\/p>\n<pre><code class=\"cpp\">int GetKey() {   volatile uint32_t* addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_IDR);   uint32_t ret_val = *addr;   return ret_val &amp; 0x0F; }<\/code><\/pre>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-309848","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309848"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309848\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}