本文整理汇总了C++中RTC_SetTime函数的典型用法代码示例。如果您正苦于以下问题:C++ RTC_SetTime函数的具体用法?C++ RTC_SetTime怎么用?C++ RTC_SetTime使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTC_SetTime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TM_RTC_SetDateTime
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);
}
}
示例2: UB_RTC_SetClock
//--------------------------------------------------------------
// 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);
}
}
示例3: set_time
//设置时间
// 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);
}
示例4: main
/* 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);
}
}
示例5: bsp_RTCSet
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");
}
}
示例6: main
/* 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);
}
}
示例7: time_main
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") ;
}
示例8: RTC_cfg
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;
}
示例9: MicoRtcSetTime
/**
* 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 */
}
示例10: rtc_test
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);
}
}
示例11: RTC_to_default_config
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);
}
示例12: conv2d
void RTCDue::setTime (const char* time)
{
_hour = conv2d(time);
_minute = conv2d(time + 3);
_second = conv2d(time + 6);
RTC_SetTime (RTC, _hour, _minute, _second);
}
示例13: rtc_write
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;
}
示例14: SetRTC_Time
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
}
示例15: RTC_change_time
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);
}