]> kolegite.com Git - vmks.git/commitdiff
Added an example of dynamic control of 7-segment LED indicators
authorvl_garistov <vl_garistov@gmail.com>
Wed, 10 Feb 2021 22:21:36 +0000 (00:21 +0200)
committervl_garistov <vl_garistov@gmail.com>
Wed, 10 Feb 2021 22:21:36 +0000 (00:21 +0200)
Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.PDF [new file with mode: 0644]
Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino [new file with mode: 0644]
Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj [new file with mode: 0644]
Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace [new file with mode: 0644]
Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.png [new file with mode: 0644]
Examples/7-segm_raw_dynamic/Backup Of 7-segm_raw_dynamic.pdsbak [new file with mode: 0644]
Examples/7-segm_raw_dynamic/Last Loaded 7-segm_raw_dynamic.pdsbak [new file with mode: 0644]

diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.PDF b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.PDF
new file mode 100644 (file)
index 0000000..dd885da
Binary files /dev/null and b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.PDF differ
diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino
new file mode 100644 (file)
index 0000000..b14da34
--- /dev/null
@@ -0,0 +1,140 @@
+#define A_PIN  12\r
+#define B_PIN  13\r
+#define C_PIN  7\r
+#define D_PIN  8\r
+#define E_PIN  9\r
+#define F_PIN  11\r
+#define G_PIN  10\r
+#define DP_PIN 6\r
+#define EN0_PIN        5\r
+#define EN1_PIN        4\r
+#define EN2_PIN        3\r
+#define EN3_PIN        2\r
+\r
+int print_dec(uint16_t value);\r
+int print_digit(uint8_t position, uint8_t digit);\r
+void timer_init(void);\r
+void gpio_init(void);\r
+\r
+const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};\r
+const uint8_t en_pins[4] = {EN0_PIN, EN1_PIN, EN2_PIN, EN3_PIN};\r
+\r
+const uint8_t segment_map[16] =\r
+{\r
+       // A B C D E F G DP\r
+       0b00000011,     // 0\r
+       0b10011111,     // 1\r
+       0b00100101,     // 2\r
+       0b00001101,     // 3\r
+       0b10011001,     // 4\r
+       0b01001001,     // 5\r
+       0b01000001,     // 6\r
+       0b00011111,     // 7\r
+       0b00000001,     // 8\r
+       0b00001001,     // 9\r
+       0b00010001,     // A\r
+       0b11000001,     // b\r
+       0b01100011,     // C\r
+       0b10000101,     // d\r
+       0b01100001,     // E\r
+       0b01110001      // F\r
+};\r
+\r
+volatile uint8_t display_value[4] = {0};\r
+volatile uint8_t current_digit = 0;\r
+\r
+void setup()\r
+{\r
+       gpio_init();\r
+       timer_init();\r
+}\r
+\r
+void loop()\r
+{\r
+       for (uint16_t cnt = 9999; cnt > 0; cnt--)\r
+       {\r
+               print_dec(cnt);\r
+               delay(100);\r
+       }\r
+       delay(3000);\r
+}\r
+\r
+int print_dec(uint16_t value)\r
+{\r
+       if (value > 9999)\r
+       {\r
+               return -1;\r
+       }\r
+\r
+       for (uint8_t i = 0; i < 4; i++)\r
+       {\r
+               print_digit(3 - i, value % 10);\r
+               value /= 10;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+int print_digit(uint8_t position, uint8_t digit)\r
+{\r
+       if (position > 4 || digit > 15)\r
+       {\r
+               return -1;\r
+       }\r
+\r
+       display_value[position] = digit;\r
+\r
+       return 0;\r
+}\r
+\r
+ISR(TIMER1_OVF_vect)\r
+{\r
+       digitalWrite(en_pins[current_digit], HIGH);\r
+\r
+       current_digit++;\r
+       if (current_digit > 3)\r
+       {\r
+               current_digit = 0;\r
+       }\r
+\r
+       for (uint8_t i = 0; i < 8; i++)\r
+       {\r
+               digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i));\r
+       }\r
+\r
+       digitalWrite(en_pins[current_digit], LOW);\r
+}\r
+\r
+void gpio_init(void)\r
+{\r
+       uint8_t i;\r
+       for (i = 0; i < 4; i++)\r
+       {\r
+               pinMode(en_pins[i], OUTPUT);\r
+               digitalWrite(en_pins[i], HIGH);\r
+       }\r
+       for (i = 0; i < 8; i++)\r
+       {\r
+               pinMode(segm_pins[i], OUTPUT);\r
+               digitalWrite(segm_pins[i], HIGH);\r
+       }\r
+}\r
+\r
+void timer_init(void)\r
+{\r
+       noInterrupts();\r
+       \r
+       // After clearing TCCR1B the timer is stopped\r
+       TCCR1B = 0;\r
+       TCNT1  = 0;\r
+       \r
+       TCCR1A = (1 << WGM11);\r
+       TCCR1B |= (1 << WGM12) | (1 << WGM13);\r
+       TIMSK1 = (1 << TOIE1);\r
+\r
+       // Set frequency to 1kHz\r
+       ICR1 = 1999;\r
+       TCCR1B |= (1 << CS11);\r
+\r
+       interrupts();\r
+}\r
diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj
new file mode 100644 (file)
index 0000000..d482f6c
Binary files /dev/null and b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj differ
diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace
new file mode 100644 (file)
index 0000000..1c21abc
--- /dev/null
@@ -0,0 +1,101 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\r
+<WORKSPACE>\r
+ <FRAME activewindow="0">\r
+  <PLACEMENT>2c0000000200000003000000ffffffffffffffffffffffffffffffffab0000000d000000d606000004040000</PLACEMENT>\r
+  <WINDOW type="default" module="ISIS"/>\r
+  <WINDOW type="device" module="LIBMAN"/>\r
+ </FRAME>\r
+ <MODULE name="VSMDEBUG">\r
+  <PWI>\r
+   <POPUP w="800" x="38" flags="00000002" y="129" h="200" pid="0" iid="-1">\r
+    <PROPERTIES>\r
+     <ITEM name="Message Column Width">542</ITEM>\r
+     <ITEM name="ShowGrid">No</ITEM>\r
+     <ITEM name="Source Column Width">100</ITEM>\r
+     <ITEM name="Time Column Width">120</ITEM>\r
+     <ITEM name="Version">100</ITEM>\r
+    </PROPERTIES>\r
+   </POPUP>\r
+   <POPUP w="350" x="58" flags="00000032" y="149" h="200" pid="1" iid="-1">\r
+    <PROPERTIES>\r
+     <ITEM name="Address Column Width">83</ITEM>\r
+     <ITEM name="AutoResize">No</ITEM>\r
+     <ITEM name="Gridlines">Yes</ITEM>\r
+     <ITEM name="Name Column Width">83</ITEM>\r
+     <ITEM name="ShowAddresses">Yes</ITEM>\r
+     <ITEM name="ShowPreviousValues">No</ITEM>\r
+     <ITEM name="ShowTypes">No</ITEM>\r
+     <ITEM name="ShowWatchPoint">Yes</ITEM>\r
+     <ITEM name="TriggerMode">0</ITEM>\r
+     <ITEM name="Value Column Width">83</ITEM>\r
+     <ITEM name="Version">100</ITEM>\r
+     <ITEM name="Watch Expression Column Width">83</ITEM>\r
+     <ITEM name="nItems">0</ITEM>\r
+    </PROPERTIES>\r
+   </POPUP>\r
+   <POPUP w="226" x="78" flags="00000008" y="169" h="215" pid="3" iid="1">\r
+    <PROPERTIES/>\r
+   </POPUP>\r
+   <POPUP w="8" x="98" flags="0000000a" y="189" h="1" pid="10" iid="1">\r
+    <PROPERTIES>\r
+     <ITEM name="DataType">2</ITEM>\r
+     <ITEM name="DispChars">Yes</ITEM>\r
+     <ITEM name="DispFormat">2</ITEM>\r
+     <ITEM name="ShowChanges">Yes</ITEM>\r
+     <ITEM name="ShowToolTips">Yes</ITEM>\r
+     <ITEM name="TopLineAddress">00000000</ITEM>\r
+    </PROPERTIES>\r
+   </POPUP>\r
+   <POPUP w="8" x="118" flags="0000000a" y="209" h="32" pid="6" iid="1">\r
+    <PROPERTIES>\r
+     <ITEM name="DataType">2</ITEM>\r
+     <ITEM name="DispChars">Yes</ITEM>\r
+     <ITEM name="DispFormat">2</ITEM>\r
+     <ITEM name="ShowChanges">Yes</ITEM>\r
+     <ITEM name="ShowToolTips">Yes</ITEM>\r
+     <ITEM name="TopLineAddress">00000000</ITEM>\r
+    </PROPERTIES>\r
+   </POPUP>\r
+   <POPUP w="16" x="138" flags="0000000a" y="229" h="32" pid="7" iid="1">\r
+    <PROPERTIES>\r
+     <ITEM name="DataType">2</ITEM>\r
+     <ITEM name="DispChars">Yes</ITEM>\r
+     <ITEM name="DispFormat">2</ITEM>\r
+     <ITEM name="ShowChanges">Yes</ITEM>\r
+     <ITEM name="ShowToolTips">Yes</ITEM>\r
+     <ITEM name="TopLineAddress">00000000</ITEM>\r
+    </PROPERTIES>\r
+   </POPUP>\r
+   <POPUP w="16" x="158" flags="80000000" y="249" h="32" pid="14" iid="1">\r
+    <PROPERTIES>\r
+     <ITEM name="DataType">2</ITEM>\r
+     <ITEM name="DispChars">Yes</ITEM>\r
+     <ITEM name="DispFormat">2</ITEM>\r
+     <ITEM name="ShowChanges">Yes</ITEM>\r
+     <ITEM name="ShowToolTips">Yes</ITEM>\r
+     <ITEM name="TopLineAddress">00000000</ITEM>\r
+    </PROPERTIES>\r
+   </POPUP>\r
+   <POPUP w="16" x="178" flags="0000000a" y="269" h="32" pid="4" iid="1">\r
+    <PROPERTIES>\r
+     <ITEM name="DataType">2</ITEM>\r
+     <ITEM name="DispChars">Yes</ITEM>\r
+     <ITEM name="DispFormat">2</ITEM>\r
+     <ITEM name="ShowChanges">Yes</ITEM>\r
+     <ITEM name="ShowToolTips">Yes</ITEM>\r
+     <ITEM name="TopLineAddress">00000100</ITEM>\r
+    </PROPERTIES>\r
+   </POPUP>\r
+   <POPUP w="16" x="198" flags="0000000a" y="289" h="8" pid="13" iid="1">\r
+    <PROPERTIES>\r
+     <ITEM name="DataType">2</ITEM>\r
+     <ITEM name="DispChars">Yes</ITEM>\r
+     <ITEM name="DispFormat">2</ITEM>\r
+     <ITEM name="ShowChanges">Yes</ITEM>\r
+     <ITEM name="ShowToolTips">Yes</ITEM>\r
+     <ITEM name="TopLineAddress">00000020</ITEM>\r
+    </PROPERTIES>\r
+   </POPUP>\r
+  </PWI>\r
+ </MODULE>\r
+</WORKSPACE>\r
diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.png b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.png
new file mode 100644 (file)
index 0000000..26fb620
Binary files /dev/null and b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.png differ
diff --git a/Examples/7-segm_raw_dynamic/Backup Of 7-segm_raw_dynamic.pdsbak b/Examples/7-segm_raw_dynamic/Backup Of 7-segm_raw_dynamic.pdsbak
new file mode 100644 (file)
index 0000000..9bed130
Binary files /dev/null and b/Examples/7-segm_raw_dynamic/Backup Of 7-segm_raw_dynamic.pdsbak differ
diff --git a/Examples/7-segm_raw_dynamic/Last Loaded 7-segm_raw_dynamic.pdsbak b/Examples/7-segm_raw_dynamic/Last Loaded 7-segm_raw_dynamic.pdsbak
new file mode 100644 (file)
index 0000000..8acc458
Binary files /dev/null and b/Examples/7-segm_raw_dynamic/Last Loaded 7-segm_raw_dynamic.pdsbak differ