|
@@ -26,10 +26,12 @@
|
|
|
#define TIMER2_CS (1<<CS22 | 1<<CS21 | 1<<CS20)
|
|
|
#define TIMER2_CNT (0x100 - (F_CPU / TIMER2_PRESCALER / TIMER2_HZ))
|
|
|
|
|
|
+#if (USE_BRIGHT_CONTROL == 1)
|
|
|
/* Lamp brightness */
|
|
|
#define BRIGHT_IDX_MAX 9
|
|
|
#define FULL_BRIGHT_ON 0x06
|
|
|
#define FULL_BRIGHT_OFF 0x22
|
|
|
+#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
/* Display timeout, sec */
|
|
|
#define DISP_WDT_TIME 10
|
|
@@ -59,9 +61,11 @@ static uint8_t brightIdx;
|
|
|
static EEMEM uint8_t EEP_SummerTime;
|
|
|
|
|
|
/* Constants */
|
|
|
+#if (USE_BRIGHT_CONTROL == 1)
|
|
|
static const uint8_t PROGMEM brightConv[10] = {
|
|
|
195, 196, 197, 199, 203, 208, 216, 226, 239, 255
|
|
|
};
|
|
|
+#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
/* Function prototypes */
|
|
|
static void Board_Init(void);
|
|
@@ -86,10 +90,12 @@ void main(void) {
|
|
|
Flag.blinkC = 0;
|
|
|
Flag.saveEEP = 0;
|
|
|
|
|
|
+ #if (USE_BRIGHT_CONTROL == 1)
|
|
|
brightIdx = eeprom_read_byte(&EEP_BrightIdx);
|
|
|
if (brightIdx > BRIGHT_IDX_MAX) {
|
|
|
brightIdx = BRIGHT_IDX_MAX;
|
|
|
}
|
|
|
+ #endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
/**
|
|
|
* Инициализация, настройка...
|
|
@@ -124,11 +130,13 @@ void main(void) {
|
|
|
RTC_ReadCalendar(&RTC);
|
|
|
ES_PlaceEvent(evRefreshCal);
|
|
|
}
|
|
|
+#if (USE_BRIGHT_CONTROL == 1)
|
|
|
if (RTC.Hr >= FULL_BRIGHT_ON && RTC.Hr < FULL_BRIGHT_OFF) {
|
|
|
OCR2 = pgm_read_byte(&brightConv[BRIGHT_IDX_MAX]);
|
|
|
} else {
|
|
|
OCR2 = pgm_read_byte(&brightConv[brightIdx]);
|
|
|
}
|
|
|
+#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
setSummerWinterTime();
|
|
|
} // begin new hour
|
|
@@ -186,7 +194,9 @@ static void Board_Init(void) {
|
|
|
TCCR2 = TIMER2_CS;
|
|
|
TCNT2 = TIMER2_CNT;
|
|
|
TIMSK = _BV(TOIE2) | _BV(OCIE2);
|
|
|
+#if (USE_BRIGHT_CONTROL == 1)
|
|
|
OCR2 = pgm_read_byte(&brightConv[BRIGHT_IDX_MAX]);
|
|
|
+#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
/* Interrupt from RTC */
|
|
|
MCUCR = _BV(ISC11); // falling edge
|
|
@@ -322,6 +332,7 @@ void showYear(void) {
|
|
|
Digit[3] = RTC.Year & 0x0F;
|
|
|
}
|
|
|
|
|
|
+#if (USE_BRIGHT_CONTROL == 1)
|
|
|
void showBright(void) {
|
|
|
DISP_WDT = DISP_WDT_TIME;
|
|
|
Digit[0] = DIGIT_BLANK;
|
|
@@ -329,6 +340,7 @@ void showBright(void) {
|
|
|
Digit[2] = brightIdx;
|
|
|
Digit[3] = DIGIT_BLANK;
|
|
|
}
|
|
|
+#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
void incWDay(void) {
|
|
|
if (RTC.WD < 7) {
|
|
@@ -384,6 +396,7 @@ void decYear(void) {
|
|
|
Flag.saveCal = 1;
|
|
|
}
|
|
|
|
|
|
+#if (USE_BRIGHT_CONTROL == 1)
|
|
|
void incBright(void) {
|
|
|
if (brightIdx < BRIGHT_IDX_MAX) {
|
|
|
brightIdx ++;
|
|
@@ -399,6 +412,7 @@ void decBright(void) {
|
|
|
Flag.saveEEP = 1;
|
|
|
}
|
|
|
}
|
|
|
+#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
static void blink(void) {
|
|
|
static uint8_t s = 0;
|
|
@@ -541,9 +555,11 @@ ISR(TIMER2_OVF_vect) {
|
|
|
uint8_t pd = PORTD & ~ANOD_PINS;
|
|
|
uint8_t pc = PORTC & ~DIGIT_PINS;
|
|
|
|
|
|
+#if (USE_BRIGHT_CONTROL != TRUE)
|
|
|
// power off lamps
|
|
|
-// PORTD = pd;
|
|
|
-// PORTC = pc;
|
|
|
+ PORTD = pd;
|
|
|
+ PORTC = pc;
|
|
|
+#endif
|
|
|
|
|
|
switch (idx) {
|
|
|
case 0:
|
|
@@ -594,6 +610,7 @@ ISR(TIMER2_OVF_vect) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#if (USE_BRIGHT_CONTROL == 1)
|
|
|
/**
|
|
|
* @brief Power Off Nixie output
|
|
|
* @note For Brightnes dimming
|
|
@@ -603,6 +620,7 @@ ISR(TIMER2_COMP_vect) {
|
|
|
PORTD &= ~ANOD_PINS;
|
|
|
PORTC &= ~DIGIT_PINS;
|
|
|
}
|
|
|
+#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
/**
|
|
|
* @brief заглушка для неиспользуемых прерываний
|