Hi,
I've been working on a project where I need to program a clock, read the values from a sensor, and create an alarm clock. I also need to save the values Alarm values in EEPROM, in case there's a reboot or the power goes out. I think I am done with almost all of it, but I just need to program something in the beginning so the program knows when to load the values from my CPP file.
My current approach is I create a count variable and have it increment. If the value is greater than 1, it loads the value. I am not sure if it would work, because I also initialize the value with 0 at the beginning and that's kind of bugging me right now. I'd be grateful if any of you could have a look at my "main" and let me know if it looks okay? If not, how else could I do it? Thank You in advance
#include <avr/io.h> #include <avr/interrupt.h> #include <avr/eeprom.h> #include "screen.h" #include "DigiPort.h" #include "Timer.h" static void ticker_clock(void); static void ticker_sensor(void); // Initializations Timer16 ticker (TC1, ticker_clock); Timer16 ticker2 (TC2, ticker_sensor); DigiPortRaw keys (PK, SET_IN_PORT); // Count Variable for EEPROM uint8_t count = 0; Clock TheClock; Sensor TheSensor; int main(void) { sei (); TheSensor.headline(); eeprom_update_byte((uint8_t *) 1, count); // Write the number stored in count in Memory cell 1 count = eeprom_read_byte((uint8_t *) 1); // Read the number stored in Memory cell and store in count if(count >= 1) { TheClock.show(); // It's only purpose is it show the alarm values saved in eeprom TheSensor.show(); } count++; ticker.start_ms(1000); ticker2.start_ms(5000); while (1) { switch(keys.read_raw()) { case 0b00000001: TheClock.set_time(1); break; case 0b00000010: TheClock.set_time(2); break; case 0b00000100: TheClock.set_time(3); break; case 0b00001000: TheClock.set_time(4); break; case 0b00010000: TheClock.set_time(5); break; case 0b00100000: TheSensor.set_temp_alarm(); break; case 0b01000000: TheSensor.convert_unit(); break; case 0b10000000: TheSensor.clear_temp_alarm(); TheClock.clear_alarm(); break; } } } void ticker_clock() { TheClock.callback();} void ticker_sensor() { TheSensor.get_measurement();}