|
@@ -18,14 +18,19 @@
|
|
#include "ds3231.h"
|
|
#include "ds3231.h"
|
|
#include "rtos.h"
|
|
#include "rtos.h"
|
|
#include "event-system.h"
|
|
#include "event-system.h"
|
|
-#include "common.h"
|
|
|
|
#include "main.h"
|
|
#include "main.h"
|
|
|
|
+#include "common.h"
|
|
|
|
|
|
/* Defines */
|
|
/* Defines */
|
|
/* Timer2 settings */
|
|
/* Timer2 settings */
|
|
-#define TIMER2_HZ 400
|
|
|
|
-#define TIMER2_PRESCALER 1024
|
|
|
|
-#define TIMER2_CS (1<<CS22 | 1<<CS21 | 1<<CS20)
|
|
|
|
|
|
+#define TIMER2_HZ 600
|
|
|
|
+#if F_CPU == 16000000
|
|
|
|
+ #define TIMER2_PRESCALER 256
|
|
|
|
+ #define TIMER2_CS (1<<CS22 | 0<<CS21 | 0<<CS20)
|
|
|
|
+#elif F_CPU == 8000000
|
|
|
|
+ #define TIMER2_PRESCALER 64
|
|
|
|
+ #define TIMER2_CS (0<<CS22 | 1<<CS21 | 1<<CS20)
|
|
|
|
+#endif // F_CPU
|
|
#define TIMER2_CNT (0x100 - (F_CPU / TIMER2_PRESCALER / TIMER2_HZ))
|
|
#define TIMER2_CNT (0x100 - (F_CPU / TIMER2_PRESCALER / TIMER2_HZ))
|
|
|
|
|
|
/* Display timeout, sec */
|
|
/* Display timeout, sec */
|
|
@@ -41,12 +46,19 @@
|
|
#endif // USE_UART
|
|
#endif // USE_UART
|
|
|
|
|
|
#ifdef USE_BRIGHT_CONTROL
|
|
#ifdef USE_BRIGHT_CONTROL
|
|
|
|
+//static void startADC(void);
|
|
|
|
+//volatile uint8_t resultADC = 0;
|
|
/* Lamp brightness */
|
|
/* Lamp brightness */
|
|
#define BRIGHT_IDX_MAX 4
|
|
#define BRIGHT_IDX_MAX 4
|
|
|
|
+#define LIGHT_LEVEL 100
|
|
#define FULL_BRIGHT_ON 0x06
|
|
#define FULL_BRIGHT_ON 0x06
|
|
#define FULL_BRIGHT_OFF 0x22
|
|
#define FULL_BRIGHT_OFF 0x22
|
|
static const uint8_t PROGMEM brightConv[BRIGHT_IDX_MAX+1] = {
|
|
static const uint8_t PROGMEM brightConv[BRIGHT_IDX_MAX+1] = {
|
|
- 218, 225, 230, 240, 255
|
|
|
|
|
|
+#if F_CPU == 16000000
|
|
|
|
+ 155, 164, 181, 211, 255
|
|
|
|
+#elif F_CPU == 8000000
|
|
|
|
+ 54, 71, 106, 165, 255
|
|
|
|
+#endif // F_CPU
|
|
};
|
|
};
|
|
#endif // USE_BRIGHT_CONTROL
|
|
#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
@@ -129,9 +141,12 @@ void main(void) {
|
|
/* Initialize Event State Machine */
|
|
/* Initialize Event State Machine */
|
|
ES_Init(stShowTime);
|
|
ES_Init(stShowTime);
|
|
|
|
|
|
- showTime();
|
|
|
|
-
|
|
|
|
RTOS_SetTask(btnProcess, 3, BTN_SCAN_PERIOD);
|
|
RTOS_SetTask(btnProcess, 3, BTN_SCAN_PERIOD);
|
|
|
|
+#ifdef USE_BRIGHT_CONTROL
|
|
|
|
+// RTOS_SetTask(startADC, 10, 500);
|
|
|
|
+#endif // USE_BRIGHT_CONTROL
|
|
|
|
+
|
|
|
|
+ showTime();
|
|
|
|
|
|
/** main loop */
|
|
/** main loop */
|
|
do {
|
|
do {
|
|
@@ -150,6 +165,7 @@ void main(void) {
|
|
}
|
|
}
|
|
#ifdef USE_BRIGHT_CONTROL
|
|
#ifdef USE_BRIGHT_CONTROL
|
|
if (RTC.Hr >= FULL_BRIGHT_ON && RTC.Hr < FULL_BRIGHT_OFF) {
|
|
if (RTC.Hr >= FULL_BRIGHT_ON && RTC.Hr < FULL_BRIGHT_OFF) {
|
|
|
|
+// if (resultADC < LIGHT_LEVEL) {
|
|
OCR2 = pgm_read_byte(&brightConv[BRIGHT_IDX_MAX]);
|
|
OCR2 = pgm_read_byte(&brightConv[BRIGHT_IDX_MAX]);
|
|
} else {
|
|
} else {
|
|
OCR2 = pgm_read_byte(&brightConv[brightIdx]);
|
|
OCR2 = pgm_read_byte(&brightConv[brightIdx]);
|
|
@@ -210,6 +226,10 @@ static void Board_Init(void) {
|
|
TIMSK = _BV(TOIE2);
|
|
TIMSK = _BV(TOIE2);
|
|
|
|
|
|
#ifdef USE_BRIGHT_CONTROL
|
|
#ifdef USE_BRIGHT_CONTROL
|
|
|
|
+ /* ADC init */
|
|
|
|
+// ADMUX = (1<<REFS0 | 1<<ADLAR | 1<<MUX2 | 1<<MUX1 | 1<<MUX0); // Vref = AVcc, channel ADC7, Left adjusted result
|
|
|
|
+// ADCSRA = (1<<ADEN | 1<<ADSC | 1<<ADIE | 1<<ADPS2 | 1<<ADPS1 | 1<<ADPS0); // enable ADC, prescaler = 128
|
|
|
|
+
|
|
OCR2 = pgm_read_byte(&brightConv[BRIGHT_IDX_MAX]);
|
|
OCR2 = pgm_read_byte(&brightConv[BRIGHT_IDX_MAX]);
|
|
TIMSK |= _BV(OCIE2);
|
|
TIMSK |= _BV(OCIE2);
|
|
#endif // USE_BRIGHT_CONTROL
|
|
#endif // USE_BRIGHT_CONTROL
|
|
@@ -309,6 +329,14 @@ static void btnProcess(void) {
|
|
}
|
|
}
|
|
|
|
|
|
void showTime(void) {
|
|
void showTime(void) {
|
|
|
|
+/*
|
|
|
|
+ Digit[0] = DIGIT_BLANK;
|
|
|
|
+ Digit[1] = DIGIT_BLANK;
|
|
|
|
+ Digit[2] = DIGIT_BLANK;
|
|
|
|
+ Digit[3] = resultADC / 100;
|
|
|
|
+ Digit[4] = (resultADC % 100) / 10;
|
|
|
|
+ Digit[5] = resultADC % 10;
|
|
|
|
+*/
|
|
dotOn();
|
|
dotOn();
|
|
RTOS_SetTask(dotOff, 500, 0);
|
|
RTOS_SetTask(dotOff, 500, 0);
|
|
|
|
|
|
@@ -352,8 +380,10 @@ void showBright(void) {
|
|
|
|
|
|
Digit[0] = DIGIT_BLANK;
|
|
Digit[0] = DIGIT_BLANK;
|
|
Digit[1] = DIGIT_BLANK;
|
|
Digit[1] = DIGIT_BLANK;
|
|
- Digit[2] = brightIdx;
|
|
|
|
- Digit[3] = DIGIT_BLANK;
|
|
|
|
|
|
+ Digit[2] = DIGIT_BLANK;
|
|
|
|
+ Digit[3] = brightIdx;
|
|
|
|
+ Digit[4] = DIGIT_BLANK;
|
|
|
|
+ Digit[5] = DIGIT_BLANK;
|
|
}
|
|
}
|
|
|
|
|
|
void incBright(void) {
|
|
void incBright(void) {
|
|
@@ -371,6 +401,11 @@ void decBright(void) {
|
|
Flag.saveEEP = 1;
|
|
Flag.saveEEP = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+/*
|
|
|
|
+static void startADC(void) {
|
|
|
|
+ // enable interrupt and start conversion
|
|
|
|
+ ADCSRA |= ((1<<ADSC) | (1<<ADIE));
|
|
|
|
+}*/
|
|
#endif // USE_BRIGHT_CONTROL
|
|
#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
static void blink(void) {
|
|
static void blink(void) {
|
|
@@ -809,6 +844,11 @@ ISR(TIMER2_COMP_vect) {
|
|
PORTD &= ~ANODD_PINS;
|
|
PORTD &= ~ANODD_PINS;
|
|
PORTC &= ~DIGIT_PINS;
|
|
PORTC &= ~DIGIT_PINS;
|
|
}
|
|
}
|
|
|
|
+/*
|
|
|
|
+ISR(ADC_vect) {
|
|
|
|
+ resultADC = ADCH;
|
|
|
|
+ ADCSRA &= ~(1<<ADIE); // disable interrupt
|
|
|
|
+}*/
|
|
#endif // USE_BRIGHT_CONTROL
|
|
#endif // USE_BRIGHT_CONTROL
|
|
|
|
|
|
/**
|
|
/**
|