WStevens_sa
Member level 2
- Joined
- Jan 5, 2011
- Messages
- 47
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- South Africa
- Activity points
- 1,695
Hi all
I have 877 programmed as RTC using TMR0. With individual timers for each day of the week. Each day has a start/stop timer (Day,Hour,Min) variable to compare to current (day, hour, min). I am using arrays for the variables. For example
timer_status is either 0= disabled, 1= enabled. Each day has its own timer. the "group" timer will default the whole week to one timer
timer_on will store the (day,hour,min) variable for when the timer must turn on. This is where I have run into a snag. I am not sure of what datatype I should store it as, as I need to compare it to the current (Day,hour,min) which has day as char and hours, min as int. These are the options I have thought of
Option 1. Convert and store both to char and do a text compare to turn timer on or off
Option 2. Convert the timer on / off values as hex. Then convert current day,hour to hex to compare.
Option 3. Shoot myself in the head
Option 4. See what everybody else thinks.
timer_of will store the day,hour and min the timer must switch off. Same problem as above
Below is hte partial code of the RTC
I have 877 programmed as RTC using TMR0. With individual timers for each day of the week. Each day has a start/stop timer (Day,Hour,Min) variable to compare to current (day, hour, min). I am using arrays for the variables. For example
timer_status is either 0= disabled, 1= enabled. Each day has its own timer. the "group" timer will default the whole week to one timer
int timer_status[8] = {0,0,0,0,0,0,0,0}; // mon,tue,wed,thu,fri,sat,sun,group
timer_on will store the (day,hour,min) variable for when the timer must turn on. This is where I have run into a snag. I am not sure of what datatype I should store it as, as I need to compare it to the current (Day,hour,min) which has day as char and hours, min as int. These are the options I have thought of
Option 1. Convert and store both to char and do a text compare to turn timer on or off
Option 2. Convert the timer on / off values as hex. Then convert current day,hour to hex to compare.
Option 3. Shoot myself in the head
Option 4. See what everybody else thinks.
int timer_on[8] = {0,0,0,0,0,0,0,0}; // store on day hour min eg Mon 13:45
timer_of will store the day,hour and min the timer must switch off. Same problem as above
int timer_off[8] = {0,0,0,0,0,0,0,0}; // store on day hour min eg Mon 13:45
Below is hte partial code of the RTC
void interrupt(void) {
if(T0IF_bit == 1){ // Check for interrupt flag
T0IF_bit=0; //Reset flag
counter++ ;
if(counter > 15625){ // 1 sec 16 Mhz crystal = 16000000 / 4 / 256
counter = 0 ;
seconds++ ;
if(seconds == 60){
seconds = 0 ;
minutes++ ;
if(minutes == 60){
minutes = 0 ;
hours++ ;
if(hours == 24){
hours = 0 ;
days++;
if (days == 7){
days = 0;
}
}
}
}
}
}
}
void main(void){
while(1){
//SECONDS
Lcd_Chr(1,12,48+(seconds % 10)); // seconds counter LSB
Lcd_Chr(1,11,48+((seconds /10) % 10)); //Seconds counter MSB
//MINUTES
Lcd_Chr(1,9,48+(minutes % 10)); // minutes counter LSB
Lcd_Chr(1,8,48+((minutes /10) % 10)); //minutes counter MSB
//HOURS
Lcd_Chr(1,6,48+(hours % 10)); // hours counter LSB
Lcd_Chr(1,5,48+((hours /10) % 10)); // hours counter MSB
//DAYS
Lcd_out(1,1,weekdays[days]); // days of the week
}
}