Beispiel #1
0
void TM_RTC_SetDateTime(TM_RTC_Time_t* data, TM_RTC_Format_t format) {	
	/* Fill time */
	RTC_TimeStruct.RTC_Hours = data->hours;
	RTC_TimeStruct.RTC_Minutes = data->minutes;
	RTC_TimeStruct.RTC_Seconds = data->seconds;
	/* Fill date */
	RTC_DateStruct.RTC_Date = data->date;
	RTC_DateStruct.RTC_Month = data->month;
	RTC_DateStruct.RTC_Year = data->year;
	RTC_DateStruct.RTC_WeekDay = data->day;
	
	/* Set the RTC time base to 1s and hours format to 24h */
	RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
	RTC_InitStruct.RTC_AsynchPrediv = uwAsynchPrediv;
	RTC_InitStruct.RTC_SynchPrediv = uwSynchPrediv;
	RTC_Init(&RTC_InitStruct);

	if (format == TM_RTC_Format_BCD) {
		RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);
	} else {
		RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);
	}
	
	if (format == TM_RTC_Format_BCD) {
		RTC_SetDate(RTC_Format_BCD, &RTC_DateStruct);
	} else {
		RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);
	}	
	
	if (TM_RTC_Status != RTC_STATUS_ZERO) {
		/* Write backup registers */
		RTC_WriteBackupRegister(RTC_STATUS_REG, RTC_STATUS_TIME_OK);
	}
}
Beispiel #2
0
//--------------------------------------------------------------
// RTC setzen
// vor dem Aufruf muss die aktuelle Uhrzeit und das Datum
// in der Struktur "UB_RTC" gespeichert werden
// format : [RTC_DEC, RTC_HEX]
//--------------------------------------------------------------
void UB_RTC_SetClock(RTC_FORMAT_t format)
{
  // Check auf Min+Max
  if(UB_RTC.std>23) UB_RTC.std=23;
  if(UB_RTC.min>59) UB_RTC.min=59;
  if(UB_RTC.sek>59) UB_RTC.sek=59;

  if(UB_RTC.tag<1) UB_RTC.tag=1;
  if(UB_RTC.tag>31) UB_RTC.tag=31;
  if(UB_RTC.monat<1) UB_RTC.monat=1;
  if(UB_RTC.monat>12) UB_RTC.monat=12;
  if(UB_RTC.jahr>99) UB_RTC.jahr=99;
  if(UB_RTC.wotag<1) UB_RTC.wotag=1;
  if(UB_RTC.wotag>7) UB_RTC.wotag=7;

  // Zeit einstellen
  RTC_TimeStructure.RTC_Hours = UB_RTC.std;
  RTC_TimeStructure.RTC_Minutes = UB_RTC.min;
  RTC_TimeStructure.RTC_Seconds = UB_RTC.sek;
  if(format==RTC_DEC) {
    RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);   
  }
  else {
    RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
  }

  // Datum einstellen
  RTC_DateStructure.RTC_Date = UB_RTC.tag;
  RTC_DateStructure.RTC_Month = UB_RTC.monat;
  RTC_DateStructure.RTC_Year = UB_RTC.jahr;
  RTC_DateStructure.RTC_WeekDay = UB_RTC.wotag;
  if(format==RTC_DEC) {
    RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure); 
  }
  else {
    RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure); 
  }

  // Sonstige Settings
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
  RTC_InitStructure.RTC_SynchPrediv =  0xFF;
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
  RTC_Init(&RTC_InitStructure);  

  // Status-Register beschreiben
  // falls Settings vom User gemacht wurden
  if(UB_RTC.status!=RTC_UNDEFINED) {
    RTC_WriteBackupRegister(RTC_STATUS_REG, RTC_STATUS_TIME_OK); 
  }
}
Beispiel #3
0
//设置时间
// RTC_H12_AM                     ((uint8_t)0x00)
// RTC_H12_PM                     ((uint8_t)0x40)
void set_time(	unsigned char year,
				unsigned char mounth,
				unsigned char day,
				unsigned char hour,
				unsigned char min,
				unsigned char sec,
				unsigned char week,
				unsigned char ampm)
{
	
	RTC_TimeTypeDef RTC_TimeStructure;
	RTC_DateTypeDef RTC_DateStructure;
	
	RTC_DateStructure.RTC_Year = year;
	RTC_DateStructure.RTC_Month = mounth;
	RTC_DateStructure.RTC_Date = day;
	RTC_DateStructure.RTC_WeekDay = week;
	//设置时间
	RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);
	
	
	RTC_TimeStructure.RTC_H12     = ampm;
	RTC_TimeStructure.RTC_Hours   = hour;
	RTC_TimeStructure.RTC_Minutes = min;
	RTC_TimeStructure.RTC_Seconds = sec; 
	RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);   

	RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F1);
}
Beispiel #4
0
/* start the main program */
void main() 
{
  
   unsigned char sec,min,hour,day,month,year;

  /* Initialize the lcd before displaying any thing on the lcd */
    LCD_Init(8,2,16);

  /* Initialize the RTC(ds1307) before reading or writing time/date */
    RTC_Init();


   /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetTime(0x10,0x40,0x00);  //  10:40:20 am
    RTC_SetDate(0x01,0x01,0x15);  //  1st Jan 2015



   /* Display the Time and Date continuously */ 
   while(1)
    {
		LCD_GoToLine(1);
	   /* Read the Time from RTC(ds1307) */ 
        RTC_GetTime(&hour,&min,&sec);    
		
	   /* Read the Date from RTC(ds1307) */ 
       RTC_GetDate(&day,&month,&year);     		 
        
	   LCD_Printf("\n\rtime:%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)hour,(uint16_t)min,(uint16_t)sec,(uint16_t)day,(uint16_t)month,(uint16_t)year);
	}		

  }
Beispiel #5
0
void bsp_RTCSet(uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
{
	RTC_TimeTypeDef RTC_TimeStructure;
	RTC_DateTypeDef RTC_DateStructure;
	RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
	RTC_TimeStructure.RTC_Hours = hour; 
  RTC_TimeStructure.RTC_Minutes = minute;
  RTC_TimeStructure.RTC_Seconds = second;
	
	RTC_DateStructure.RTC_WeekDay = 0;
	RTC_DateStructure.RTC_Date = day;
	RTC_DateStructure.RTC_Month = month;
	RTC_DateStructure.RTC_Year = year;
	
	
	if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure) == ERROR)
	{
		//printf("\n\r>> !! RTC Set Time failed. !! <<\n\r");
	} 
	
	if(RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure) == ERROR)
	{
		//printf("\n\r>> !! RTC Set Time failed. !! <<\n\r");
	} 
	
}
/* start the main program */
void main() 
{
   unsigned char sec,min,hour,day,month,year;

  /* Initilize the Uart before Transmiting/Reaceiving any data */
    UART_Init(9600);

  /* Initilize the RTC(ds1307) before reading or writing time/date */
    RTC_Init();

	UART_TxString(" Testing RTC ");
 /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetTime(0x10,0x40,0x00);  //  10:40:20 am
    RTC_SetDate(0x01,0x01,0x15);  //  1st Jan 2015



   /* Display the Time and Date continuously */ 
   while(1)
    {
	   /* Read the Time from RTC(ds1307) */ 
        RTC_GetTime(&hour,&min,&sec);      
		
	    /* Read the Date from RTC(ds1307) */ 
        RTC_GetDate(&day,&month,&year);        
	 
        UART_Printf("\n\r the time is :%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)hour,(uint16_t)min,(uint16_t)sec,(uint16_t)day,(uint16_t)month,(uint16_t)year);
	  }		

  }
Beispiel #7
0
void time_main(void *args) 
{
    char * datetime ;
    RTC_TimeTypeDef RTC_Time ;
    RTC_DateTypeDef RTC_Date ;
    int year ;
    if( args == NULL || ((func_args *)args)->argc == 1) {
        RTC_GetTime(RTC_Format_BIN, &RTC_Time) ;
        RTC_GetDate(RTC_Format_BIN, &RTC_Date) ;
        printf("Date: %d/%d/%d, Time: %02d:%02d:%02d\n", 
             RTC_Date.RTC_Month, RTC_Date.RTC_Date, RTC_Date.RTC_Year+2000,  
             RTC_Time.RTC_Hours,  RTC_Time.RTC_Minutes,  RTC_Time.RTC_Seconds) ;              
    } else if(((func_args *)args)->argc == 3 && 
              ((func_args *)args)->argv[1][0] == '-' && 
              ((func_args *)args)->argv[1][1] == 'd' ) {
        datetime = ((func_args *)args)->argv[2];
        sscanf(datetime, "%d/%d/%d", 
             (int *)&RTC_Date.RTC_Month, (int *)&RTC_Date.RTC_Date, &year) ;
        RTC_Date.RTC_Year = year - 2000 ;   
        RTC_Date.RTC_WeekDay = 0 ;
        RTC_SetDate(RTC_Format_BIN, &RTC_Date) ;        
    } else if(((func_args *)args)->argc == 3 && 
              ((func_args *)args)->argv[1][0] == '-' && 
              ((func_args *)args)->argv[1][1] == 't' ) {
        datetime = ((func_args *)args)->argv[2];
        sscanf(datetime, "%d:%d:%d",            
            (int *)&RTC_Time.RTC_Hours, 
            (int *)&RTC_Time.RTC_Minutes, 
            (int *)&RTC_Time.RTC_Seconds
        ) ;
        RTC_SetTime(RTC_Format_BIN, &RTC_Time) ;
    } else printf("Invalid argument\n") ; 
}
Beispiel #8
0
unsigned int RTC_cfg(void)
{
	unsigned int ret;
	RTC_DateTypeDef   RTC_DateStruct;
	RTC_TimeTypeDef   RTC_TimeStruct;
	
	ret = 0;

	if (RTC_ReadBackupRegister(RTC_BKP_DR1) != 0xA5A5)
	{
	  	ret = 1;
		
		/* Allow access to BKP Domain */
		PWR_BackupAccessCmd(ENABLE);
	 
		/* Reset Backup Domain */
		RTC_DeInit();
	 
		/* Enable LSE */
		RCC_LSEConfig(RCC_LSE_ON);
		
		/* Wait till LSE is ready */
		while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
		{}
	 
		/* Select LSE as RTC Clock Source */
		RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
	 
		/* Enable RTC Clock */
		RCC_RTCCLKCmd(ENABLE);
	 
		/* Wait for RTC registers synchronization */
		RTC_WaitForSynchro();
	 
		/* Adjust time */
		RTC_DateStruct.RTC_Year = 13;
		RTC_DateStruct.RTC_Month = 05;
		RTC_DateStruct.RTC_Date = 29;
		RTC_DateStruct.RTC_WeekDay = 3;
		RTC_TimeStruct.RTC_Hours = 11;
		RTC_TimeStruct.RTC_Minutes = 0;	
		RTC_TimeStruct.RTC_Seconds = 0;
		RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);	
		RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);
			
		RTC_WriteBackupRegister(RTC_BKP_DR1, 0xA5A5);
	}
	else
	{
	
		/* Allow access to BKP Domain */
		PWR_BackupAccessCmd(ENABLE);

		/* Wait for RTC registers synchronization */
		RTC_WaitForSynchro();
		while (RTC_GetFlagStatus(RTC_FLAG_RSF) == RESET);
		
	}
	return ret;
}
/**
* This function will set MCU RTC time to a new value. Time value must be given in the format of
* the structure wiced_rtc_time_t
*
* @return    WICED_SUCCESS : on success.
* @return    WICED_ERROR   : if an error occurred with any step
*/
OSStatus MicoRtcSetTime(mico_rtc_time_t* time)
{
#ifdef MICO_ENABLE_MCU_RTC
  RTC_TimeTypeDef rtc_write_time;
  RTC_DateTypeDef rtc_write_date;
  bool    valid = false;
  
  MicoMcuPowerSaveConfig(false);
  
  MICO_VERIFY_TIME(time, valid);
  if( valid == false )
  {
    return kParamErr;
  }
  rtc_write_time.RTC_Seconds = time->sec;
  rtc_write_time.RTC_Minutes = time->min;
  rtc_write_time.RTC_Hours   = time->hr;
  rtc_write_date.RTC_WeekDay = time->weekday;
  rtc_write_date.RTC_Date    = time->date;
  rtc_write_date.RTC_Month   = time->month;
  rtc_write_date.RTC_Year    = time->year;
  
  
  RTC_SetTime( RTC_Format_BIN, &rtc_write_time );
  RTC_SetDate( RTC_Format_BIN, &rtc_write_date );
  
  MicoMcuPowerSaveConfig(true);
  return kNoErr;
#else /* #ifdef MICO_ENABLE_MCU_RTC */
  UNUSED_PARAMETER(time);
  return kUnsupportedErr;
#endif /* #ifdef MICO_ENABLE_MCU_RTC */
}
void rtc_test()
{
    unsigned char sec,min,hour,day,month,year;
    UART_Printf("\n\rConnections SCL->P0.6 SDA->P0.7");
	UART_Printf("\n\r Make connections and hit 'k' to test! ");
    while(UART_RxChar()!='k');   

	RTC_Init();

	
 /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetTime(0x10,0x40,0x00);  //  10:40:20 am
    RTC_SetDate(0x01,0x01,0x15);  //  1st Jan 2015

   /* Display the Time and Date continuously */ 
   while(1)
    {
        RTC_GetTime(&hour,&min,&sec);      
        RTC_GetDate(&day,&month,&year);        
        UART_Printf("\n\rtime:%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)hour,(uint16_t)min,(uint16_t)sec,(uint16_t)day,(uint16_t)month,(uint16_t)year);
     }
    
   
}
Beispiel #11
0
void RTC_to_default_config(void)
{
    //enable clk for PWR & allow access to RTC
    /* Enable the PWR clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

    /* Allow access to RTC */
    PWR_RTCAccessCmd(ENABLE);

    /* RTC Configuration -------------------------------------------------------*/
    RTC_Config();
    RTC_DateStructure.RTC_Month = RTC_Month_May;
    RTC_DateStructure.RTC_Date = 1;
    RTC_DateStructure.RTC_Year = 13;
    RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Wednesday;


    RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
    RTC_TimeStructure.RTC_Hours = 12;
    RTC_TimeStructure.RTC_Minutes = 00;
    RTC_TimeStructure.RTC_Seconds = 00;


    RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);
    //RTC_SetDate(RTC_Format_BIN,&RTC_DateStructure);

    //disable access to RTC & disable clk to PWR
    PWR_RTCAccessCmd(DISABLE);
    //RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, DISABLE);
}
Beispiel #12
0
void RTCDue::setTime (const char* time)
{
  _hour   = conv2d(time);
  _minute = conv2d(time + 3);
  _second = conv2d(time + 6);
  
  RTC_SetTime (RTC, _hour, _minute, _second);
}
Beispiel #13
0
void rtc_write(void) {
  if(!rtc_ok) {
    // Enable the PWR clock
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

    // Allow access to RTC
    PWR_BackupAccessCmd(ENABLE);

    // Enable the LSE OSC
    RCC_LSEConfig(RCC_LSE_ON);
  
    // Wait till LSE is ready
    while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
  
    // Select the RTC Clock Source
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
  
    // Enable the RTC Clock
    RCC_RTCCLKCmd(ENABLE);

    // Wait for RTC APB registers synchronisation
    RTC_WaitForSynchro();

    // Enable The TimeStamp 
    RTC_TimeStampCmd(RTC_TimeStampEdge_Falling, ENABLE); // TODO: can return ERROR

    RTC_InitTypeDef RTC_InitStructure;
  
    RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
    RTC_InitStructure.RTC_SynchPrediv = 0xFF;
    RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
    RTC_Init(&RTC_InitStructure);
  }
  
  RTC_TimeTypeDef TimeRTC;
  RTC_DateTypeDef DateRTC;

  TimeRTC.RTC_H12     = RTC_H12_AM; // Always AM for 24H
  TimeRTC.RTC_Hours   = rtc_hour;
  TimeRTC.RTC_Minutes = rtc_minute;
  TimeRTC.RTC_Seconds = rtc_second;
  
  RTC_SetTime(RTC_Format_BIN, &TimeRTC);
  
  (void)RTC->DR;
  
  DateRTC.RTC_WeekDay = rtc_day;
  DateRTC.RTC_Date    = rtc_date;
  DateRTC.RTC_Month   = rtc_month;
  DateRTC.RTC_Year    = rtc_year;
  
  RTC_SetDate(RTC_Format_BIN, &DateRTC); // TODO: can return ERROR

  RTC_WriteBackupRegister(RTC_BKP_DR0, 0xCA7E);
  
  rtc_ok = true;
}
Beispiel #14
0
void SetRTC_Time(void)
{
		// Set the time to 01h 00mn 00s AM 
	RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
	RTC_TimeStructure.RTC_Hours   = 0x01;
	RTC_TimeStructure.RTC_Minutes = 0x00;
	RTC_TimeStructure.RTC_Seconds = 0x00;  

	RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure); // Write values to registers
}
Beispiel #15
0
void RTC_change_time(uint8_t hr, uint8_t min, uint8_t s)
{
    PWR_RTCAccessCmd(ENABLE);
    RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
    RTC_TimeStructure.RTC_Hours = hr;
    RTC_TimeStructure.RTC_Minutes = min;
    RTC_TimeStructure.RTC_Seconds = s;
    RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);
    PWR_RTCAccessCmd(DISABLE);
}
Beispiel #16
0
static void setting_time(void)
{
  /* set 8:29:55 */
  RTC_TimeTypeDef RTC_TimeStruct;
  RTC_TimeStruct.RTC_Hours = 0x08;
  RTC_TimeStruct.RTC_Minutes = 0x29;
  RTC_TimeStruct.RTC_Seconds = 0x55;

  RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);

}
Beispiel #17
0
void rtc_set_cb(guiObject_t *obj, const void *data)
{
    (void)obj;
    if ((long)data == TIMEBUTTON) {
        RTC_SetTime(Rtc.value[HOUR], Rtc.value[MINUTE], Rtc.value[SECOND]);
        GUI_Redraw(&gui->acttime);
    } else if ((long)data == DATEBUTTON) {
        RTC_SetDate(Rtc.value[YEAR], Rtc.value[MONTH], Rtc.value[DAY]);
        GUI_Redraw(&gui->actdate);
    }
}
Beispiel #18
0
void RTC_Set(tm_elems *tm){
    LDD_RTC_TTime ttime;
    ttime.Day = tm->date;
    ttime.DayOfWeek = tm->dow;
    ttime.Hour = tm->hours;
    ttime.Minute = tm->minutes;
    ttime.Month = tm->month;
    ttime.Second = tm->seconds;
    ttime.Year = tm->year + 2000;

    RTC_SetTime(RTC, &ttime);
}
Beispiel #19
0
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();

}
Beispiel #20
0
static void System_Time_Init(void)
{
	/* RTC Block section ------------------------------------------------------ */
	// Init RTC module
	RTC_Init(LPC_RTC);

    /* Disable RTC interrupt */
    NVIC_DisableIRQ(RTC_IRQn);
    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(RTC_IRQn, ((0x01<<3)|0x01));

	/* Enable rtc (starts increase the tick counter and second counter register) */
	RTC_ResetClockTickCounter(LPC_RTC);
	RTC_Cmd(LPC_RTC, ENABLE);
	RTC_CalibCounterCmd(LPC_RTC, DISABLE);

	/* Set current time for RTC */
	// Current time is 06:45:00PM, 2011-03-25
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, 45);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, 15);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 3);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 2014);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 30);

	return;
}
Beispiel #21
0
//To be called when the Adjust time button is pushed. Decrements the RTC time by 1 hour
void DecrementHours()
{
    int currentHour = myclockTimeStruct.RTC_Hours;
    int currentMinute = myclockTimeStruct.RTC_Minutes;
    currentHour--;
    if(currentHour <= -1) {
        currentHour = 23;
    }
    myclockTimeStruct.RTC_Hours = currentHour;
    myclockTimeStruct.RTC_Minutes = currentMinute;
    myclockTimeStruct.RTC_Seconds = 0;
    RTC_SetTime(RTC_Format_BIN, &myclockTimeStruct);
}
void SWRB_TimeSettingsChangeConfirmProc(void)
{
    gSwrbDialogSelectFlag = SWRB_DIALOG_SELECT_NONE;
    gSwrbTestSetSelectFlag = SWRB_TEST_SET_SELECT_NONE;
    
    TimeStr_Comb(hWin_SWRB_TIMESET, ID_TIMESET_EDIT_SETVALUE);
    
    PWR_BackupAccessCmd(ENABLE);
    while(!(RTC_SetDate(RTC_Format_BIN, &rtcDate)));
    while(!(RTC_SetTime(RTC_Format_BIN, &rtcTime)));
    while(!RTC_WaitForSynchro());
    PWR_BackupAccessCmd(DISABLE);
}
Beispiel #23
0
/**
  * @brief  Reset Chrono to zero.
  * @param  None.
  * @retval None.
  */
void Time_Reset(void)
{
  PauseStatus = RESET;

  RTC_TimeStr.RTC_H12     = RTC_H12_AM;
  RTC_TimeStr.RTC_Hours   = 00;
  RTC_TimeStr.RTC_Minutes = 00;
  RTC_TimeStr.RTC_Seconds = 00;

  RTC_SetTime(RTC_Format_BIN, &RTC_TimeStr);
  CLK_RTCClockConfig(CLK_RTCCLKSource_Off, CLK_RTCCLKDiv_1);


}
Beispiel #24
0
static rt_err_t rt_rtc_control(rt_device_t dev, rt_uint8_t cmd, void *args)
{
    //rt_time_t *time;
    RT_ASSERT(dev != RT_NULL);

    switch (cmd)
    {
    case RT_DEVICE_CTRL_RTC_GET_TIME:
       // time = (rt_time_t *)args;
        /* read device */
        RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
        break;

    case RT_DEVICE_CTRL_RTC_SET_TIME:
    {
//        time = (rt_time_t *)args;

        /* Enable PWR and BKP clocks */
        //RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
        /* Allow access to BKP Domain */
        //PWR_BackupAccessCmd(ENABLE);
        PWR_BackupAccessCmd(ENABLE);
        /* Wait until last write operation on RTC registers has finished */
        //RTC_WaitForLastTask();
	 RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);
				
	 RTC_WaitForSynchro();
			
        /* Change the current time */
        //RTC_SetCounter(*time);

        /* Wait until last write operation on RTC registers has finished */
        //RTC_WaitForLastTask();

    }
    break;
		case RT_DEVICE_CTRL_RTC_SET_DATE:
		{
			RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); 
			PWR_BackupAccessCmd(ENABLE);
			RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure);
	 	
			RTC_WaitForSynchro();
    }
		break;
    }

    return RT_EOK;
}
Beispiel #25
0
void setRTCTime(RTC_TimeTypeDef* RTC_TimeStructure, RTC_DateTypeDef* RTC_DateStructure)
{
	/* Configure the RTC time register */
	if(RTC_SetTime(RTC_Format_BIN, RTC_TimeStructure) == ERROR)
	{
		/* RTC Set Time failed */
	}

	/* Configure the RTC date register */
	if(RTC_SetDate(RTC_Format_BIN, RTC_DateStructure) == ERROR)
	{
		/* RTC Set Date failed */
	}
}
Beispiel #26
0
//To be called when the adjust time button is pushed. Increments the RTC time by one hour.
void IncrementHours()
{
    int currentHour = myclockTimeStruct.RTC_Hours;
    int currentMinute = myclockTimeStruct.RTC_Minutes;
    currentHour++;
    if(currentHour >= 24)
    {
        currentHour = 0;
    }
    myclockTimeStruct.RTC_Hours = currentHour;
    myclockTimeStruct.RTC_Minutes = currentMinute;
    myclockTimeStruct.RTC_Seconds = 0;
    RTC_SetTime(RTC_Format_BIN, &myclockTimeStruct);
}
Beispiel #27
0
void date_settime(enum nilop op) {
	int h, m, s;
	if (extract_time(&h, &m, &s, 24))
		return;
#ifdef REALBUILD
	if (Xtal) {
		busy();
		RTC_SetTime((unsigned char) h, (unsigned char) m, (unsigned char) s);
	} else
		err(ERR_NO_CRYSTAL);
#else
	err(ERR_ILLEGAL);
#endif
}
Beispiel #28
0
void RTC_Clock_Init(void)
{
	RTC_TimeTypeDef RTC_TimeStruct;
	RTC_DateTypeDef RTC_DateStruct;
	RTC_InitTypeDef RTC_InitStruct;
	/* Enable the PWR clock */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
	/* Allow access to RTC */
	//RTC_WriteProtectionCmd(DISABLE);
	PWR_BackupAccessCmd(ENABLE);

	RCC_LSEConfig(RCC_LSE_ON);

	/* Wait till LSE is ready */
	while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
	{
	}

	/* Select the RTC Clock Source */
	RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

    SynchPrediv = 0xFF;
    AsynchPrediv = 0x7F;

	RCC_RTCCLKCmd(ENABLE);
	RTC_WaitForSynchro();

	RTC_WriteBackupRegister(RTC_BKP_DR0, FIRST_DATA);

	RTC_StructInit(&RTC_InitStruct);

	RTC_TimeStruct.RTC_Hours = (1<<4)|0;
	RTC_TimeStruct.RTC_Minutes = (2<<4)|3;
	RTC_TimeStruct.RTC_Seconds = 0;
	RTC_SetTime(RTC_Format_BCD,&RTC_TimeStruct);

	RTC_DateStruct.RTC_WeekDay = RTC_Weekday_Thursday;
	RTC_DateStruct.RTC_Date = 14;
	RTC_DateStruct.RTC_Month = RTC_Month_March;
	RTC_DateStruct.RTC_Year = 13;
	RTC_SetDate(RTC_Format_BCD,&RTC_DateStruct);

	RTC_InitStruct.RTC_AsynchPrediv = AsynchPrediv;
	RTC_InitStruct.RTC_SynchPrediv = SynchPrediv;
	RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
    RTC_Init(&RTC_InitStruct);

    xTaskCreate(RTC_Task,(signed char*)"RTC",128,NULL, tskIDLE_PRIORITY + 1, NULL);
}
void set_iec_time(cp56time2a* TM_cp56_time){
  RTC_TimeTypeDef RTC_TimeStruct;
	RTC_DateTypeDef RTC_DateStruct;
	
	RTC_TimeStruct.RTC_Hours = TM_cp56_time->hour;
	RTC_TimeStruct.RTC_Minutes = TM_cp56_time->min;
	RTC_TimeStruct.RTC_Seconds = TM_cp56_time->msec/0x03E8;
	RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);
	
	RTC_DateStruct.RTC_Date = TM_cp56_time->mday;
	RTC_DateStruct.RTC_Month = TM_cp56_time->month;
	RTC_DateStruct.RTC_WeekDay = TM_cp56_time->wday;
	RTC_DateStruct.RTC_Year = TM_cp56_time->year;
	RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);
}
Beispiel #30
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* In this example:
	 * Suppose that the RTC need periodically adjust after each 5 second.
	 * And the time counter need by incrementing the counter by 2 instead of 1
	 * We will observe timer counter after calibration via serial display
	 */
	// Init RTC module
	RTC_Init(LPC_RTC);

	/* Enable rtc (starts increase the tick counter and second counter register) */
	RTC_ResetClockTickCounter(LPC_RTC);
	RTC_Cmd(LPC_RTC, ENABLE);

	//Set current time = 0
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);

	/* Setting Timer calibration
	 * Calibration value =  5s;
	 * Direction = Forward calibration
	 * So after each 5s, calibration logic can periodically adjust the time counter by
	 * incrementing the counter by 2 instead of 1
	 */
	RTC_CalibConfig(LPC_RTC, 5, RTC_CALIB_DIR_FORWARD);
	RTC_CalibCounterCmd(LPC_RTC, ENABLE);

	/* Set the CIIR for second counter interrupt*/
	RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);

    /* Enable RTC interrupt */
    NVIC_EnableIRQ(RTC_IRQn);

    /* Loop forever */
    while(1);
    return 1;
}