|
@@ -13,11 +13,22 @@
|
|
/* Defines */
|
|
/* Defines */
|
|
|
|
|
|
/* Variables */
|
|
/* Variables */
|
|
|
|
+static volatile struct {
|
|
|
|
+ uint8_t newTempSet: 1;
|
|
|
|
+ uint8_t AHT10state: 1;
|
|
|
|
+ uint8_t rezerv: 6;
|
|
|
|
+} Flag;
|
|
|
|
+uint8_t TemperatureSetpoint;
|
|
|
|
+aht10_t Sensor;
|
|
|
|
|
|
/* Function prototypes */
|
|
/* Function prototypes */
|
|
static void board_Init(void);
|
|
static void board_Init(void);
|
|
|
|
+static void checkTemperatureSetpoint(void);
|
|
|
|
+static void sensorStart(void);
|
|
|
|
+static void sensorGetData(void);
|
|
|
|
|
|
int main(void) {
|
|
int main(void) {
|
|
|
|
+ /* Init all */
|
|
board_Init();
|
|
board_Init();
|
|
RTOS_Init();
|
|
RTOS_Init();
|
|
I2C_Init();
|
|
I2C_Init();
|
|
@@ -25,9 +36,17 @@ int main(void) {
|
|
tdelay_ms(40);
|
|
tdelay_ms(40);
|
|
ssd1306_init();
|
|
ssd1306_init();
|
|
|
|
|
|
|
|
+ /* Clear flags */
|
|
|
|
+ Flag.newTempSet = 0;
|
|
|
|
+ Flag.AHT10state = 0;
|
|
|
|
+
|
|
|
|
+ /* Set tasks */
|
|
|
|
+ RTOS_SetTask(checkTemperatureSetpoint, 10, 100);
|
|
|
|
+ RTOS_SetTask(sensorStart, 50, 1000);
|
|
|
|
+ RTOS_SetTask(sensorGetData, 1050, 1000);
|
|
|
|
+
|
|
// ssd1306_clear();
|
|
// ssd1306_clear();
|
|
- ssd1306_fill2(0xff, 0x00);
|
|
|
|
- tdelay_ms(2500);
|
|
|
|
|
|
+// ssd1306_fill2(0xff, 0x00);
|
|
ssd1306_clear();
|
|
ssd1306_clear();
|
|
ssd1306tx_init(ssd1306xled_font6x8data, 0);
|
|
ssd1306tx_init(ssd1306xled_font6x8data, 0);
|
|
// ssd1306xled_font8x16data
|
|
// ssd1306xled_font8x16data
|
|
@@ -39,23 +58,24 @@ int main(void) {
|
|
ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 0, 5, "TINUSAUR Project");
|
|
ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 0, 5, "TINUSAUR Project");
|
|
ssd1306_setpos(0, 7);
|
|
ssd1306_setpos(0, 7);
|
|
ssd1306tx_string("http://tinusaur.org");
|
|
ssd1306tx_string("http://tinusaur.org");
|
|
|
|
+ tdelay_ms(1000);
|
|
|
|
|
|
- RTOS_SetTask((void *)AHT10_StartMeasure, 0, 500);
|
|
|
|
- aht10_t Sensor;
|
|
|
|
- aht10_st_t status;
|
|
|
|
-
|
|
|
|
|
|
+ /* Infinity loop */
|
|
do {
|
|
do {
|
|
|
|
+ if (Flag.newTempSet != 0) {
|
|
|
|
+ Flag.newTempSet = 0;
|
|
|
|
+ // do some ...
|
|
|
|
+ }
|
|
|
|
|
|
- RTOS_DispatchTask();
|
|
|
|
-
|
|
|
|
- status = AHT10_StartMeasure();
|
|
|
|
- tdelay_ms(200);
|
|
|
|
- status = AHT10_GetData(&Sensor);
|
|
|
|
- if (status == AHT10_St_OK) {
|
|
|
|
- ssd1306_setpos(1, 3);
|
|
|
|
|
|
+ ssd1306_setpos(1, 3);
|
|
|
|
+ if (Flag.AHT10state == 0) {
|
|
ssd1306tx_numdec(Sensor.Temperature);
|
|
ssd1306tx_numdec(Sensor.Temperature);
|
|
|
|
+ } else {
|
|
|
|
+ ssd1306tx_string("AHT10 error");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ RTOS_DispatchTask();
|
|
|
|
+
|
|
// делать нечего -- спим, ждём прерывание
|
|
// делать нечего -- спим, ждём прерывание
|
|
#if defined(__GNUC__)
|
|
#if defined(__GNUC__)
|
|
set_sleep_mode(SLEEP_MODE_IDLE);
|
|
set_sleep_mode(SLEEP_MODE_IDLE);
|
|
@@ -78,13 +98,12 @@ static void board_Init(void) {
|
|
/* power off Analog Comparator */
|
|
/* power off Analog Comparator */
|
|
ACSR = ACD;
|
|
ACSR = ACD;
|
|
|
|
|
|
- /* I/O-Ports */
|
|
|
|
- DDRB = 0x22; // PB2 - Triac control, PB5 - Green LED
|
|
|
|
|
|
+ /* GPIO */
|
|
|
|
+ DDRB = 0x22; // PB1 - Triac control, PB5 - Green LED
|
|
DDRC = 0x30; // I2C output
|
|
DDRC = 0x30; // I2C output
|
|
- DDRD = 0x03; // D2..D7 input / UART output
|
|
|
|
- PORTB = 0x02; // close Triac
|
|
|
|
|
|
+ PORTB = 0x03; // close Triac, enable pull-up for D8
|
|
PORTC = 0x3e; // I2C = 1, enable pull-up for switch
|
|
PORTC = 0x3e; // I2C = 1, enable pull-up for switch
|
|
- PORTD = 0xfc; // enable pull-up for switch
|
|
|
|
|
|
+ PORTD = 0xfc; // enable pull-up for D0-D7 (Switch)
|
|
|
|
|
|
/* Timer0 - RTOS & tdelay_ms() */
|
|
/* Timer0 - RTOS & tdelay_ms() */
|
|
TCCR0B = ((0<<CS02)|(1<<CS01)|(1<<CS00));
|
|
TCCR0B = ((0<<CS02)|(1<<CS01)|(1<<CS00));
|
|
@@ -98,28 +117,81 @@ static void board_Init(void) {
|
|
//TCNT2 = 0x00;
|
|
//TCNT2 = 0x00;
|
|
//TIMSK |= _BV(TOIE2);
|
|
//TIMSK |= _BV(TOIE2);
|
|
|
|
|
|
-#ifdef USE_UART
|
|
|
|
- /* USART */
|
|
|
|
- DDRD |= _BV(PD0); // RX to Input
|
|
|
|
- // Set baud rate
|
|
|
|
- UBRRH = (BAUD_PRESCALE >> 8);
|
|
|
|
- UBRRL = BAUD_PRESCALE;
|
|
|
|
- #if (BAUD_U2X != 0)
|
|
|
|
- // Asynchronous Double Speed
|
|
|
|
- UCSRA = 1 << U2X;
|
|
|
|
- #endif // BAUD_U2X
|
|
|
|
- // Turn on USART hardware (no RX, TX)
|
|
|
|
- UCSRB = (1 << RXEN) | (1 << TXEN);
|
|
|
|
- // 8 bit char sizes, 1 stop bit
|
|
|
|
- //UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); -- default value
|
|
|
|
-#endif // USE_UART
|
|
|
|
-
|
|
|
|
/* Enable Interrupts */
|
|
/* Enable Interrupts */
|
|
-#if defined(__GNUC__)
|
|
|
|
- sei();
|
|
|
|
-#elif defined(__ICCAVR__)
|
|
|
|
- __enable_interrupt();
|
|
|
|
-#endif
|
|
|
|
|
|
+ ENABLE_INTERRUPT;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void checkTemperatureSetpoint(void) {
|
|
|
|
+ static uint8_t oldTempSet = 0;
|
|
|
|
+ uint8_t pvalue;
|
|
|
|
+
|
|
|
|
+ pvalue = ~(PIND);
|
|
|
|
+ if (pvalue != 0) {
|
|
|
|
+ switch (pvalue) {
|
|
|
|
+ case 1<<PB0:
|
|
|
|
+ TemperatureSetpoint = 55;
|
|
|
|
+ break;
|
|
|
|
+ case 1<<PB1:
|
|
|
|
+ TemperatureSetpoint = 50;
|
|
|
|
+ break;
|
|
|
|
+ case 1<<PB2:
|
|
|
|
+ TemperatureSetpoint = 60;
|
|
|
|
+ break;
|
|
|
|
+ case 1<<PB3:
|
|
|
|
+ TemperatureSetpoint = 65;
|
|
|
|
+ break;
|
|
|
|
+ case 1<<PB4:
|
|
|
|
+ TemperatureSetpoint = 70;
|
|
|
|
+ break;
|
|
|
|
+ case 1<<PB5:
|
|
|
|
+ TemperatureSetpoint = 75;
|
|
|
|
+ break;
|
|
|
|
+ case 1<<PB6:
|
|
|
|
+ TemperatureSetpoint = 80;
|
|
|
|
+ break;
|
|
|
|
+ case 1<<PB7:
|
|
|
|
+ TemperatureSetpoint = 85;
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ TemperatureSetpoint = 0;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ pvalue = ~(PINB) | (1<<PB0);
|
|
|
|
+ if (pvalue != 0) {
|
|
|
|
+ TemperatureSetpoint = 90;
|
|
|
|
+ } else {
|
|
|
|
+ TemperatureSetpoint = 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (oldTempSet != TemperatureSetpoint) {
|
|
|
|
+ Flag.newTempSet = 1;
|
|
|
|
+ oldTempSet = TemperatureSetpoint;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void sensorStart(void) {
|
|
|
|
+ aht10_st_t status;
|
|
|
|
+
|
|
|
|
+ status = AHT10_StartMeasure();
|
|
|
|
+
|
|
|
|
+ if (status != AHT10_St_OK) {
|
|
|
|
+ Flag.AHT10state = 1;
|
|
|
|
+ } else {
|
|
|
|
+ Flag.AHT10state = 0;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void sensorGetData(void) {
|
|
|
|
+ aht10_st_t status;
|
|
|
|
+
|
|
|
|
+ status = AHT10_GetData(&Sensor);
|
|
|
|
+
|
|
|
|
+ if (status != AHT10_St_OK) {
|
|
|
|
+ Flag.AHT10state = 1;
|
|
|
|
+ } else {
|
|
|
|
+ Flag.AHT10state = 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|