Actions

Kamod BluePill: Difference between revisions

From Kamamilabs.com - Wiki

 
(One intermediate revision by the same user not shown)
Line 261: Line 261:
===== Test program =====
===== Test program =====
The simplified code of the test program is below, it can be compiled in the Arduino environment.
The simplified code of the test program is below, it can be compiled in the Arduino environment.
<syntaxhighlight lang="arduino">
#include <STM32RTC.h>


<code>
#define LED_PIN   PC13
<font color="#5e6d03">#include</font> <font color="#434f54">&lt;</font><b><font color="#d35400">STM32RTC</font></b><font color="#434f54">.</font><font color="#000000">h</font><font color="#434f54">&gt;</font>
#define SW_PIN   PA0
<br><br>
<font color="#5e6d03">#define</font> <font color="#000000">LED_PIN</font> &nbsp;&nbsp;<font color="#00979c">PC13</font><br>
<font color="#5e6d03">#define</font> <font color="#000000">SW_PIN</font> &nbsp;&nbsp;&nbsp;<font color="#00979c">PA0</font><br><br>


<font color="#00979c">int</font> <font color="#000000">message_period</font> <font color="#434f54">=</font> <font color="#000000">0</font><font color="#000000">;</font><br>
int message_period = 0;
<font color="#00979c">int</font> <font color="#000000">config_state</font> <font color="#434f54">=</font> <font color="#000000">0</font><font color="#000000">;</font><br>
int config_state = 0;
<font color="#00979c">int</font> <font color="#000000">ports_state</font> <font color="#434f54">=</font> <font color="#000000">0</font><font color="#000000">;</font><br>
int ports_state = 0;
<font color="#00979c">int</font> <font color="#000000">pindex</font> <font color="#434f54">=</font> <font color="#000000">0</font><font color="#000000">;</font><br><br>
int pindex = 0;


<b><font color="#d35400">STM32RTC</font></b><font color="#434f54">&amp;</font> <font color="#000000">rtc</font> <font color="#434f54">=</font> <b><font color="#d35400">STM32RTC</font></b><font color="#434f54">:</font><font color="#434f54">:</font><font color="#d35400">getInstance</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
STM32RTC& rtc = STM32RTC::getInstance();
<br><br>
<font color="#00979c">void</font> <font color="#5e6d03">setup</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#000000">{</font>
&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">begin</font><font color="#000000">(</font><font color="#000000">115200</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#000000">LED_PIN</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#000000">SW_PIN</font><font color="#434f54">,</font> <font color="#00979c">INPUT_PULLUP</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#000000">rtc</font><font color="#434f54">.</font><font color="#d35400">begin</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font> <font color="#434f54">&#47;&#47; initialize RTC 24H format</font>
<font color="#000000">}</font>


<font color="#434f54">&#47;&#47; the loop function runs over and over again forever</font><br>
void setup() {
<font color="#00979c">void</font> <font color="#5e6d03">loop</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#000000">{</font>
  Serial.begin(115200);
&nbsp;<font color="#434f54">&#47;&#47;digitalWrite(LED_PIN, HIGH);</font>
  pinMode(LED_PIN, OUTPUT);
&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#d35400">digitalRead</font><font color="#000000">(</font><font color="#000000">SW_PIN</font><font color="#000000">)</font> <font color="#434f54">==</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">{</font>
  pinMode(SW_PIN, INPUT_PULLUP);
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">ports_state</font><font color="#434f54">&amp;</font><font color="#000000">4</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">{</font>
  rtc.begin(); // initialize RTC 24H format
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">LED_PIN</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font> <font color="#5e6d03">else</font> <font color="#000000">{</font> &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">LED_PIN</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>


&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">config_state</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">{</font>
// the loop function runs over and over again forever
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">IO2input</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
void loop() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">config_state</font> <font color="#434f54">=</font> <font color="#000000">0</font><font color="#000000">;</font>
  //digitalWrite(LED_PIN, HIGH);
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
  if (digitalRead(SW_PIN) == HIGH){
    if ((ports_state&4) > 0){
      digitalWrite(LED_PIN, HIGH);    
    } else {   
      digitalWrite(LED_PIN, LOW);    
    }


&nbsp;<font color="#000000">}</font> <font color="#5e6d03">else</font> <font color="#000000">{</font>
    if (config_state > 0){
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">(</font><font color="#000000">ports_state</font><font color="#434f54">&amp;</font><font color="#000000">1</font><font color="#000000">)</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">{</font>
      IO2input();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">LED_PIN</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      config_state = 0;
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font> <font color="#5e6d03">else</font> <font color="#000000">{</font> &nbsp;&nbsp;&nbsp;
    }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">LED_PIN</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">config_state</font> <font color="#434f54">==</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">{</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">IO2output</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">config_state</font> <font color="#434f54">=</font> <font color="#000000">1</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>


  } else {
    if ((ports_state&1) > 0){
      digitalWrite(LED_PIN, HIGH);     
    } else {   
      digitalWrite(LED_PIN, LOW);     
    }
   
    if (config_state == 0){
      IO2output();
      config_state = 1;
    }


&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">config_state</font> <font color="#434f54">==</font> <font color="#000000">1</font><font color="#000000">)</font><font color="#000000">{</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">IO2low</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">IOwriteIndexed</font><font color="#000000">(</font><font color="#000000">pindex</font><font color="#434f54">,</font> <font color="#000000">1</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#000000">pindex</font><font color="#434f54">++</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">pindex</font> <font color="#434f54">&gt;</font> <font color="#000000">26</font><font color="#000000">)</font> <font color="#000000">pindex</font> <font color="#434f54">=</font> <font color="#000000">1</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#000000">}</font>
&nbsp;<font color="#000000">}</font>


&nbsp;<font color="#434f54">&#47;&#47; check if plugged into a host</font>
    if (config_state == 1){
&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">message_period</font> <font color="#434f54">&gt;=</font> <font color="#000000">11</font><font color="#000000">)</font><font color="#000000">{</font>
      IO2low();
&nbsp;&nbsp;&nbsp;<font color="#000000">message_period</font> <font color="#434f54">=</font> <font color="#000000">0</font><font color="#000000">;</font>
      IOwriteIndexed(pindex, 1);
&nbsp;&nbsp;&nbsp;
      pindex++;
&nbsp;&nbsp;&nbsp;<font color="#00979c">int</font> <font color="#000000">tmt</font> <font color="#434f54">=</font> <font color="#000000">rtc</font><font color="#434f54">.</font><font color="#d35400">getMinutes</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
      if (pindex > 26) pindex = 1;
&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">&#34;KAmod BluePill+ RTC=&#34;</font><font color="#000000">)</font><font color="#000000">;</font>
    }
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">tmt</font> <font color="#434f54">&lt;</font> <font color="#000000">10</font><font color="#000000">)</font> <b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">&#34;0&#34;</font><font color="#000000">)</font><font color="#000000">;</font>
  }
&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#000000">tmt</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;<font color="#000000">tmt</font> <font color="#434f54">=</font> <font color="#000000">rtc</font><font color="#434f54">.</font><font color="#d35400">getSeconds</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">&#34;:&#34;</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">tmt</font> <font color="#434f54">&lt;</font> <font color="#000000">10</font><font color="#000000">)</font> <b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">print</font><font color="#000000">(</font><font color="#005c5f">&#34;0&#34;</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">println</font><font color="#000000">(</font><font color="#000000">tmt</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#000000">}</font>
&nbsp;
&nbsp;<font color="#d35400">delay</font><font color="#000000">(</font><font color="#000000">200</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#000000">message_period</font><font color="#434f54">++</font><font color="#000000">;</font>
&nbsp;<font color="#000000">ports_state</font><font color="#434f54">++</font><font color="#000000">;</font>
<font color="#000000">}</font>


<font color="#00979c">void</font> <font color="#000000">IO2output</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">{</font>
  // check if plugged into a host
&nbsp;<font color="#434f54">&#47;&#47;pinMode(PA0, OUTPUT); &#47;&#47;switch</font>
  if (message_period >= 11){
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA1</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
    message_period = 0;
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA2</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
   
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA3</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
    int tmt = rtc.getMinutes();
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA4</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
    Serial.print("KAmod BluePill+ RTC=");
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA5</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
    if (tmt < 10) Serial.print("0");
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA6</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
    Serial.print(tmt);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA7</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
   
    tmt = rtc.getSeconds();
    Serial.print(":");
    if (tmt < 10) Serial.print("0");
    Serial.println(tmt);
  }
 
  delay(200);  
  message_period++;
  ports_state++;
}


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA8</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
void IO2output(){
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA9</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  //pinMode(PA0, OUTPUT); //switch
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA10</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PA1, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA15</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PA2, OUTPUT);
  pinMode(PA3, OUTPUT);
  pinMode(PA4, OUTPUT);
  pinMode(PA5, OUTPUT);
  pinMode(PA6, OUTPUT);
  pinMode(PA7, OUTPUT);


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB0</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PA8, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB1</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PA9, OUTPUT);
&nbsp;
  pinMode(PA10, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB3</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PA15, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB4</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB5</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB6</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB7</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB8</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB9</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB10</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB0, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB11</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB1, OUTPUT);
 
  pinMode(PB3, OUTPUT);
  pinMode(PB4, OUTPUT);
  pinMode(PB5, OUTPUT);
  pinMode(PB6, OUTPUT);
  pinMode(PB7, OUTPUT);
  pinMode(PB8, OUTPUT);
  pinMode(PB9, OUTPUT);


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB12</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB10, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB13</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB11, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB14</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB15</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#434f54">&#47;&#47;pinMode(PC13, OUTPUT); &nbsp;&#47;&#47;led</font>
<font color="#000000">}</font>


<font color="#00979c">void</font> <font color="#000000">IO2input</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">{</font>
  pinMode(PB12, OUTPUT);
&nbsp;<font color="#434f54">&#47;&#47;pinMode(PA0, INPUT); &#47;&#47;switch</font>
  pinMode(PB13, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA1</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB14, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA2</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB15, OUTPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA3</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  //pinMode(PC13, OUTPUT);  //led
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA4</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
}
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA5</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  &nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA6</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA7</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA8</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
void IO2input(){
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA9</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  //pinMode(PA0, INPUT); //switch
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA10</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PA1, INPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PA15</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PA2, INPUT);
  pinMode(PA3, INPUT);
  pinMode(PA4, INPUT);
  pinMode(PA5, INPUT);
  pinMode(PA6, INPUT);
  pinMode(PA7, INPUT);


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB0</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PA8, INPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB1</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PA9, INPUT);
  pinMode(PA10, INPUT);
  pinMode(PA15, INPUT);


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB3</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB0, INPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB4</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB1, INPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB5</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB6</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB7</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB8</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB9</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB10</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB3, INPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB11</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB4, INPUT);
  pinMode(PB5, INPUT);
  pinMode(PB6, INPUT);
  pinMode(PB7, INPUT);
  pinMode(PB8, INPUT);
  pinMode(PB9, INPUT);


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB12</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB10, INPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB13</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
  pinMode(PB11, INPUT);
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB14</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#00979c">PB15</font><font color="#434f54">,</font> <font color="#00979c">INPUT</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#434f54">&#47;&#47;pinMode(PC13, INPUT); &nbsp;&#47;&#47;led</font>
  pinMode(PB12, INPUT);
<font color="#000000">}</font>
  pinMode(PB13, INPUT);
  pinMode(PB14, INPUT);
  pinMode(PB15, INPUT);


<font color="#00979c">void</font> <font color="#000000">IO2low</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">{</font>
  //pinMode(PC13, INPUT);  //led
&nbsp;<font color="#434f54">&#47;&#47;digitalWrite(PA0, LOW); &#47;&#47;switch</font>
}
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA1</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA2</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  &nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA3</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA4</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA5</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA6</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA7</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA8</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
void IO2low(){
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA9</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  //digitalWrite(PA0, LOW); //switch
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA10</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA1, LOW);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA15</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA2, LOW);
  digitalWrite(PA3, LOW);
  digitalWrite(PA4, LOW);
  digitalWrite(PA5, LOW);
  digitalWrite(PA6, LOW);
  digitalWrite(PA7, LOW);


&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB0</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA8, LOW);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB1</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA9, LOW);
&nbsp;
  digitalWrite(PA10, LOW);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB3</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA15, LOW);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB4</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB5</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB6</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB7</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB8</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB9</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB10</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PB0, LOW);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB11</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PB1, LOW);
 
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, LOW);
  digitalWrite(PB5, LOW);
  digitalWrite(PB6, LOW);
  digitalWrite(PB7, LOW);
  digitalWrite(PB8, LOW);
  digitalWrite(PB9, LOW);


&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB12</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PB10, LOW);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB13</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PB11, LOW);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB14</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB15</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#434f54">&#47;&#47;digitalWrite(PC13, LOW); &nbsp;&nbsp;</font>
  digitalWrite(PB12, LOW);
<font color="#000000">}</font>
  digitalWrite(PB13, LOW);
  digitalWrite(PB14, LOW);
  digitalWrite(PB15, LOW);


<font color="#00979c">void</font> <font color="#000000">IO2high</font><font color="#000000">(</font><font color="#000000">)</font><font color="#000000">{</font>
  //digitalWrite(PC13, LOW);  
&nbsp;<font color="#434f54">&#47;&#47;digitalWrite(PA0, HIGH); &#47;&#47;switch</font>
}
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA1</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA2</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA3</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA4</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA5</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA6</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA7</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA8</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
void IO2high(){
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA9</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  //digitalWrite(PA0, HIGH); //switch
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA10</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA1, HIGH);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PA15</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA2, HIGH);
  digitalWrite(PA3, HIGH);
  digitalWrite(PA4, HIGH);
  digitalWrite(PA5, HIGH);
  digitalWrite(PA6, HIGH);
  digitalWrite(PA7, HIGH);


&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB0</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA8, HIGH);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB1</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA9, HIGH);
&nbsp;
  digitalWrite(PA10, HIGH);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB3</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PA15, HIGH);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB4</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB5</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB6</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB7</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB8</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB9</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB10</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PB0, HIGH);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB11</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PB1, HIGH);
 
  digitalWrite(PB3, HIGH);
  digitalWrite(PB4, HIGH);
  digitalWrite(PB5, HIGH);
  digitalWrite(PB6, HIGH);
  digitalWrite(PB7, HIGH);
  digitalWrite(PB8, HIGH);
  digitalWrite(PB9, HIGH);


&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB12</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PB10, HIGH);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB13</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
  digitalWrite(PB11, HIGH);
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB14</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#00979c">PB15</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>


&nbsp;<font color="#434f54">&#47;&#47;digitalWrite(PC13, HIGH); &nbsp;&nbsp;</font>
  digitalWrite(PB12, HIGH);
<font color="#000000">}</font>
  digitalWrite(PB13, HIGH);
  digitalWrite(PB14, HIGH);
  digitalWrite(PB15, HIGH);


<font color="#00979c">void</font> <font color="#000000">IOwriteIndexed</font><font color="#000000">(</font><font color="#00979c">int</font> <font color="#000000">index</font><font color="#434f54">,</font> <font color="#00979c">int</font> <font color="#000000">state</font><font color="#000000">)</font><font color="#000000">{</font>
  //digitalWrite(PC13, HIGH)
&nbsp;<font color="#00979c">int</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#000000">1</font><font color="#000000">;</font>
}


&nbsp;<font color="#5e6d03">switch</font> <font color="#000000">(</font><font color="#000000">index</font><font color="#000000">)</font><font color="#000000">{</font>
void IOwriteIndexed(int index, int state){
&nbsp;&nbsp;&nbsp;<font color="#434f54">&#47;&#47;case 0: pp = PA0; break;</font>
  int pp = 1;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">1</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA1</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">2</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA2</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">3</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA3</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">4</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA4</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">5</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA5</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">6</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA6</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">7</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA7</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>


&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">8</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB0</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
  switch (index){
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">9</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB1</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    //case 0: pp = PA0; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">10</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB10</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 1: pp = PA1; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">11</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB11</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 2: pp = PA2; break;
    case 3: pp = PA3; break;
    case 4: pp = PA4; break;
    case 5: pp = PA5; break;
    case 6: pp = PA6; break;
    case 7: pp = PA7; break;


&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">12</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB12</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 8: pp = PB0; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">13</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB13</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 9: pp = PB1; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">14</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB14</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 10: pp = PB10; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">15</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB15</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 11: pp = PB11; break;


&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">16</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA8</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 12: pp = PB12; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">17</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA9</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 13: pp = PB13; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">18</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA10</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 14: pp = PB14; break;
&nbsp;&nbsp;&nbsp;
    case 15: pp = PB15; break;
&nbsp;&nbsp;&nbsp;<font color="#434f54">&#47;&#47;case 19: pp = PA11; break</font>
&nbsp;&nbsp;&nbsp;<font color="#434f54">&#47;&#47;case 20: pp = PA12; break</font>
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">19</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PA15</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>


&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">20</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB3</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 16: pp = PA8; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">21</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB4</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 17: pp = PA9; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">22</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB5</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 18: pp = PA10; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">23</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB6</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
   
    //case 19: pp = PA11; break
    //case 20: pp = PA12; break
   
    case 19: pp = PA15; break;


&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">24</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB7</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 20: pp = PB3; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">25</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB8</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 21: pp = PB4; break;
&nbsp;&nbsp;&nbsp;<font color="#5e6d03">case</font> <font color="#000000">26</font><font color="#434f54">:</font> <font color="#000000">pp</font> <font color="#434f54">=</font> <font color="#00979c">PB9</font><font color="#000000">;</font> <font color="#5e6d03">break</font><font color="#000000">;</font>
    case 22: pp = PB5; break;
&nbsp;<font color="#000000">}</font>
    case 23: pp = PB6; break;


&nbsp;<font color="#d35400">pinMode</font><font color="#000000">(</font><font color="#000000">pp</font><font color="#434f54">,</font> <font color="#00979c">OUTPUT</font><font color="#000000">)</font><font color="#000000">;</font>
    case 24: pp = PB7; break;
&nbsp;<font color="#5e6d03">if</font> <font color="#000000">(</font><font color="#000000">state</font> <font color="#434f54">&gt;</font> <font color="#000000">0</font><font color="#000000">)</font><font color="#000000">{</font>
    case 25: pp = PB8; break;
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">pp</font><font color="#434f54">,</font> <font color="#00979c">HIGH</font><font color="#000000">)</font><font color="#000000">;</font>
    case 26: pp = PB9; break;
&nbsp;<font color="#000000">}</font> <font color="#5e6d03">else</font> <font color="#000000">{</font>
  }
&nbsp;&nbsp;&nbsp;<font color="#d35400">digitalWrite</font><font color="#000000">(</font><font color="#000000">pp</font><font color="#434f54">,</font> <font color="#00979c">LOW</font><font color="#000000">)</font><font color="#000000">;</font>
 
&nbsp;<font color="#000000">}</font>
  pinMode(pp, OUTPUT);
<font color="#000000">}</font>
  if (state > 0){
</code>
    digitalWrite(pp, HIGH);
  } else {
    digitalWrite(pp, LOW);
  }
}
</syntaxhighlight>
<br><br><br>
<br><br><br>
The program works on starting the serial port based on the USB interface and the RTC clock module and cyclically sending time information via this serial port.<br><br>
The program works on starting the serial port based on the USB interface and the RTC clock module and cyclically sending time information via this serial port.<br><br>
Line 541: Line 540:
===== Links =====  
===== Links =====  
*[https://wiki.kamamilabs.com/images/a/ac/Kamod_BluePill_3D.zip CAD model (STEP)]  
*[https://wiki.kamamilabs.com/images/a/ac/Kamod_BluePill_3D.zip CAD model (STEP)]  
*[https://kamami.pl/dl/ stm32f103_x6_x8_xb.pdf Catalog card of the STM32F103C8T6 system]  
*[https://kamami.pl/dl/stm32f103_x6_x8_xb.pdf Catalog card of the STM32F103C8T6 system]  
*[https://wiki.kamamilabs.com/images/0/0f/Program_testowy_arduino.zip Arduino test program]  
*[https://wiki.kamamilabs.com/images/0/0f/Program_testowy_arduino.zip Arduino test program]  
*[https://wiki.kamamilabs.com/images/0/0a/BluePillDemo_USB_CDC.zip Test project STM32CUBE_IDE]
*[https://wiki.kamamilabs.com/images/0/0a/BluePillDemo_USB_CDC.zip Test project STM32CUBE_IDE]

Latest revision as of 10:04, 2 November 2024

Description

Kamod BluePill+
Evaluation board with STM32F103C8T6 microcontroller, compatible with BluePill

The Kamod BluePill+ evaluation board contains the STM32F103C8T6 microcontroller and the components necessary to run and program it. The board is pin-compatible with the BluePill project, but has a number of improvements, including: new PCB design, USB-C connector with ESD protection, or improved power supply circuit. It can be programmed with Arduino IDE, because the system memory contains a suitable bootloader.

Basic features and parameters
  • STM32F103C8T6 microcontroller: 64 kB Flash, 20 kB RAM, 72 MHz, 2 x 12-bit ADC, 4 timers, 2 x I2C, 2 x SPI, 3 x UART, CAN, USB, RTC
  • USB-C connector, which serves as a power connector, USB communication interface and allows for microcontroller programming
  • elements filtering interference and overvoltages on USB interface lines
  • 32 GPIO pins and 5 V and 3.3 V power lines available on standard 2.54 mm pitch connectors
  • maximum load on the 5 V line is 500 mA, while for the 3.3 V line it is 200 mA
  • precise resonator clocking the microcontroller and an independent resonator for the RTC module
  • possibility of connecting a battery to support the RTC module
  • SWD programming/debugging interface connector
  • possibility of programming via STM32CubeIDE and Arduino IDE
  • board dimensions: 53.5x23 mm, height approx. 7 mm (without soldered goldpins)
Standard equipment
Code Description
Kamod BluePill+
  • Assembled and started module, with bootloader uploaded
  • 2 x straight goldpin header 20-pin raster 2.54 mm
  • 1 x angled goldpin header 4-pin raster 2.54 mm


Electrical diagram


Microcontroller and GPIO and SWD connectors
USB interface
Power supply circuit
Microcontroller clock speed
Additional elements
External memory
Power
Connector Function
USB-C

J1, J2

  • Supplies 5 V power to the module
  • Allows 5 V power and provides 3.3 V

The Kamod BluePill+ evaluation board can be powered in two ways:

  • via the appropriate contacts of J1 and J2 connectors,
  • via the USB-C connector.


A power source with a voltage in the range of 4.5...5.5 V and an efficiency of min. 100 mA should be connected to the contacts marked ' 5V (plus) and GND (minus) on connectors J1 and/or J2. Then, on the contact marked 3.3V, a stabilized voltage of 3.3 V is available, which also powers the microcontroller. The presence of 3.3 V is indicated by the LED marked PWR' lighting up.

A standard USB power source with a capacity of at least 100 mA should be connected to the USB-C connector. Then, on the 5V contact of connector J1, a voltage of close to 5 V is available (relative to the ground marked GND). A small voltage drop (approx. 0.5 V) occurs on the Schottky diode, which allows current to flow in the direction from the USB-C connector to the board, but blocks current flow in the opposite direction - to the USB-C connector. Thanks to this, you can safely connect power in various configurations - USB and/or J1, J2 contacts.

There is a contact marked B+' on the J2 connector. Together with the ground GND this is the power input from the battery supporting the RTC clock (integrated with the microcontroller). The backup battery voltage should be in the range of 1.8...3.6 V. Detailed information on the operation of the RTC module can be found in the documentation for the STM32F103C8T6 microcontroller.

USB interface
Connector Ffunction
USB-C
  • Provides 5V power to the module
  • Can implement USB 2.0 FS Peripheral interface
  • Allows programming of microcontroller Flash memory

The USB-C connector is an easy way to provide power to the Kamod BluePill+ board. In addition, the STM32F103C8T6 microcontroller has an integrated USB 2.0 FS interface controller, which can be used for communication, e.g. in VCP (Virtual COM Port) or CDC (Communication Device Class) mode.

The board has been configured in such a way that it allows the interface to operate in Peripheral mode, it is not prepared to work in Host mode. The board also contains elements that filter possible interference and overvoltages on the USB interface lines, which ensure its stable operation.

Additional functionality of the USB-C connector is the ability to program the microcontroller's Flash memory. This requires an appropriate bootloader, which is loaded into the Kamod BluePill+ module microcontroller along with the test program.

The USB interface lines (DP and DM) are also GPIO ports PA12 and PA11 of the microcontroller. If we use USB, the contacts marked A12 and A11 cannot perform any other function - they must remain unconnected.

SWD programming/debugging interface
Connector Function
J3
  • SWD (Single Wire Debug) interface with SWDIO and SWCLK signals

The SWD (Single Wire Debug) interface allows for programming the microcontroller's Flash memory and tracking the program's operation (debugging). Requires the connection of an external programmer/debugger, e.g. STLINK-V2 or STLINK-V3MINIE.

The SWD interface has been led out to the J3 pin connector. The signals are described as follows:

  • G – system ground,
  • C – SWCLK clock signal,
  • D – SWDIO data signal,
  • V – 3.3 V power line.

The signals should be connected to the same signals on the programmer/debugger connector. Sometimes SWCLK is also marked as TCK, while SWDIO is also marked as TMS. The programmer does not supply power to the Kamod BluePill+ board, the power should be connected to the USB-C connector or J1/J2 pins.

Microcontroller programming
Component Function

SW1 – NRST
SW2 – BOOT0
J3 – SWD
A9, A10 – UART

  • Forcing the microcontroller to zero state
  • Starting the factory microcontroller bootloader
  • SWD (Single Wire Debug) programming interface
  • UART (TXD, RXD) programming interface

A special area of ​​the microcontroller's memory contains software that allows programming its program memory - this is the so-called bootloader prepared by the microcontroller manufacturer. To start the bootloader, perform the following sequence of actions, with the board's power supply connected:

  1. Press and hold the NRTS button
  2. Press and hold the BOOT 0 button while holding the NRST button
  3. Release the NRTS button while holding the BOOT 0 button
  4. Release the BOOT 0 button



Starting the bootloader activates two programming interfaces:

  • SWD, which was described in the previous chapter and allows programming the microcontroller using a programmer/debugger, e.g. STLINK-V2 or STLINK-V3MINIE.
  • UART, which allows you to use a regular USB-UART converter as a programmer, e.g. KAmod USB-UART-mini. Then you need to connect the UART interface lines to the A9 and A10 pins, where:
    • A9 – the TXD output of the microcontroller should be connected to the RXD input of the USB-UART converter,
    • A10 – the RXD input of the microcontroller should be connected to the TXD output of the USB-UART converter.



Now you can program the microcontroller via SWD or UART using the STM32CubeProgrammer, which is available on the official STMicroelectronics website: https://www.st.com/en/development-tools/stm32cubeprog.html


The Kamod BluePill+ board also allows you to program the microcontroller via the USB interface using the Arduino IDE. This is possible because, along with the test program, an additional bootloader is placed in the program memory for communication and programming in the Arduino environment.duino.Then you should:


Then, after creating a new sketch, in the Tools tab:

  • select the board: BluePill F103C8,
  • set the Upload method to: Maple DFU Bootloader 2.0,
  • USB support should be set to: CDC (generic Serial),
  • U(S)ART support should be set to: Enabled (generic Serial),
  • select STM Serial communication port (COMxx).


Additional elements – LED and button
Component Function

D3 – LED (C13)
SW3 – KEY (A0)

  • LED connected to port PC13, active in L state
  • Microswitch connected to port PA0, active in L state

The Kamod BluePill+ board contains additional elements – LED and microswitch, which can be used in the target application.

The LED is connected to port PC13, it lights up when the state is low.

The microswitch is connected to port PA0, pressing it forces the state to be low on this port. The button is connected via a 1k resistor, so there is no possibility of damaging port PA0 configured as an output.

GPIO connectors
Connector Function
J1, J2
  • 20-pin connectors with a 2.54 mm pitch, to which the microcontroller's GPIO ports and 5 V and 3.3 V power supply are connected

GPIO connectors J1 and J2 contain 20 pins each, to which the 5 V, 3.3 V power supply lines, GND ground and the GPIO pins of the microcontroller module are connected. The exact description of the pins and their additional functions are shown in the drawing and table below:

Dimensions

The dimensions of the Kamod BluePill+ board are 53.5x23 mm, and the height is approx. 7 mm (without soldered goldpins).

Test program

The simplified code of the test program is below, it can be compiled in the Arduino environment.

#include <STM32RTC.h>

#define LED_PIN   PC13
#define SW_PIN    PA0

int message_period = 0;
int config_state = 0;
int ports_state = 0;
int pindex = 0;

STM32RTC& rtc = STM32RTC::getInstance();

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
  pinMode(SW_PIN, INPUT_PULLUP);
  rtc.begin(); // initialize RTC 24H format
}

// the loop function runs over and over again forever
void loop() {
  //digitalWrite(LED_PIN, HIGH);
  if (digitalRead(SW_PIN) == HIGH){
    if ((ports_state&4) > 0){
      digitalWrite(LED_PIN, HIGH);      
    } else {    
      digitalWrite(LED_PIN, LOW);      
    }

    if (config_state > 0){
      IO2input();
      config_state = 0;
    }

  } else {
    if ((ports_state&1) > 0){
      digitalWrite(LED_PIN, HIGH);      
    } else {    
      digitalWrite(LED_PIN, LOW);      
    }
    
    if (config_state == 0){
      IO2output();
      config_state = 1;
    }


    if (config_state == 1){
      IO2low();
      IOwriteIndexed(pindex, 1);
      pindex++;
      if (pindex > 26) pindex = 1;
    }
  }

  // check if plugged into a host
  if (message_period >= 11){
    message_period = 0;
    
    int tmt = rtc.getMinutes();
    Serial.print("KAmod BluePill+ RTC=");
    if (tmt < 10) Serial.print("0");
    Serial.print(tmt);
    
    tmt = rtc.getSeconds();
    Serial.print(":");
    if (tmt < 10) Serial.print("0");
    Serial.println(tmt);
  }
  
  delay(200); 
  message_period++;
  ports_state++;
}

void IO2output(){
  //pinMode(PA0, OUTPUT); //switch
  pinMode(PA1, OUTPUT);
  pinMode(PA2, OUTPUT);
  pinMode(PA3, OUTPUT);
  pinMode(PA4, OUTPUT);
  pinMode(PA5, OUTPUT);
  pinMode(PA6, OUTPUT);
  pinMode(PA7, OUTPUT);

  pinMode(PA8, OUTPUT);
  pinMode(PA9, OUTPUT);
  pinMode(PA10, OUTPUT);
  pinMode(PA15, OUTPUT);

  pinMode(PB0, OUTPUT);
  pinMode(PB1, OUTPUT);
  
  pinMode(PB3, OUTPUT);
  pinMode(PB4, OUTPUT);
  pinMode(PB5, OUTPUT);
  pinMode(PB6, OUTPUT);
  pinMode(PB7, OUTPUT);
  pinMode(PB8, OUTPUT);
  pinMode(PB9, OUTPUT);

  pinMode(PB10, OUTPUT);
  pinMode(PB11, OUTPUT);

  pinMode(PB12, OUTPUT);
  pinMode(PB13, OUTPUT);
  pinMode(PB14, OUTPUT);
  pinMode(PB15, OUTPUT);
  //pinMode(PC13, OUTPUT);  //led
}

void IO2input(){
  //pinMode(PA0, INPUT); //switch
  pinMode(PA1, INPUT);
  pinMode(PA2, INPUT);
  pinMode(PA3, INPUT);
  pinMode(PA4, INPUT);
  pinMode(PA5, INPUT);
  pinMode(PA6, INPUT);
  pinMode(PA7, INPUT);

  pinMode(PA8, INPUT);
  pinMode(PA9, INPUT);
  pinMode(PA10, INPUT);
  pinMode(PA15, INPUT);

  pinMode(PB0, INPUT);
  pinMode(PB1, INPUT);

  pinMode(PB3, INPUT);
  pinMode(PB4, INPUT);
  pinMode(PB5, INPUT);
  pinMode(PB6, INPUT);
  pinMode(PB7, INPUT);
  pinMode(PB8, INPUT);
  pinMode(PB9, INPUT);

  pinMode(PB10, INPUT);
  pinMode(PB11, INPUT);

  pinMode(PB12, INPUT);
  pinMode(PB13, INPUT);
  pinMode(PB14, INPUT);
  pinMode(PB15, INPUT);

  //pinMode(PC13, INPUT);  //led
}

void IO2low(){
  //digitalWrite(PA0, LOW); //switch
  digitalWrite(PA1, LOW);
  digitalWrite(PA2, LOW);
  digitalWrite(PA3, LOW);
  digitalWrite(PA4, LOW);
  digitalWrite(PA5, LOW);
  digitalWrite(PA6, LOW);
  digitalWrite(PA7, LOW);

  digitalWrite(PA8, LOW);
  digitalWrite(PA9, LOW);
  digitalWrite(PA10, LOW);
  digitalWrite(PA15, LOW);

  digitalWrite(PB0, LOW);
  digitalWrite(PB1, LOW);
  
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, LOW);
  digitalWrite(PB5, LOW);
  digitalWrite(PB6, LOW);
  digitalWrite(PB7, LOW);
  digitalWrite(PB8, LOW);
  digitalWrite(PB9, LOW);

  digitalWrite(PB10, LOW);
  digitalWrite(PB11, LOW);

  digitalWrite(PB12, LOW);
  digitalWrite(PB13, LOW);
  digitalWrite(PB14, LOW);
  digitalWrite(PB15, LOW);

  //digitalWrite(PC13, LOW);   
}

void IO2high(){
  //digitalWrite(PA0, HIGH); //switch
  digitalWrite(PA1, HIGH);
  digitalWrite(PA2, HIGH);
  digitalWrite(PA3, HIGH);
  digitalWrite(PA4, HIGH);
  digitalWrite(PA5, HIGH);
  digitalWrite(PA6, HIGH);
  digitalWrite(PA7, HIGH);

  digitalWrite(PA8, HIGH);
  digitalWrite(PA9, HIGH);
  digitalWrite(PA10, HIGH);
  digitalWrite(PA15, HIGH);

  digitalWrite(PB0, HIGH);
  digitalWrite(PB1, HIGH);
  
  digitalWrite(PB3, HIGH);
  digitalWrite(PB4, HIGH);
  digitalWrite(PB5, HIGH);
  digitalWrite(PB6, HIGH);
  digitalWrite(PB7, HIGH);
  digitalWrite(PB8, HIGH);
  digitalWrite(PB9, HIGH);

  digitalWrite(PB10, HIGH);
  digitalWrite(PB11, HIGH);

  digitalWrite(PB12, HIGH);
  digitalWrite(PB13, HIGH);
  digitalWrite(PB14, HIGH);
  digitalWrite(PB15, HIGH);

  //digitalWrite(PC13, HIGH);   
}

void IOwriteIndexed(int index, int state){
  int pp = 1;

  switch (index){
    //case 0: pp = PA0; break;
    case 1: pp = PA1; break;
    case 2: pp = PA2; break;
    case 3: pp = PA3; break;
    case 4: pp = PA4; break;
    case 5: pp = PA5; break;
    case 6: pp = PA6; break;
    case 7: pp = PA7; break;

    case 8: pp = PB0; break;
    case 9: pp = PB1; break;
    case 10: pp = PB10; break;
    case 11: pp = PB11; break;

    case 12: pp = PB12; break;
    case 13: pp = PB13; break;
    case 14: pp = PB14; break;
    case 15: pp = PB15; break;

    case 16: pp = PA8; break;
    case 17: pp = PA9; break;
    case 18: pp = PA10; break;
    
    //case 19: pp = PA11; break
    //case 20: pp = PA12; break
    
    case 19: pp = PA15; break;

    case 20: pp = PB3; break;
    case 21: pp = PB4; break;
    case 22: pp = PB5; break;
    case 23: pp = PB6; break;

    case 24: pp = PB7; break;
    case 25: pp = PB8; break;
    case 26: pp = PB9; break;
  }

  pinMode(pp, OUTPUT);
  if (state > 0){
    digitalWrite(pp, HIGH);
  } else {
    digitalWrite(pp, LOW);
  }
}




The program works on starting the serial port based on the USB interface and the RTC clock module and cyclically sending time information via this serial port.

The program is run by slow flashing of the D3 LED. When the KEY (SW3) button is pressed, all ports the high state will be set and the LED will start flashing quickly.

Links