//--------------------------------------------------------------
// RTC auslesen
// nach dem Aufruf steht die aktuelle Uhrzeit
// und das Datum in der Struktur "UB_RTC"
// format : [RTC_DEC, RTC_HEX]
//--------------------------------------------------------------
void UB_RTC_GetClock(RTC_FORMAT_t format)
{
  // Zeit auslesen
  if(format==RTC_DEC) {
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
  }
  else {
    RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);
  }
  UB_RTC.std = RTC_TimeStructure.RTC_Hours;
  UB_RTC.min = RTC_TimeStructure.RTC_Minutes;
  UB_RTC.sek = RTC_TimeStructure.RTC_Seconds;

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

}
示例#2
0
//--------------------------------------------------------------
// RTC auslesen
// nach dem Aufruf steht die aktuelle Uhrzeit
// und das Datum in der Struktur "UB_RTC"
// format : [RTC_DEC, RTC_HEX]
//--------------------------------------------------------------
RTC_t UB_RTC_GetClock(RTC_FORMAT_t format)
{
  RTC_t time;
  // Zeit auslesen
  if(format==RTC_DEC) {
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
  }
  else {
    RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);
  }
  time.std = RTC_TimeStructure.RTC_Hours;
  time.min = RTC_TimeStructure.RTC_Minutes;
  time.sek = RTC_TimeStructure.RTC_Seconds;

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

  return time;
}
示例#3
0
void TM_RTC_GetDateTime(TM_RTC_Time_t* data, TM_RTC_Format_t format) {
	uint32_t unix;

	/* Get time */
	if (format == TM_RTC_Format_BIN) {
		RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
	} else {
		RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct);
	}
	
	data->hours = RTC_TimeStruct.RTC_Hours;
	data->minutes = RTC_TimeStruct.RTC_Minutes;
	data->seconds = RTC_TimeStruct.RTC_Seconds;
	
	/* Get date */
	if (format == TM_RTC_Format_BIN) {
		RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
	} else {
		RTC_GetDate(RTC_Format_BCD, &RTC_DateStruct);
	}
	
	data->year = RTC_DateStruct.RTC_Year;
	data->month = RTC_DateStruct.RTC_Month;
	data->date = RTC_DateStruct.RTC_Date;
	data->day = RTC_DateStruct.RTC_WeekDay;
	
	/* Calculate unix offset */
	unix = TM_RTC_GetUnixTimeStamp(data);
	data->unix = unix;
}
示例#4
0
uint32_t RTC_time_GetUnixtime(void) {
  uint32_t t;
  uint16_t days = days_from_2000(RTC_GetTime (LPC_RTC, RTC_TIMETYPE_YEAR), RTC_GetTime (LPC_RTC, RTC_TIMETYPE_MONTH), RTC_GetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH));
  t = time2long(days, RTC_GetTime (LPC_RTC, RTC_TIMETYPE_HOUR), RTC_GetTime (LPC_RTC, RTC_TIMETYPE_MINUTE), RTC_GetTime (LPC_RTC, RTC_TIMETYPE_SECOND));
  t += SECONDS_FROM_1970_TO_2000; // seconds from 1970 to 2000
  return t;
}
示例#5
0
文件: tick_rtc.c 项目: AriZuu/picoos
static long rtcTimeNow()
{
  RTC_TimeTypeDef time;
  RTC_DateTypeDef date;
  RTC_TimeTypeDef time2;
  RTC_DateTypeDef date2;
  uint32_t        ss;
  uint32_t        ss2;
  struct tm t;

  // RTC is in BYPSHAD mode. Read the registers twice.
  RTC_GetTime(RTC_Format_BIN, &time);
  RTC_GetDate(RTC_Format_BIN, &date);
  ss = RTC_GetSubSecond();

  RTC_GetTime(RTC_Format_BIN, &time2);
  RTC_GetDate(RTC_Format_BIN, &date2);
  ss2 = RTC_GetSubSecond();

  // Check read values. If they match, read was ok. Otherwise read third time.
  if (ss != ss2 ||
      time.RTC_Seconds != time2.RTC_Seconds ||
      time.RTC_Minutes != time2.RTC_Minutes ||
      time.RTC_Hours != time2.RTC_Hours ||
      date.RTC_Date != date2.RTC_Date ||
      date.RTC_Month != date2.RTC_Month ||
      date.RTC_Year != date2.RTC_Year) {

    RTC_GetTime(RTC_Format_BIN, &time);
    RTC_GetDate(RTC_Format_BIN, &date);
    ss = RTC_GetSubSecond();
  }

  memset(&t, '\0', sizeof(t));

  t.tm_sec  = time.RTC_Seconds;
  t.tm_min  = time.RTC_Minutes;
  t.tm_hour = time.RTC_Hours;
  t.tm_mday = date.RTC_Date;
  t.tm_mon  = date.RTC_Month - 1;
  t.tm_year = date.RTC_Year + 2000 - 1900;

  time_t secs;
  long msecs;

  secs = mktime(&t);
  msecs = 1000 - (ss * 1000 / 1024);

  return 1000 * secs + msecs;
}
/***************************************************************************//*!
 * @brief   RTC Callback function (second interrupt, alarm interrupt).
 ******************************************************************************/
void rtc_callback (RTC_CALLBACK_TYPE type)
{ 
  if (type == TAF_CALLBACK) 
  { 
    RTC_SetAlarm (RTC_GetTime()+alarm_interval);
    GPIO_Tgl (GPIOE, PIN_31);
  }
  if (type == TSF_CALLBACK) 
  { 
    RTC_GmTime (RTC_GetTime(),&time);
    lcd_settime(&time);
    GPIO_Tgl (GPIOD, PIN_5);
  }
}
示例#7
0
/**
  * @brief  Display the current time on the Hyperterminal.
  * @param  None
  * @retval None
  */
void RTC_TimeShow(void)
{
  RTC_TimeStructInit(&RTC_TimeStructure);
  /* Get the current Time */
  RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
  printf("\n\r  The current time is :  %0.2d:%0.2d:%0.2d \n\r", RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
}
示例#8
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);
	}		

  }
示例#9
0
/**
  * @brief  Enters STANDBY mode, RTC Alarm within 3 second or an external RESET
  *         will wake-up the system from STANDBY
  * @param  None
  * @retval None
  */
static void EnterSTANDBYMode(void)
{
    RTC_AlarmTypeDef  RTC_AlarmStructure;
    RTC_TimeTypeDef   RTC_TimeStructure;

    /* Disable the Alarm A */
    RTC_AlarmCmd(RTC_Alarm_A, DISABLE);

    /* Get the current time */
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);

    /* Set the alarm to current time + 3s */
    RTC_AlarmStructure.RTC_AlarmTime.RTC_H12     = RTC_TimeStructure.RTC_H12;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours   = RTC_TimeStructure.RTC_Hours;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = RTC_TimeStructure.RTC_Minutes;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = (RTC_TimeStructure.RTC_Seconds + 0x3) % 60;
    RTC_AlarmStructure.RTC_AlarmDateWeekDay = 31;
    RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
    RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay | RTC_AlarmMask_Hours | RTC_AlarmMask_Minutes;
    RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);

    /* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from
    STANDBY mode (RTC Alarm IT not enabled in NVIC) */
    RTC_ITConfig(RTC_IT_ALRA, ENABLE);

    /* Enable the Alarm A */
    RTC_AlarmCmd(RTC_Alarm_A, ENABLE);

    /* Clear RTC Alarm Flag */
    RTC_ClearFlag(RTC_FLAG_ALRAF);

    /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
    PWR_EnterSTANDBYMode();
}
示例#10
0
void Time_Show(uint8_t Line, uint8_t pos)
{
  /* Wait until the calendar is synchronized */
  while (RTC_WaitForSynchro() != SUCCESS);

  /* Get the current subsecond Time*/
  Subsecondvalue = RTC_GetSubSecond();

  /* Wait until the calendar is synchronized */
  while (RTC_WaitForSynchro() != SUCCESS);
  /* Get the current Time*/
  RTC_GetTime(RTC_Format_BCD, &RTC_TimeStr);

  Mstime = 999 - ((uint32_t)((uint32_t)Subsecondvalue * 1000) / (uint32_t)RTC_InitStr.RTC_SynchPrediv);

  Ms100 = (uint8_t)(Mstime / 100);
  Ms10  = (uint8_t)((Mstime % 100 ) / 10);
  Ms1  =  (uint8_t)(Mstime % 10);


  /* Fill the LCDString fields with the current Time : second and milliseconds*/

  LCDStringTime[pos] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Seconds & 0xF0) >> 4) + ASCII_NUM_0);
  LCDStringTime[pos+1] = (uint8_t)(((uint8_t)(RTC_TimeStr.RTC_Seconds & 0x0F)) + ASCII_NUM_0);

  LCDStringTime[pos+3] = (uint8_t)((uint8_t)(Ms100 + ASCII_NUM_0));
  LCDStringTime[pos+4] = (uint8_t)((uint8_t)(Ms10 + ASCII_NUM_0));
  LCDStringTime[pos+5] = (uint8_t)((uint8_t)(Ms1 + ASCII_NUM_0));

  /* Print the Time Calendar on the LCD*/
  LCD_SetCursorPos(Line, 0);
  LCD_Print((uint8_t*)LCDStringTime);
}
示例#11
0
文件: time.c 项目: zgramana/arm-mcu
int _gettimeofday(struct timeval *ptimeval, void *ptimezone)
{
    RTC_DATE date;
    RTC_TIME time;
    struct tm tm;
    time_t now;

// Read current date and time from the RTC

    RTC_GetDate(BINARY, &date);
    RTC_GetTime(BINARY, &time);

// Get the date again if the current time is 00:00:00 (Midnight)

    if ((time.hours == 0) && (time.minutes == 0) && (time.seconds == 0))
        RTC_GetDate(BINARY, &date);

// Convert current date and time to time_t

    memset(&tm, 0, sizeof(struct tm));
    tm.tm_sec = time.seconds;
    tm.tm_min = time.minutes;
    tm.tm_hour = time.hours;
    tm.tm_mday = date.day;
    tm.tm_mon = date.month - 1;
    tm.tm_year = date.century*100 + date.year - 1900;
    now = rep_timegm(&tm);

// Convert current date and time to struct timeval

    memset(ptimeval, 0, sizeof(struct timeval));
    ptimeval->tv_sec = now;

    return 0;
}
/* 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);
	  }		

  }
示例#13
0
void get_sensors_state(){
	if(PIN_STATE(WATER_LEVER_SENSOR)) {
		if(regim == DISPLAY_REGIM_DEFAULT)
			{regim = DISPLAY_REGIM_NO_WATER;}
		PIN_ON(NO_WATER_LED);
		PIN_OFF(WATERING_RELAY);
	}else{
		if(PIN_STATE(NO_WATER_LED)) {PIN_OFF(NO_WATER_LED);}
	}

	if(PIN_STATE(LIGHT_SENSOR)) {
		//датчик естественного света - выключаем досветку
		if(PIN_STATE(LIGHT_RELAY)) {PIN_OFF(LIGHT_RELAY);}
	}else{
		//текущее врем¤ в разрешенном диапазоне использовани¤ досветки
		RTCTIME rtc_clock;
		RTC_GetTime(&rtc_clock);

		u16 now_time = set_low_n_height(rtc_clock.hour, rtc_clock.min); //текущее врем¤ (часы+минуты)

		//но в заданный промежуток времени
		if (BKP_ReadBackupRegister(tMORNING_LIGHT_TIME_BKP) < now_time &&
			now_time < BKP_ReadBackupRegister(tEVENING_LIGHT_TIME_BKP)) //с утра до вечера
		{
			PIN_ON(LIGHT_RELAY);
		}
	}
}
示例#14
0
u8 CreateNewJob(void)
{
    // ÇöÀç ³¯Â¥, ½Ã°£
    RTC_DateTypeDef RTC_DateStruct;
    RTC_TimeTypeDef RTC_TimeStruct;
    RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);

    // JOB ä¿ì±â
    JOB_INFO info = { "NEW JOB",
                      gxFileCount + 1, 0, 0,
                      RTC_DateStruct.RTC_Year,
                      RTC_DateStruct.RTC_Month,
                      RTC_DateStruct.RTC_Date,
                      RTC_TimeStruct.RTC_Hours,
                      RTC_TimeStruct.RTC_Minutes,
                      RTC_TimeStruct.RTC_Seconds,
                    };
    // "NEW JOB", NULL};

    // ÆÄÀÏ »ý¼º
    SaveJobData(info, NULL, gxFileCount);

    u32 selValue = ++gxFileCount % PAGE_JOB_COUNT;
    gJobPageNo = (gxFileCount / PAGE_JOB_COUNT) + (selValue != 0 ? 1 : 0);
    gPreJobMgrMenu = (TSA_JOB_MGR_MENU)((u16)(JM_SEL1 - 1) + (selValue != 0 ? selValue : PAGE_JOB_COUNT));

    if(gJobMgrMenu >= JM_SEL1 && gJobMgrMenu <= JM_SEL12)	gIsJobNotPlaySound = TRUE;

    return TRUE;
}
示例#15
0
文件: MainPage.c 项目: beartan/q-sys
static void DispTime(void)
{
	RTC_TIME Time;
	char TimeMsg[64];
	GUI_REGION DrawRegion;

	if(Gui_GetBgLightVal()==0) return;//背光没亮,无需更新

	RTC_GetTime(&Time);
	sprintf(TimeMsg,"%02d月%02d日 周%s",Time.mon,Time.day,Week[Time.week]);

	DrawRegion.x=0;
	DrawRegion.y=0;
	DrawRegion.w=240;
	DrawRegion.h=18;
	DrawRegion.Color=FatColor(NO_TRANS);
	Gui_Draw24Bmp("Theme/F/MainPage/Bg/A01.Bmp",&DrawRegion);
	
	DrawRegion.x=4;
	DrawRegion.y=4;
	DrawRegion.w=120;
	DrawRegion.h=16;
	DrawRegion.Space=0x11;
  	DrawRegion.Color=FatColor(0xf2f2f2);
	Gui_DrawFont(GBK12_FONT,(void *)TimeMsg,&DrawRegion);

	DrawRegion.x=200;
	DrawRegion.Space=0x00;
	sprintf(TimeMsg,"%02d:%02d",Time.hour,Time.min);
	Gui_DrawFont(GBK12_FONT,(void *)TimeMsg,&DrawRegion);
}
/**
* This function will return the value of time read from the on board CPU real time clock. 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 MicoRtcGetTime(mico_rtc_time_t* time)
{
#ifdef MICO_ENABLE_MCU_RTC
  RTC_TimeTypeDef rtc_read_time;
  RTC_DateTypeDef rtc_read_date;
  
  if( time == 0 )
  {
    return kParamErr;
  }
  
  /* save current rtc time */
  RTC_GetTime( RTC_Format_BIN, &rtc_read_time );
  RTC_GetDate( RTC_Format_BIN, &rtc_read_date );
  
  /* fill structure */
  time->sec = rtc_read_time.RTC_Seconds;
  time->min = rtc_read_time.RTC_Minutes;
  time->hr = rtc_read_time.RTC_Hours;
  time->weekday = rtc_read_date.RTC_WeekDay;
  time->date = rtc_read_date.RTC_Date;
  time->month= rtc_read_date.RTC_Month;
  time->year = rtc_read_date.RTC_Year;
  
  return kNoErr;
#else /* #ifdef WICED_ENABLE_MCU_RTC */
  UNUSED_PARAMETER(time);
  return kUnsupportedErr;
#endif /* #ifdef WICED_ENABLE_MCU_RTC */
}
// Rutina de interrupción del RTC
void RTC_IRQHandler(void) {
	static signed portBASE_TYPE param;
	uint32_t sec;

	// Verifica que haya una interrupción pendiente por incremento en el RTC
	if (RTC_GetIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE)) {

		// Limpia la interrupción pendiente
		RTC_ClearIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE);

		sec = RTC_GetTime(LPC_RTC, RTC_TIMETYPE_SECOND);
		sumarSegundo();

		//if (!(sec % INTERVALO_SEG)) {		// PARA HACER CADA INTERVALOS DE MENOS DE UN MIN - REVISAR BIEN CÓDIGO

		if (sec == 40) {
			deshabilitar_int_rotativo();
		} else if (sec == 50) {
			param = pdFALSE;
			xSemaphoreGiveFromISR(sem_calcula_temp, &param);// Libera semáforo
			// En param se guardará pdTRUE si la liberación del semáforo desbloqueó una tarea
			// y si esta tarea es de mayor prioridad a la tarea running actual.
			portYIELD_FROM_ISR(param);// Si param=pdTRUE, se fuerza a un cambio de contexto

			//printf("Cant: %d \n",timer0_cant);
			//timer0_cant=0;

		} else if (sec == 59) {
			habilitar_int_rotativo();
		}
	}

}
示例#18
0
void Clock_GetTime(int* h, int* m, int* s)
{
  RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
	*h = RTC_TimeStructure.RTC_Hours;
	*m = RTC_TimeStructure.RTC_Minutes;
	*s = RTC_TimeStructure.RTC_Seconds;
}
示例#19
0
文件: rtc.c 项目: Lasitha78/elua
// Read the time from the RTC.
static int rtc_get( lua_State *L ) {
  XMC_RTC_TIME_t t;

  // Get the time.
  RTC_GetTime( &t );

  // Construct the table to return the result
  lua_createtable( L, 0, 6 );

  lua_pushstring( L, "sec" );
  lua_pushinteger( L, t.seconds );
  lua_rawset( L, -3 );

  lua_pushstring( L, "min" );
  lua_pushinteger( L, t.minutes );
  lua_rawset( L, -3 );

  lua_pushstring( L, "hour" );
  lua_pushinteger( L, t.hours );
  lua_rawset( L, -3 );

  lua_pushstring( L, "day" );
  lua_pushinteger( L, t.days );
  lua_rawset( L, -3 );

  lua_pushstring( L, "month" );
  lua_pushinteger( L, t.month );
  lua_rawset( L, -3 );

  lua_pushstring( L, "year" );
  lua_pushinteger( L, t.year );
  lua_rawset( L, -3 );

  return 1;
}
示例#20
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") ; 
}
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);
     }
    
   
}
示例#22
0
struct tm *Cyassl_MDK_gmtime(const time_t *c) 
{ 

    RTC_TimeTypeDef RTC_Time ;
    RTC_DateTypeDef RTC_Date ;
    static struct tm date ; 

    RTC_GetTime(RTC_Format_BIN, &RTC_Time) ;
    RTC_GetDate(RTC_Format_BIN, &RTC_Date) ;

    date.tm_year = RTC_Date.RTC_Year + 100 ;
    date.tm_mon = RTC_Date.RTC_Month - 1 ;
    date.tm_mday = RTC_Date.RTC_Date ;
    date.tm_hour = RTC_Time.RTC_Hours ;
    date.tm_min = RTC_Time.RTC_Minutes ;
    date.tm_sec = RTC_Time.RTC_Seconds ;

    #if defined(DEBUG_CYASSL) 
    {
        char msg[100] ;
        sprintf(msg, "Debug::Cyassl_KEIL_gmtime(DATE=/%4d/%02d/%02d TIME=%02d:%02d:%02d)\n",
        RTC_Date.RTC_Year+2000,  RTC_Date.RTC_Month, RTC_Date.RTC_Date,
        RTC_Time.RTC_Hours,  RTC_Time.RTC_Minutes,  RTC_Time.RTC_Seconds) ; 
        CYASSL_MSG(msg) ;   
    }
    #endif
    
    return(&date) ;
}
/*********************************************************************//**
 * @brief		RTC interrupt handler sub-routine
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void RTC_IRQHandler(void)
{
	uint32_t secval;

	/* This is increment counter interrupt*/
	if (RTC_GetIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE))
	{
		secval = RTC_GetTime (LPC_RTC, RTC_TIMETYPE_SECOND);

		/* Send debug information */
		_DBG ("Second: "); _DBD(secval);
		_DBG_("");

		// Clear pending interrupt
		RTC_ClearIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE);
	}

	/* Continue to check the Alarm match*/
	if (RTC_GetIntPending(LPC_RTC, RTC_INT_ALARM))
	{
		/* Send debug information */
		_DBG_ ("ALARM 10s matched!");

		// Clear pending interrupt
		RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM);
	}
}
/**
  * @brief  Display the current time on the Hyperterminal.
  * @param  None
  * @retval None
  */
void RTC_TimeShow(void)
{
    /* Get the current Time and Date */
    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
    printf("\n\r============== Current Time Display ============================\n\r");
    printf("\n\r  The current time (Hour-Minute-Second) is :  %0.2d:%0.2d:%0.2d \n\r", RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
    /* Unfreeze the RTC DR Register */
    (void)RTC->DR;
}
示例#25
0
/*******************************************************************************
* Function name: DisplayPrintfRealTime
********************************************************************************
*
* Summary:
*   print real time from position row = 1, column = 0
*
*******************************************************************************/
void DisplayRealTime(void)
{
    uint32_t time;
    
    time = RTC_GetTime();
    sprintf(buff, "%02lu:%02lu:%02lu      ", RTC_GetHours(time),RTC_GetMinutes(time), RTC_GetSecond(time));
    LCD_Position(1,0);
    LCD_PrintString(buff);
}
示例#26
0
文件: RTC.cpp 项目: Bigboy20769/TCode
char* GetRTCTime(void)
{
	/* Get the RTC current Time */
	RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
	/* Get the RTC current Date */
	RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);
	/* Display time Format : hh:mm:ss */
	sprintf(showtime, "%.2d:%.2d:%.2d", RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
	return(showtime);
}
示例#27
0
文件: RTC.cpp 项目: Bigboy20769/TCode
char* GetRTCDate(void)
{
	/* Get the RTC current Time */
	RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
	/* Get the RTC current Date */
	RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);
	/* Display date Format : mm-dd-yy */
	sprintf(showdate, "%.2d-%.2d-%.2d", RTC_DateStructure.RTC_Month, RTC_DateStructure.RTC_Date, 2000 + RTC_DateStructure.RTC_Year);   
	return(showdate);
}
/*********************************************************************//**
 * @brief       RTC interrupt handler sub-routine
 * @param[in]   None
 * @return      None
 **********************************************************************/
void RTC_IRQHandler(void)
{
    /* This is increment counter interrupt*/
    if (RTC_GetIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE))
    {
        secval = RTC_GetTime (LPC_RTC, RTC_TIMETYPE_SECOND);

        // Clear pending interrupt
        RTC_ClearIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE);
    }
}
示例#29
0
void Get_RealTimeString(char *TimeString)
{
	char timeBuffer[9];
	uint8 scroll = 0;
	TimeStruct.Time = RTC_GetTime();
    sprintf(timeBuffer, "%02lu:%02lu:%02lu", RTC_GetHours(TimeStruct.Time), RTC_GetMinutes(TimeStruct.Time), RTC_GetSecond(TimeStruct.Time));
	for(scroll = 0; scroll < 9; scroll++)
	{
		TimeString[scroll] = timeBuffer[scroll];
	}
}
示例#30
0
void RTC_Get(tm_elems *tm){
    LDD_RTC_TTime ttime;
    RTC_GetTime(RTC, &ttime);

    tm->date = ttime.Day;
    tm->dow = ttime.DayOfWeek;
    tm->hours = ttime.Hour;
    tm->minutes = ttime.Minute;
    tm->month = ttime.Month;
    tm->seconds = ttime.Second;
    tm->year = ttime.Year - 2000;
}