|
@@ -19,11 +19,10 @@
|
|
|
#include "event-system.h"
|
|
|
|
|
|
/* Defines */
|
|
|
-#define TIMER2_HZ 250
|
|
|
-#define TIMER2_PRESCALER 256
|
|
|
-#define TIMER2_CS (1<<CS22 | 1<<CS21 | 0<<CS20)
|
|
|
+#define TIMER2_HZ 252
|
|
|
+#define TIMER2_PRESCALER 1024
|
|
|
+#define TIMER2_CS (1<<CS22 | 1<<CS21 | 1<<CS20)
|
|
|
#define TIMER2_CNT (0x100 - (F_CPU / TIMER2_PRESCALER / TIMER2_HZ))
|
|
|
-#define OCR2_MIN (0xFF - TIMER2_CNT)
|
|
|
#define OCR2_MAX 0xFF
|
|
|
#define FULL_BRIGHT_ON 0x06
|
|
|
#define FULL_BRIGHT_OFF 0x22
|
|
@@ -44,7 +43,7 @@ static volatile struct {
|
|
|
static btn_t Button[BTN_NUM] = {
|
|
|
{0, evBTN1Pressed, evBTN1Holded, BUTTON1_PIN},
|
|
|
{0, evBTN2Pressed, evBTN2Pressed, BUTTON2_PIN},
|
|
|
- {0, evBTN3Pressed, evBTN2Pressed, BUTTON3_PIN}
|
|
|
+ {0, evBTN3Pressed, evBTN3Pressed, BUTTON3_PIN}
|
|
|
};
|
|
|
static volatile uint8_t DISP_WDT = 0;
|
|
|
static EEMEM uint8_t EEP_Bright;
|
|
@@ -172,7 +171,7 @@ static void Board_Init(void) {
|
|
|
TCCR2 = TIMER2_CS;
|
|
|
TCNT2 = TIMER2_CNT;
|
|
|
TIMSK = _BV(TOIE2) | _BV(OCIE2);
|
|
|
- OCR2 = Bright;
|
|
|
+ OCR2 = OCR2_MAX;
|
|
|
|
|
|
/* Interrupt from RTC */
|
|
|
MCUCR = _BV(ISC11); // falling edge
|
|
@@ -234,7 +233,7 @@ static void btnProcess(void) {
|
|
|
// button pressed
|
|
|
if (BUTTON_STATE(Button[i].pin) == 0) {
|
|
|
Button[i].time ++;
|
|
|
- if (Button[i].time > BTN_TIME_HOLDED) {
|
|
|
+ if (Button[i].time >= BTN_TIME_HOLDED) {
|
|
|
Button[i].time -= BTN_TIME_REPEATED;
|
|
|
if (Button[i].holded == Button[i].pressed) {
|
|
|
// if pressed and holded - same function, then button pressed auto repeat
|
|
@@ -309,11 +308,13 @@ void showYear(void) {
|
|
|
}
|
|
|
|
|
|
void showBright(void) {
|
|
|
+ uint8_t a = Bright / 100;
|
|
|
+ uint8_t b = Bright - (a * 100);
|
|
|
DISP_WDT = DISP_WDT_TIME;
|
|
|
Digit[0] = DIGIT_BLANK;
|
|
|
- Digit[1] = 0x00;
|
|
|
- Digit[2] = RTC.Year >> 4;
|
|
|
- Digit[3] = RTC.Year & 0x0F;
|
|
|
+ Digit[1] = a;
|
|
|
+ Digit[2] = b / 10;
|
|
|
+ Digit[3] = b % 10;
|
|
|
}
|
|
|
|
|
|
void incWDay(void) {
|
|
@@ -374,14 +375,14 @@ void incBright(void) {
|
|
|
if (Bright < 0xFF) {
|
|
|
Bright ++;
|
|
|
} else {
|
|
|
- Bright = OCR2_MIN;
|
|
|
+ Bright = TIMER2_CNT;
|
|
|
}
|
|
|
OCR2 = Bright;
|
|
|
Flag.saveEEP = 1;
|
|
|
}
|
|
|
|
|
|
void decBright(void) {
|
|
|
- if (Bright > OCR2_MIN) {
|
|
|
+ if (Bright > TIMER2_CNT) {
|
|
|
Bright --;
|
|
|
} else {
|
|
|
Bright = 0xFF;
|