diff options
| -rwxr-xr-x | main.c | 58 | 
1 files changed, 50 insertions, 8 deletions
| @@ -105,11 +105,11 @@ void main(void) {       * Set an initial date time via initial program variables
       * Currently 00:00:00 1/1/00 and Sunday (day of week as 1)
       */
 -    
 +
      //Set_Time();
      //Set_Date();
      //Set_DayOfWeek(Get_DayOfWeek(year, month, date));
 -    
 +
      /*
       * isr expects 1Hz clock from RTC. This will update clock each second
       * While interrupted, clock is updating and set button will be ignored.
 @@ -235,18 +235,21 @@ void format_Temperature() {  }
  // Determine Alarm status from control register 0Fh bits 0 (A1F) and 1 (A2F)
 +
  void Get_Alarm_Status() {
      alarm1_status = control_reg & 0x01; // Read alarm1 A1F bit
      alarm2_status = (control_reg >> 1) & 0x01; // Read alarm2 A2F bit
  }
  // Separate data into tens and ones units to display with character displays
 +
  void display_Digit(unsigned int data) {
      Lcd_Write_Char(MSB(data));
      Lcd_Write_Char(LSB(data));
  }
  // Provides the user program info on startup
 +
  void display_Intro() {
      // Give an intro message on the LCD
      Lcd_Clear();
 @@ -332,6 +335,10 @@ void update_Display() {   * edit flag is cleared and clock continues as normal. Sets :'s to display for
   * time in case they were blanked.
   * 
 + * Change detection variables are set before values are changed and compared
 + * as user goes through fields. If a change is detected then updateRTC flag is
 + * enabled causing the RTC to be updated.
 + * 
   * As month/date is selected, functions determine if year is leap or not,
   * the max number of days in each month, and displays the day of the week.
   * ex: 29/02/2020 is Sat and leap year with max date to select in Feb as 29.
 @@ -341,6 +348,18 @@ void update_Display() {   */
  void edit_Date_Time(void) {
 +    // Variable to determine if RTC is updated or not (date/time valus change)
 +    int updateRTC = 0;
 +
 +    // Variables set to current edit value and if a mismatch from user input
 +    // then updateRTC is set to 1 and RTC will be updated
 +    unsigned int hour_org = hour;
 +    unsigned int min_org = min;
 +    unsigned int sec_org = sec;
 +    unsigned int year_org = year;
 +    unsigned int month_org = month;
 +    unsigned int date_org = date;
 +
      Lcd_Set_Cursor(2, 16);
      Lcd_Write_Char('S');
      edit_datetime++;
 @@ -377,7 +396,10 @@ void edit_Date_Time(void) {                      Lcd_Set_Cursor(1, 1);
                      display_Digit(hour);
                  }
 +                updateRTC |= (hour_org == hour);
 +
                  break;
 +
              case 2: //Minutes
                  Lcd_Set_Cursor(2, 16);
                  Lcd_Write_Char('m');
 @@ -402,6 +424,8 @@ void edit_Date_Time(void) {                      Lcd_Set_Cursor(1, 4);
                      display_Digit(min);
                  }
 +                updateRTC |= (min_org == min);
 +                
                  break;
              case 3: //Seconds
 @@ -416,6 +440,9 @@ void edit_Date_Time(void) {                      }
                      Lcd_Set_Cursor(1, 7);
                      display_Digit(sec);
 +                    if (sec_org != sec) {
 +                        updateRTC = 1;
 +                    }
                  } else if (!INCR) {
                      __delay_ms(250);
 @@ -427,7 +454,12 @@ void edit_Date_Time(void) {                      Lcd_Set_Cursor(1, 7);
                      display_Digit(sec);
 +                    if (sec_org != sec) {
 +                        updateRTC = 1;
 +                    }
                  }
 +                updateRTC |= (sec_org == sec);
 +                
                  break;
              case 6: //Date
 @@ -460,6 +492,8 @@ void edit_Date_Time(void) {                      Lcd_Set_Cursor(2, 6);
                      display_Digit(date);
                  }
 +                updateRTC |= (date_org == date);
 +                
                  break;
              case 5: //Month
 @@ -486,6 +520,8 @@ void edit_Date_Time(void) {                      Lcd_Set_Cursor(2, 9);
                      display_Digit(month);
                  }
 +                updateRTC |= (month_org == month);
 +                
                  break;
              case 4: //Year
 @@ -512,10 +548,12 @@ void edit_Date_Time(void) {                      Lcd_Set_Cursor(2, 14);
                      display_Digit(year);
                  }
 +                updateRTC |= (year_org == year);
 +                
                  break;
                  //TODO Maybe add a case to edit century on display
 -                
 +
              default:
                  break;
          }
 @@ -527,19 +565,23 @@ void edit_Date_Time(void) {      }
      // TODO Edit alarms
 -    
 +
      /*
       * Set button pressed after Date selection then we set the values in RTC.
       * Unset edit_datetime until next time set button is pressed and clear
       * field text from lower right of display.
       */
      if (edit_datetime > 6) {
 -        Set_Time();
 -        Set_DayOfWeek(Get_DayOfWeek(year, month, date));
 -        Set_Date();
 -        edit_datetime = 0;
          Lcd_Set_Cursor(2, 16);
          Lcd_Write_String(" ");
 +        edit_datetime = 0;
 +        
 +        if(updateRTC) {
 +            updateRTC = 0;
 +            Set_Time();
 +            Set_DayOfWeek(Get_DayOfWeek(year, month, date));
 +            Set_Date();
 +        }
      }
  }
 | 
