|
@@ -22,11 +22,13 @@
|
|
|
static volatile struct {
|
|
|
uint8_t newTempSet: 1;
|
|
|
uint8_t AHT10state: 1;
|
|
|
- uint8_t rezerv: 6;
|
|
|
+ uint8_t ClockRun: 1;
|
|
|
+ uint8_t rezerv: 5;
|
|
|
} Flag;
|
|
|
-static uint8_t TemperatureSetpoint = 0;
|
|
|
+static uint8_t TemperatureSetpoint = 0, oldTempSet = 0;
|
|
|
static aht20_t Sensor;
|
|
|
static bresenham_t Heater;
|
|
|
+static clock_t Clock = {0};
|
|
|
|
|
|
/* Function prototypes */
|
|
|
static void board_Init(void);
|
|
@@ -38,6 +40,11 @@ static void LedOff(void);
|
|
|
static void HeaterCtrl(void);
|
|
|
|
|
|
int main(void) {
|
|
|
+ /* Clear flags */
|
|
|
+ Flag.newTempSet = 1;
|
|
|
+ Flag.AHT10state = 0;
|
|
|
+ Flag.ClockRun = 0;
|
|
|
+
|
|
|
/* Init all */
|
|
|
board_Init();
|
|
|
RTOS_Init();
|
|
@@ -46,10 +53,6 @@ int main(void) {
|
|
|
tdelay_ms(40);
|
|
|
ssd1306_init();
|
|
|
|
|
|
- /* Clear flags */
|
|
|
- Flag.newTempSet = 1;
|
|
|
- Flag.AHT10state = 0;
|
|
|
-
|
|
|
/* Bresenham init.
|
|
|
* step - 10 ms, period - 1 sek, heater - off */
|
|
|
bresenham_Init(&Heater, HEATER_POWER_MAX);
|
|
@@ -73,41 +76,69 @@ int main(void) {
|
|
|
tdelay_ms(1000);
|
|
|
|
|
|
ssd1306_clear();
|
|
|
- ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 0, "Pwr:"); // Set
|
|
|
- ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 3, " T:");
|
|
|
- ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 5, " H:");
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 8, 0, "Pwr:"); // Set
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 8, 2, " T: xx.x C");
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 8, 4, " H: yy.y %");
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 48, 6, ": :");
|
|
|
char buffer[9] = {0};
|
|
|
- uint8_t digits = 0;
|
|
|
+ uint8_t i = 0, d = 0;
|
|
|
|
|
|
/* Infinity loop */
|
|
|
do {
|
|
|
-
|
|
|
- if (Flag.newTempSet != 0) {
|
|
|
- Flag.newTempSet = 0;
|
|
|
- if (TemperatureSetpoint != 0) {
|
|
|
- digits = usint2decascii(TemperatureSetpoint, buffer);
|
|
|
- strncpy(buffer+5, " % \0", 4); // C
|
|
|
- ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 0, buffer+digits);
|
|
|
- } else {
|
|
|
- ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 0, " Off");
|
|
|
+ /* Action for new temperature setting */
|
|
|
+ if (Flag.newTempSet != 0) {
|
|
|
+ Flag.newTempSet = 0;
|
|
|
+ if (TemperatureSetpoint != 0) {
|
|
|
+ if (oldTempSet == 0) {
|
|
|
+ Flag.ClockRun = 1;
|
|
|
+ Clock.SS = 0;
|
|
|
+ Clock.MM = 0;
|
|
|
+ Clock.HH = 0;
|
|
|
+ }
|
|
|
+ usint2decascii(TemperatureSetpoint, buffer);
|
|
|
+ strncpy(buffer+5, " % \0", 4); // C
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 48, 0, buffer+3);
|
|
|
+ } else {
|
|
|
+ Flag.ClockRun = 0;
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 48, 0, " Off");
|
|
|
+ }
|
|
|
+ // set new Heater Power
|
|
|
+ bresenham_setValue(&Heater, TemperatureSetpoint);
|
|
|
}
|
|
|
- // set new Heater Power
|
|
|
- bresenham_setValue(&Heater, TemperatureSetpoint);
|
|
|
- }
|
|
|
|
|
|
+ /* Output Sensor Data */
|
|
|
if (Flag.AHT10state == 0) {
|
|
|
- digits = usint2decascii(Sensor.Temperature, buffer);
|
|
|
- strncpy(buffer+5, " C\0", 3);
|
|
|
- ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 3, buffer+digits);
|
|
|
-
|
|
|
- digits = usint2decascii(Sensor.Humidity, buffer);
|
|
|
- strncpy(buffer+5, " %\0", 3);
|
|
|
- ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 5, buffer+digits);
|
|
|
+ strncpy(buffer, "\0", 6);
|
|
|
+ i = Sensor.Temperature / 10;
|
|
|
+ d = Sensor.Temperature % 10;
|
|
|
+ usint2decascii(i, buffer);
|
|
|
+ //strncpy(buffer+5, " C\0", 3);
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 48, 2, buffer+3);
|
|
|
+ usint2decascii(d, buffer);
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 72, 2, buffer+4);
|
|
|
+
|
|
|
+ strncpy(buffer, "\0", 6);
|
|
|
+ i = Sensor.Humidity / 10;
|
|
|
+ d = Sensor.Humidity % 10;
|
|
|
+ usint2decascii(i, buffer);
|
|
|
+ //strncpy(buffer+5, " %\0", 3);
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 48, 4, buffer+3);
|
|
|
+ usint2decascii(d, buffer);
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 72, 4, buffer+4);
|
|
|
} else {
|
|
|
- ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 3, " I2C ");
|
|
|
- ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 5, "Error");
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 48, 2, "Er");
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 48, 4, "Er");
|
|
|
}
|
|
|
|
|
|
+ /* Output Clock */
|
|
|
+ strncpy(buffer, "\0", 6);
|
|
|
+ usint2decascii(Clock.HH, buffer);
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 32, 6, buffer+3);
|
|
|
+ usint2decascii(Clock.MM, buffer);
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 56, 6, buffer+3);
|
|
|
+ usint2decascii(Clock.SS, buffer);
|
|
|
+ ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 80, 6, buffer+3);
|
|
|
+
|
|
|
RTOS_DispatchTask();
|
|
|
|
|
|
// nothing to do - sleep, wait for interrupt
|
|
@@ -144,7 +175,10 @@ static void board_Init(void) {
|
|
|
TCNT0 = TIMER0_CNT;
|
|
|
TIMSK0 |= (1<<TOIE0);
|
|
|
|
|
|
- /* Timer1 */
|
|
|
+ /* Timer1 - Clock */
|
|
|
+ TCCR1B = (1<<CS12 | 0<<CS11 | 1<<CS10);
|
|
|
+ TCNT1 = TIMER1_CNT;
|
|
|
+ TIMSK1 |= (1<<TOIE1);
|
|
|
|
|
|
/* Timer2 - refresh screen values */
|
|
|
//TCCR2 = 0x00;
|
|
@@ -159,7 +193,7 @@ static void board_Init(void) {
|
|
|
* Setup Temperature Set Point by valcoder value
|
|
|
*/
|
|
|
static void checkTemperatureSetpoint(void) {
|
|
|
- static uint8_t oldTempSet = 0;
|
|
|
+ static uint8_t prev = 0;
|
|
|
uint8_t pvalue;
|
|
|
|
|
|
pvalue = ~(PIND);
|
|
@@ -201,9 +235,10 @@ static void checkTemperatureSetpoint(void) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (oldTempSet != TemperatureSetpoint) {
|
|
|
+ if (prev != TemperatureSetpoint) {
|
|
|
Flag.newTempSet = 1;
|
|
|
- oldTempSet = TemperatureSetpoint;
|
|
|
+ oldTempSet = prev;
|
|
|
+ prev = TemperatureSetpoint;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -253,6 +288,30 @@ static void HeaterCtrl(void) {
|
|
|
/**
|
|
|
* I n t e r r u p t s
|
|
|
*/
|
|
|
+#if defined(__ICCAVR__)
|
|
|
+#pragma vector=TIMER1_OVF_vect
|
|
|
+__interrupt void TIMER1_OVF_ISR(void)
|
|
|
+#elif defined(__GNUC__)
|
|
|
+ISR(TIMER1_OVF_vect)
|
|
|
+#endif
|
|
|
+{
|
|
|
+ /* reload timer counter */
|
|
|
+ TCNT1 = TIMER1_CNT;
|
|
|
+
|
|
|
+ /* Clock */
|
|
|
+ if (Flag.ClockRun != 0) {
|
|
|
+ Clock.SS ++;
|
|
|
+ if (Clock.SS > 59) {
|
|
|
+ Clock.SS = 0;
|
|
|
+ Clock.MM ++;
|
|
|
+ if (Clock.MM > 59) {
|
|
|
+ Clock.MM = 0;
|
|
|
+ Clock.HH ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#if defined(__GNUC__)
|
|
|
/**
|
|
|
* @brief заглушка для неиспользуемых прерываний
|