void main(void) { initIO(); initOscillator(); initTimer(); while (1) { /* Check to see if the timer has counted beyond 32768 */ if (TMR1H == 0x80) { // reset the timer TMR1H = 0; TMR1L = 0; incrementSeconds(); } /* Check for button input */ // all buttons are active low if (TMR0 >= (unsigned) 192) { if (oldButtonS == 0 && _button_s == 1) second = 0; if (oldButtonM == 0 && _button_m == 1) incrementMinutes(); if (oldButtonH == 0 && _button_h == 1) incrementHours(); oldButtonS = _button_s; oldButtonM = _button_m; oldButtonH = _button_h; } /* Update display */ updateDisplay(); } }
void changeHours(struct tm *dt) { unsigned int buttonsState; unsigned int nextState; LCD_Clear(); LCD_Goto(0,1); LCD_WriteString(str1); while(nextState != SET_HOURS) { buttonsState = Button_Read(); nextState = decodeButtons_inHours(buttonsState); //Actualizar o LCD para os novos valores das horas LCD_Goto(0,0); strftime(buffer,16,"%T",dt); LCD_WriteString(buffer); switch(nextState) { case INC_HOURS: LCD_Goto(0,1); incrementHours(dt); break; case DEC_HOURS: LCD_Goto(0,1); decrementHours(dt); break; case INC_MINUTES: incrementMinutes(dt); break; case DEC_MINUTES: decrementMinutes(dt); break; case CHANGE_FIELD: actualPosition = (actualPosition + 1)%LEN_ENUM; break; default: break; } } RTC_SetTime(dt); RTC_SetDate(dt); RTC_SetDays(dt); LCD_Clear(); }
void incrementMinutes(void) { if (minute == 59) { minute = 0; incrementHours(); } else minute++; }