??? 10/19/10 01:39 Read: times |
#179182 - Segment your Application Responding to: ???'s previous message |
Your application is easily achieved, but you need to break it down into manageable chunks.
1, Develop your RTC, if you are using external RTC then make sure you know the drift and can compensate for it, if you are making your own 1Hz Tick this is fine as well, just make sure you can adjust the ticks to give 1Hz accuratly, if it runs for any period of time at a temperature other than 20degC (or there abouts) the Xtal tolerance will slow down, (I don't think they go faster) 2, once you have a 1Hz Tick, then you have to count the ticks to make a clock. 3, once you have a clock you have to count the days to make a calendar (if this required) 4, when you have a calendar you need a look up table of alarms to see when you get a match on your calendar. In the lookup table have one (or more) extra fields that defines which relay / port will be activated / deactivated when you get a match, Here is my Calendar event matcher function for the above, I'm sure that it will be critiqued by everyone, but it does work. I have additionally implemented wildcards in my lookup table (which are values 99) so that I can have a repeating alarm, by entering 99 where I want a catch all. In this manner I can have an alarm activate only on a single Saturday, or every saturday, or every saturday in 2010, etc. Hope it helps, regards. Marshall void funCheckCalendarEvents(void){ idata unsigned int i = 0; idata static unsigned char relay_bits = 0; idata unsigned char relay_num = 0; idata unsigned char on_off= 0; for (i=0; i<=CALENDAR_RECORDS; i++){ //check all records for a match funCalendarRead (i); if (c.reg.control != 0xFF){ //if the control field is unset then ditch the whole record. if (c.reg.year == Year || c.reg.year == CALENDAR_MASK){ if (c.reg.month == Month || c.reg.month == CALENDAR_MASK){ if (c.reg.date == Date || c.reg.date == CALENDAR_MASK){ if (c.reg.dayofweek == Day || c.reg.dayofweek == CALENDAR_MASK){ if (c.reg.hours == Hours || c.reg.hours == CALENDAR_MASK){ if (c.reg.minutes == Minutes || c.reg.minutes == CALENDAR_MASK){ printf("Match @ entry %04d ", (unsigned int) i); printf("%02d:%02d ",(unsigned int)Hours, (unsigned int)Minutes); printf("on %02d.%02d.20%02d", (unsigned int)Date,(unsigned int)Month, (unsigned int)Year); printf("tMask is "); if (c.reg.hours == CALENDAR_MASK) printf("--:"); else printf("%02d:",(unsigned int)c.reg.hours); if (c.reg.minutes == CALENDAR_MASK) printf("-- on "); else printf("%02d on ",(unsigned int)c.reg.minutes); if (c.reg.dayofweek == CALENDAR_MASK) printf("--- "); else printf("%s ",day_names[c.reg.dayofweek]); if (c.reg.date == CALENDAR_MASK) printf("--."); else printf("%02d.",(unsigned int)c.reg.date); if (c.reg.month == CALENDAR_MASK) printf("--."); else printf("%02d." ,(unsigned int)c.reg.month); if (c.reg.year == CALENDAR_MASK) printf("20-- "); else printf("20%02d " , (unsigned int)c.reg.year); relay_num = c.reg.control & 0x0F; on_off = (c.reg.control & 0xC0) >> 6; printf(" relay %02d " , relay_num); if (on_off == 1) printf("On"); if (on_off == 0) printf("Off"); if (on_off == 2) printf("Toggle"); printf("rn"); if (relay_num <=8) { on_off = on_off << (relay_num -1); if (on_off != 0){ //then shift it the correct number of places then OR it relay_bits |= on_off; } else { //shift if the correct number of places then AND it relay_bits &= on_off; } } } } } } } } } } //only after we have checked all the records should we start the control functions //in this manner we are not inadvertently turning the outputs on and off in the same //minute. funActivateControl(relay_bits); } |
Topic | Author | Date |
8051 alarm clock | 01/01/70 00:00 | |
Large number of alarms | 01/01/70 00:00 | |
Design Really Needed | 01/01/70 00:00 | |
two things | 01/01/70 00:00 | |
Segment your Application | 01/01/70 00:00 | |
Incremental work | 01/01/70 00:00 | |
date means date. | 01/01/70 00:00 | |
an interesting anecdote | 01/01/70 00:00 | |
Definitely keep a table | 01/01/70 00:00 | |
I wouldn't rely on that | 01/01/70 00:00 | |
No SMS for setting clock | 01/01/70 00:00 | |
thank for the help on my project | 01/01/70 00:00 | |
Options | 01/01/70 00:00 |