Example #1
0
/*******************************************************************************
* Function Name  : RegulateMonth
* Description    : Regulates month.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
static void RegulateMonth(void)
{
  uint32_t tmpValue = 0;
  uint32_t MyKey = 0;

  /* Initialize tmpValue */
  tmpValue = date_s.month;

  /* Endless loop */
  while(1)
  {
    /* Check which key is pressed */
    MyKey = ReadKey();

    /* If "UP" pushbutton is pressed */
    if(MyKey == UP)
    {
      /* Increase the value of the digit */
      if(tmpValue == 12)
      {
        tmpValue = 0;
      }
      LCD_ClearLine(Line3);
      LCD_ClearLine(Line7);
      LCD_ClearLine(Line8);
      Date_Display(date_s.year, ++tmpValue, date_s.day);
    }
    /* If "DOWN" pushbutton is pressed */
    if(MyKey == DOWN)
    {
      /* Decrease the value of the digit */
      if(tmpValue == 1)
      {
        tmpValue = 13;
      }
      LCD_ClearLine(Line3);
      LCD_ClearLine(Line7);
      LCD_ClearLine(Line8);     
      /* Display new value */
      Date_Display(date_s.year, --tmpValue, date_s.day);
    }
    /* If "SEL" pushbutton is pressed */
    if(MyKey == SEL)
    {
      LCD_ClearLine(Line3);
      LCD_ClearLine(Line7);
      LCD_ClearLine(Line8);     
      /* Display new value */
      Date_Display(date_s.year, tmpValue, date_s.day);
      /* Return the digit value and exit */
      date_s.month = tmpValue;
      return;
    }
  }
}
Example #2
0
/**
  * @brief  Returns the date entered by user, using demoboard keys.
  * @param  None
  * @retval None
  */
void Date_Adjust(void)
{
  /* Display the current Date */
  Date_Display();

  /* Change the current Date */
  Date_Regulate();
}
Example #3
0
/**
  * @brief  Shows the current time and date on LCD.
  * @param  None
  * @retval None
  */
static void Calendar_Show(void)
{
  /* If 1s has elapsed */
  if (uwTimeDisplay == 1)
  {
    /* Display current time */
    Time_Display();
    
    /* Display current date */
    Date_Display();
    
    uwTimeDisplay = 0;
  }
}
Example #4
0
/*******************************************************************************
* Function Name  : Date_PreAdjust
* Description    : Pre-Adjusts the current date (MM/DD/YYYY).
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
static void Date_PreAdjust(void)
{
  uint32_t tmp = 0, pressedkey = 0;
   
  /* Clear the LCD */
  LCD_Clear(White);
  LCD_SetBackColor(Blue);
  LCD_SetTextColor(White);

  if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    LCD_DisplayStringLine(Line7, "Time and Date Config");
    LCD_DisplayStringLine(Line8, "Select: Press SEL   ");
    LCD_DisplayStringLine(Line9, "Abort: Press Any Key");   
    
    while(1)
    {
      pressedkey = ReadKey(); 
      if(pressedkey == SEL)
      {
        /* Adjust Time */
        Time_PreAdjust();
        /* Clear the LCD */
        LCD_Clear(White);
        return;
      }
      else if (pressedkey != NOKEY)
      {
        return;
      }
    }
  }
  else
  {
    /* Display the current date */
    Date_Display(date_s.year, date_s.month, date_s.day);

    /* Change the current date */
    Date_Regulate();
    BKP_WriteBackupRegister(BKP_DR2, date_s.year);
    tmp = date_s.month << 8;
    tmp |= date_s.day; 
    BKP_WriteBackupRegister(BKP_DR3, tmp);
    BKP_WriteBackupRegister(BKP_DR4, daycolumn);
    BKP_WriteBackupRegister(BKP_DR5, dayline);
  }
}
Example #5
0
/**
  * @brief  Shows the current time and date on LCD.
  * @param  None
  * @retval None
  */
void Calendar_Show(void)
{
  while(1)
  {
    /* If 1s has elapsed */
    if (TimeDisplay == 1)
    {
      /* Display current time */
      Time_Display();

      /* Display current date */
      Date_Display();

      TimeDisplay = 0;
    }
  }
}
Example #6
0
/*******************************************************************************
* Function Name  : Date_Show
* Description    : Shows date in a graphic mode on LCD.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Date_Show(void)
{
  uint32_t tmpValue = 0;
  uint32_t MyKey = 0, ValueMax = 0;
  uint32_t firstdaycolumn = 0, lastdaycolumn = 0, lastdayline = 0;
  uint32_t testvalue = 0, pressedkey = 0;
  
  /* Disable the JoyStick interrupts */
  IntExtOnOffConfig(DISABLE);
  LCD_Clear(White);

  while(ReadKey()!= NOKEY)
  {
  }
  LCD_SetBackColor(Blue);
  LCD_SetTextColor(White);

  if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    LCD_DisplayStringLine(Line7, "Time and Date Config");
    LCD_DisplayStringLine(Line8, "Select: Press SEL   ");
    LCD_DisplayStringLine(Line9, "Abort: Press Any Key");
    
    while(testvalue == 0)
    {
      pressedkey = ReadKey(); 
      if(pressedkey == SEL)
      {
        /* Adjust Time */
        Time_PreAdjust();
        /* Clear the LCD */
        LCD_Clear(White);
        testvalue = 0x01;
      }
      else if (pressedkey != NOKEY)
      {
        /* Clear the LCD */
        LCD_Clear(White);
        /* Display the menu */
        DisplayMenu();
        /* Enable the JoyStick interrupts */
        IntExtOnOffConfig(ENABLE);
        return;
      }
    }
  }
  /* Clear the LCD */
  LCD_Clear(White);
  
  LCD_DisplayStringLine(Line9, " To Exit Press SEL  ");

  /* Display the current date */
  Date_Display(date_s.year, date_s.month, date_s.day);

  if(date_s.month == 2)
  {
    if(IsLeapYear(date_s.year))
    {
      ValueMax = 29;
    }
    else
    {
      ValueMax = (MonLen[date_s.month - 1] - 1);
    }    
  }
  else
  {
    ValueMax = (MonLen[date_s.month - 1] - 1);
  }

  firstdaycolumn = 0x13F - (0x30 * dn);
  
  lastdaycolumn = ValueMax - (7 - dn);
  lastdayline = lastdaycolumn / 7;
  lastdaycolumn %= 7;

  if(lastdaycolumn == 0)
  {
    lastdayline = Line3 + (lastdayline * 24);
    lastdaycolumn = 31;
  }
  else
  {
    lastdayline = Line4 + (lastdayline * 24);
    lastdaycolumn = 0x13F -(0x30 * (lastdaycolumn - 1));
  }

  /* Initialize tmpValue */
  tmpValue = date_s.day;
  
  /* Endless loop */
  while(1)
  {
    /* Check which key is pressed */
    MyKey = ReadKey();

    /* If "RIGHT" pushbutton is pressed */
    if(MyKey == RIGHT)
    {
      LCD_SetTextColor(White);   
      LCD_DrawRect(dayline, daycolumn, 24, 32);
      
      /* Increase the value of the digit */
      if(tmpValue == ValueMax)
      {
        tmpValue = 0;
        dayline = Line3;
        daycolumn = firstdaycolumn + 48;
      }
             
      if(daycolumn == 31)
      {
        daycolumn = 367;
        dayline += 24;
      }       

      daycolumn -= 48;
      LCD_SetTextColor(Red);   
      LCD_DrawRect(dayline, daycolumn, 24, 32);
      tmpValue++;
      WeekDayNum(date_s.year, date_s.month, tmpValue);
      LCD_SetBackColor(Blue2);
      LCD_SetTextColor(White);
      LCD_DisplayStringLine(Line1, " WEEK     DAY N:    ");
      if(wn/10)
      {
        LCD_DisplayChar(Line1, 223, ((wn/10)+ 0x30));
        LCD_DisplayChar(Line1, 207, ((wn%10)+ 0x30));
      }
      else
      {
        LCD_DisplayChar(Line1, 223, ((wn%10)+ 0x30));
      }
      if(dc/100)
      {
        LCD_DisplayChar(Line1, 47, ((dc/100)+ 0x30));
        LCD_DisplayChar(Line1, 31, (((dc%100)/10)+ 0x30));
        LCD_DisplayChar(Line1, 15, (((dc%100)%10)+ 0x30));
      }
      else if(dc/10)
      {
        LCD_DisplayChar(Line1, 47, ((dc/10)+ 0x30));
        LCD_DisplayChar(Line1, 31, ((dc%10)+ 0x30));
      }
      else
      {
        LCD_DisplayChar(Line1, 47, ((dc%10)+ 0x30));
      }
      LCD_SetBackColor(White);          
    }
    /* If "LEFT" pushbutton is pressed */
    if(MyKey == LEFT)
    {
      LCD_SetTextColor(White);   
      LCD_DrawRect(dayline, daycolumn, 24, 32);
      
      /* Decrease the value of the digit */
      if(tmpValue == 1)
      {
        tmpValue = ValueMax + 1;
        dayline = lastdayline;
        daycolumn = lastdaycolumn - 48;
      }
      
      if(daycolumn == 319)
      {
        daycolumn = 0xFFEF;
        dayline -= 24;
      }

      daycolumn += 48;      
      LCD_SetTextColor(Red);   
      LCD_DrawRect(dayline, daycolumn, 24, 32);
      tmpValue--;
      WeekDayNum(date_s.year, date_s.month, tmpValue);
      LCD_SetBackColor(Blue2);
      LCD_SetTextColor(White);
      LCD_DisplayStringLine(Line1, " WEEK     DAY N:    ");
      if(wn/10)
      {
        LCD_DisplayChar(Line1, 223, ((wn/10)+ 0x30));
        LCD_DisplayChar(Line1, 207, ((wn%10)+ 0x30));
      }
      else
      {
        LCD_DisplayChar(Line1, 223, ((wn%10)+ 0x30));
      }
      if(dc/100)
      {
        LCD_DisplayChar(Line1, 47, ((dc/100)+ 0x30));
        LCD_DisplayChar(Line1, 31, (((dc%100)/10)+ 0x30));
        LCD_DisplayChar(Line1, 15, (((dc%100)%10)+ 0x30));
      }
      else if(dc/10)
      {
        LCD_DisplayChar(Line1, 47, ((dc/10)+ 0x30));
        LCD_DisplayChar(Line1, 31, ((dc%10)+ 0x30));
      }
      else
      {
        LCD_DisplayChar(Line1, 47, ((dc%10)+ 0x30));
      }
      LCD_SetBackColor(White);
    }
    /* If "UP" pushbutton is pressed */
    if(MyKey == UP)
    {
      LCD_SetTextColor(White);   
      LCD_DrawRect(dayline, daycolumn, 24, 32);
      
      if(tmpValue == 1)
      {
        dayline = lastdayline;
        daycolumn =  lastdaycolumn;
        tmpValue = ValueMax;
      }
      else if(tmpValue < 8)
      {
        tmpValue = 1;
        dayline = Line3;
        daycolumn = firstdaycolumn;
      }
      else
      {
        dayline -= 24;
        tmpValue -= 7;
      }

      LCD_SetTextColor(Red);   
      LCD_DrawRect(dayline, daycolumn, 24, 32);
      WeekDayNum(date_s.year, date_s.month, tmpValue);

      LCD_SetBackColor(Blue2);
      LCD_SetTextColor(White);
      LCD_DisplayStringLine(Line1, " WEEK     DAY N:    ");
      if(wn/10)
      {
        LCD_DisplayChar(Line1, 223, ((wn/10)+ 0x30));
        LCD_DisplayChar(Line1, 207, ((wn%10)+ 0x30));
      }
      else
      {
        LCD_DisplayChar(Line1, 223, ((wn%10)+ 0x30));
      }
      if(dc/100)
      {
        LCD_DisplayChar(Line1, 47, ((dc/100)+ 0x30));
        LCD_DisplayChar(Line1, 31, (((dc%100)/10)+ 0x30));
        LCD_DisplayChar(Line1, 15, (((dc%100)%10)+ 0x30));
      }
      else if(dc/10)
      {
        LCD_DisplayChar(Line1, 47, ((dc/10)+ 0x30));
        LCD_DisplayChar(Line1, 31, ((dc%10)+ 0x30));
      }
      else
      {
        LCD_DisplayChar(Line1, 47, ((dc%10)+ 0x30));
      }
      LCD_SetBackColor(White);
    } 
    /* If "DOWN" pushbutton is pressed */
    if(MyKey == DOWN)
    {
      LCD_SetTextColor(White);   
      LCD_DrawRect(dayline, daycolumn, 24, 32);
      if(tmpValue == ValueMax)
      {
        dayline = Line3;
        daycolumn =  firstdaycolumn;
        tmpValue = 1;
      }
      else
      {
        dayline += 24;
        tmpValue += 7;
      }

      if(tmpValue > ValueMax)
      {
        tmpValue = ValueMax;
        dayline = lastdayline;
        daycolumn = lastdaycolumn;
      }
      LCD_SetTextColor(Red);   
      LCD_DrawRect(dayline, daycolumn, 24, 32);
      WeekDayNum(date_s.year, date_s.month, tmpValue);

      LCD_SetBackColor(Blue2);
      LCD_SetTextColor(White);
      LCD_DisplayStringLine(Line1, " WEEK     DAY N:    ");
      if(wn/10)
      {
        LCD_DisplayChar(Line1, 223, ((wn/10)+ 0x30));
        LCD_DisplayChar(Line1, 207, ((wn%10)+ 0x30));
      }
      else
      {
        LCD_DisplayChar(Line1, 223, ((wn%10)+ 0x30));
      }
      if(dc/100)
      {
        LCD_DisplayChar(Line1, 47, ((dc/100)+ 0x30));
        LCD_DisplayChar(Line1, 31, (((dc%100)/10)+ 0x30));
        LCD_DisplayChar(Line1, 15, (((dc%100)%10)+ 0x30));
      }
      else if(dc/10)
      {
        LCD_DisplayChar(Line1, 47, ((dc/10)+ 0x30));
        LCD_DisplayChar(Line1, 31, ((dc%10)+ 0x30));
      }
      else
      {
        LCD_DisplayChar(Line1, 47, ((dc%10)+ 0x30));
      }
      LCD_SetBackColor(White);
    }
    /* If "SEL" pushbutton is pressed */
    if(MyKey == SEL)
    {
      /* Clear the LCD */
      LCD_Clear(White);
      /* Display the menu */
      DisplayMenu();
      /* Enable the JoyStick interrupts */
      IntExtOnOffConfig(ENABLE);
      return;
    }
  }
}
Example #7
0
/*******************************************************************************
* Function Name  : Calendar_Init
* Description    : Initializes calendar application.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Calendar_Init(void)
{
  uint32_t i = 0, tmp = 0, pressedkey = 0;
  
  /* Initialize Date structure */
  date_s.month = 01;
  date_s.day = 01;
  date_s.year = 2009;
    
  if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    LCD_SetBackColor(Blue);
    LCD_SetTextColor(White);
    LCD_DisplayStringLine(Line7, "Time and Date Config");
    LCD_DisplayStringLine(Line8, "Select: Press SEL   ");
    LCD_DisplayStringLine(Line9, "Abort: Press Any Key");
    
    while(1)
    { 
      pressedkey = ReadKey();

      if(pressedkey == SEL)
      {
        /* Adjust Time */
        Time_PreAdjust();
        return;
      }
      else if (pressedkey != NOKEY)
      {
        return;
      }
    }
  }
  else
  {
    /* PWR and BKP clocks selection ------------------------------------------*/
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
  
    /* Allow access to BKP Domain */
    PWR_BackupAccessCmd(ENABLE);
    
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
  
    /* Enable the RTC Second */  
    RTC_ITConfig(RTC_IT_SEC, ENABLE);

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    
    /* Initialize Date structure */
    date_s.month = (BKP_ReadBackupRegister(BKP_DR3) & 0xFF00) >> 8;
    date_s.day = (BKP_ReadBackupRegister(BKP_DR3) & 0x00FF);
    date_s.year = BKP_ReadBackupRegister(BKP_DR2);
    daycolumn = BKP_ReadBackupRegister(BKP_DR4);
    dayline = BKP_ReadBackupRegister(BKP_DR5);

    if(RTC_GetCounter() / 86399 != 0)
    {
      for(i = 0; i < (RTC_GetCounter() / 86399); i++)
      {
        Date_Update();
      }

      RTC_SetCounter(RTC_GetCounter() % 86399);

      LCD_DisplayStringLine(Line8, "       Days elapsed ");
      tmp = i/100;
      LCD_DisplayChar(Line8, 276,(tmp + 0x30));
      tmp = ((i%100)/10);
      LCD_DisplayChar(Line8, 260,(tmp + 0x30));
      tmp = ((i%100)%10);
      LCD_DisplayChar(Line8, 244,(tmp + 0x30));
      LCD_DisplayStringLine(Line9, "      Press SEL     ");

      while(ReadKey() != SEL)
      {
      }

      LCD_ClearLine(Line8);
      LCD_ClearLine(Line9);
      LCD_DisplayStringLine(Line9, "Push SEL to Continue");
      Date_Display(date_s.year, date_s.month, date_s.day);
 
      while(ReadKey() != SEL)
      {
      }
   
      BKP_WriteBackupRegister(BKP_DR4, daycolumn);
      BKP_WriteBackupRegister(BKP_DR5, dayline);
    }
  }
}