Vladimir N. Shilov 5 жил өмнө
parent
commit
1af0d6ac80
8 өөрчлөгдсөн 66 нэмэгдсэн , 32 устгасан
  1. 4 0
      ReadMe.txt
  2. BIN
      hw/disp-in4x6.dch
  3. BIN
      hw/disp-in4x6.dip
  4. 2 2
      inc/common.h
  5. 1 1
      inc/event-system.h
  6. 13 6
      inc/main.h
  7. 1 1
      inc/rtos.h
  8. 45 22
      src/main.c

+ 4 - 0
ReadMe.txt

@@ -7,3 +7,7 @@ PWR: MAX771
 Управление катодами: К155ИД1
 
 Начальный исходный код от проекта "My Nixie Clock IN-12".
+=====
+2020.01.12
+Поправил под схему на 6 индикаторов.
+Идут 2 секунды и виснут...

BIN
hw/disp-in4x6.dch


BIN
hw/disp-in4x6.dip


+ 2 - 2
inc/common.h

@@ -5,8 +5,8 @@
 /**
  * Global defines
  */
-#define USE_BRIGHT_CONTROL
-#define USE_DHT
+//#define USE_BRIGHT_CONTROL
+//#define USE_DHT
 //#define USE_UART
 
 #endif /* _COMMON_H */

+ 1 - 1
inc/event-system.h

@@ -18,7 +18,7 @@
 #include "list_event.h"
 
 /* вместимость буфера очереди событий */
-#define SIZE_BUF 16
+#define SIZE_BUF 20
 
 void ES_Init(es_state_t init_state);    /* инициализация */
 es_state_t ES_GetState(void);           /* взять код состояния */

+ 13 - 6
inc/main.h

@@ -56,12 +56,19 @@
 #define DIGIT_PINS      (DIGIT_A0 | DIGIT_A1 | DIGIT_A2 | DIGIT_A3)
 
 /* Port D, Lamp anods, Dot, RTC interrupt, UART */
-#define DOT_PIN         _BV(PD2)
-#define ANOD1           _BV(PD4)
-#define ANOD2           _BV(PD5)
-#define ANOD3           _BV(PD6)
-#define ANOD4           _BV(PD7)
-#define ANOD_PINS       (ANOD1 | ANOD2 | ANOD3 | ANOD4)
+#define A123_PORT       PORTD
+#define DOT_PIN         _BV(PD4)
+#define ANOD1           _BV(PD5)
+#define ANOD2           _BV(PD6)
+#define ANOD3           _BV(PD7)
+#define ANODD_PINS      (ANOD1 | ANOD2 | ANOD3)
+
+/* Port B, Lamp anods, BTNs */
+#define A456_PORT       PORTB
+#define ANOD4           _BV(PB0)
+#define ANOD5           _BV(PB1)
+#define ANOD6           _BV(PB2)
+#define ANODB_PINS      (ANOD4 | ANOD5 | ANOD6)
 
 
 typedef struct {

+ 1 - 1
inc/rtos.h

@@ -21,7 +21,7 @@
 
 #include <avr/io.h>
 
-#define MAX_TASKS      10              // Количество задач
+#define MAX_TASKS      20              // Количество задач
 
 /**
  * Будем использовать таймер 0, период -- 1 мсек

+ 45 - 22
src/main.c

@@ -1,7 +1,7 @@
 /**
- * My Nixie Clock IN-12
+ * My Nixie Clock IN-4x6
  * Vladimir N. Shilov <shilow@ukr.net>
- * 2019.01.18
+ * 2020.01.06
  */
 /* Compiler libs */
 #include <stdbool.h>
@@ -62,16 +62,16 @@ static struct {
 
 
 /* Variables */
-static volatile uint8_t Digit[4] = {1, 2, 3, 4};
+static volatile uint8_t Digit[6] = {1, 2, 3, 4, 5, 6};
 static rtc_t RTC, setRTC;
 static volatile struct {
   uint8_t RTC_Int:  1;
   uint8_t saveCal:  1;
-  uint8_t blinkC:   1;
-  uint8_t blink0:   1;
-  uint8_t blink1:   1;
-  uint8_t blink2:   1;
-  uint8_t blink3:   1;
+  uint8_t blinkC:   1; // флаг задающий ритм мигания
+  uint8_t blink0:   1; // мигать разрядами 1-2
+  uint8_t blink1:   1; // мигать разрядами 3-4
+  uint8_t blink2:   1; // мигать разрядами 5-6
+  uint8_t rezerv:   1;
   uint8_t saveEEP:  1;
 } Flag;
 static btn_t Button[BTN_NUM] = {
@@ -114,7 +114,6 @@ void main(void) {
   Flag.blink0 = 0;
   Flag.blink1 = 0;
   Flag.blink2 = 0;
-  Flag.blink3 = 0;
   Flag.blinkC = 0;
   Flag.saveEEP = 0;
 
@@ -132,6 +131,7 @@ void main(void) {
 
   /* Initialize Scheduler */
   RTOS_Init();
+  tdelay_ms(10000);
 
   /* Initialize I2C Bus and RTC */
   I2C_Init();
@@ -236,9 +236,10 @@ static void Board_Init(void) {
   ACSR = ACD;
 
   /* GPIO */
+  DDRB = ANODB_PINS; // as output
   PORTB = BUTTON_PINS; // enable pull-up
   DDRC = DIGIT_PINS; // as output
-  DDRD = (DOT_PIN | ANOD_PINS); // as output
+  DDRD = (DOT_PIN | ANODD_PINS); // as output
 
 #ifdef USE_DHT
   /* Timer1, IC negative edge, CTC mode, 64 prescaler, 4 mks one tick */
@@ -470,6 +471,8 @@ void showTime(void) {
   Digit[1] = RTC.Hr & 0x0F;
   Digit[2] = RTC.Min >> 4;
   Digit[3] = RTC.Min & 0x0F;
+  Digit[4] = RTC.Sec >> 4;
+  Digit[5] = RTC.Sec & 0x0F;
 }
 
 void showMMSS(void) {
@@ -628,9 +631,8 @@ void setTimeBegin(void) {
 
 void setHHBegin(void) {
   Flag.blink0 = 1;
-  Flag.blink1 = 1;
+  Flag.blink1 = 0;
   Flag.blink2 = 0;
-  Flag.blink3 = 0;
   RTOS_SetTask(blink, 0, 0);
   setTimeShow();
 }
@@ -645,9 +647,8 @@ void setHHDec(void) {
 
 void setMMBegin(void) {
   Flag.blink0 = 0;
-  Flag.blink1 = 0;
-  Flag.blink2 = 1;
-  Flag.blink3 = 1;
+  Flag.blink1 = 1;
+  Flag.blink2 = 0;
   RTOS_SetTask(blink, 0, 0);
   setTimeShow();
 }
@@ -670,7 +671,6 @@ void setTimeEnd(void) {
   Flag.blink0 = 0;
   Flag.blink1 = 0;
   Flag.blink2 = 0;
-  Flag.blink3 = 0;
   Flag.blinkC = 0;
 
   RTC_ReadTime(&RTC);
@@ -745,11 +745,13 @@ ISR(TIMER2_OVF_vect) {
   TCNT2 = TIMER2_CNT;
 
   // read current register value and clean bits
-  uint8_t pd = PORTD & ~ANOD_PINS;
+  uint8_t pb = PORTB & ~ANODB_PINS;
+  uint8_t pd = PORTD & ~ANODD_PINS;
   uint8_t pc = PORTC & ~DIGIT_PINS;
 
 #ifndef USE_BRIGHT_CONTROL
   // power off lamps
+  PORTB = pb;
   PORTD = pd;
   PORTC = pc;
 #endif
@@ -770,7 +772,7 @@ ISR(TIMER2_OVF_vect) {
   case 1:
     PORTC = pc | Digit[1];
     if (Digit[1] != DIGIT_BLANK) {
-      if (Flag.blink1 == 0 || Flag.blinkC == 0) {
+      if (Flag.blink0 == 0 || Flag.blinkC == 0) {
         PORTD = pd | ANOD2;
       }
     }
@@ -780,7 +782,7 @@ ISR(TIMER2_OVF_vect) {
   case 2:
     PORTC = pc | Digit[2];
     if (Digit[2] != DIGIT_BLANK) {
-      if (Flag.blink2 == 0 || Flag.blinkC == 0) {
+      if (Flag.blink1 == 0 || Flag.blinkC == 0) {
         PORTD = pd | ANOD3;
       }
     }
@@ -790,8 +792,28 @@ ISR(TIMER2_OVF_vect) {
   case 3:
     PORTC = pc | Digit[3];
     if (Digit[3] != DIGIT_BLANK) {
-      if (Flag.blink3 == 0 || Flag.blinkC == 0) {
-        PORTD = pd | ANOD4;
+      if (Flag.blink1 == 0 || Flag.blinkC == 0) {
+        PORTB = pb | ANOD4;
+      }
+    }
+    idx = 4;
+    break;
+
+  case 4:
+    PORTC = pc | Digit[4];
+    if (Digit[4] != DIGIT_BLANK) {
+      if (Flag.blink2 == 0 || Flag.blinkC == 0) {
+        PORTB = pb | ANOD5;
+      }
+    }
+    idx = 5;
+    break;
+
+  case 5:
+    PORTC = pc | Digit[5];
+    if (Digit[5] != DIGIT_BLANK) {
+      if (Flag.blink2 == 0 || Flag.blinkC == 0) {
+        PORTB = pb | ANOD6;
       }
     }
     idx = 0;
@@ -811,7 +833,8 @@ ISR(TIMER2_OVF_vect) {
 #pragma GCC optimize ("O3")
 ISR(TIMER2_COMP_vect) {
   // power off lamps
-  PORTD &= ~ANOD_PINS;
+  PORTB &= ~ANODB_PINS;
+  PORTD &= ~ANODD_PINS;
   PORTC &= ~DIGIT_PINS;
 }
 #endif // USE_BRIGHT_CONTROL