Пример #1
0
void clockInit(void)
{
    /* NVIC configuration */
    rtcNvicConfig();

    /* Backup data register value is not correct or not yet programmed (when
       the first time the program is executed) */
    if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) {
        /* RTC Configuration */
        rtcConfig();

        /* Adjust time by values entered by the user on the hyperterminal */
        //setTime(t);

        BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
    }
    else  {
        /* Check if the Power On Reset flag is set */
        if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) {
            printStr("\r\n\n Power On Reset occurred....");
        }

        /* Check if the Pin Reset flag is set */
        else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) {
            printStr("\r\n\n External Reset occurred....");
        }

        /* Wait for RTC registers synchronization */
        RTC_WaitForSynchro();

        /* Enable the RTC Second */
        RTC_ITConfig(RTC_IT_SEC, ENABLE);

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

#ifdef RTCClockOutput_Enable
    /* Enable PWR and BKP clocks */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

    /* Allow access to BKP Domain */
    PWR_BackupAccessCmd(ENABLE);

    /* Disable the Tamper Pin */
    BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
                                 functionality must be disabled */

    /* Enable RTC Clock Output on Tamper Pin */
    BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
#endif

    /* Clear reset flags */
    RCC_ClearFlag();

    /* RTC Clock Calibration */
    //...
}
Пример #2
0
void clockInit(void)
{
    /* NVIC configuration */
    rtcNvicConfig();

    /* RTC Configuration */
    rtcConfig();

    /* RTC Clock Calibration */
    //...
}
Пример #3
0
/* FUNCION PRINCIPAL, PUNTO DE ENTRADA AL PROGRAMA LUEGO DE RESET. */
int main(void){

   /* ------------- INICIALIZACIONES ------------- */

   /* Inicializar la placa */
   boardConfig();

   /* Inicializar el conteo de Ticks con resolución de 1ms, sin tickHook */
   tickConfig( 1, 0 );

   /* Inicializar DigitalIO */
   digitalConfig( 0, ENABLE_DIGITAL_IO );

   /* Configuración de pines de entrada para Teclas de la CIAA-NXP */
   digitalConfig( TEC1, INPUT );
   digitalConfig( TEC2, INPUT );
   digitalConfig( TEC3, INPUT );
   digitalConfig( TEC4, INPUT );

   /* Configuración de pines de salida para Leds de la CIAA-NXP */
   digitalConfig( LEDR, OUTPUT );
   digitalConfig( LEDG, OUTPUT );
   digitalConfig( LEDB, OUTPUT );
   digitalConfig( LED1, OUTPUT );
   digitalConfig( LED2, OUTPUT );
   digitalConfig( LED3, OUTPUT );

   /* Inicializar UART_USB a 115200 baudios */
   uartConfig( UART_USB, 115200 );
   
   /* Estructura RTC */
   RTC_t rtc;
   
   rtc.year = 2016;
   rtc.month = 7;
   rtc.mday = 3;
   rtc.wday = 1;
   rtc.hour = 13;
   rtc.min = 17;
   rtc.sec= 0;

   bool_t val = 0;
   uint8_t i = 0;

   /* Inicializar RTC */
   val = rtcConfig( &rtc );

   delay_t delay1s;
   delayConfig( &delay1s, 1000 );
   
   delay(2000);
   
   for( i=0; i<10; i++ ){
      /* Leer fecha y hora */
      val = rtcRead( &rtc );
      /* Mostrar fecha y hora en formato "DD/MM/YYYY, HH:MM:SS" */
      showDateAndTime( &rtc );
      delay(1000);
   }
   
   rtc.year = 2016;
   rtc.month = 7;
   rtc.mday = 3;
   rtc.wday = 1;
   rtc.hour = 14;
   rtc.min = 30;
   rtc.sec= 0;
   
   /* Establecer fecha y hora */
   val = rtcWrite( &rtc );

   /* ------------- REPETIR POR SIEMPRE ------------- */
   while(1) {

      if( delayRead( &delay1s ) ){
         /* Leer fecha y hora */
         val = rtcRead( &rtc );
         /* Mostrar fecha y hora en formato "DD/MM/YYYY, HH:MM:SS" */
         showDateAndTime( &rtc );
      }

   }

   /* NO DEBE LLEGAR NUNCA AQUI, debido a que a este programa no es llamado
      por ningun S.O. */
   return 0 ;
}