00001 /** 00002 ****************************************************************************** 00003 * @file RTC/RTC_Timer/main.c 00004 * @author MCD Application Team 00005 * @version V1.0.1 00006 * @date 13-April-2012 00007 * @brief Main program body 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 *

© COPYRIGHT 2012 STMicroelectronics

00012 * 00013 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/software_license_agreement_liberty_v2 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 * 00025 ****************************************************************************** 00026 */ 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "main.h" 00030 00031 /** @addtogroup STM32F4xx_StdPeriph_Examples 00032 * @{ 00033 */ 00034 00035 /** @addtogroup RTC_Timer 00036 * @{ 00037 */ 00038 00039 /* Private typedef -----------------------------------------------------------*/ 00040 /* Private define ------------------------------------------------------------*/ 00041 #define MESSAGE1 "*** Progress Bar ***" 00042 #define MESSAGE2 "WAKEUP TAMPER KEY " 00043 #define MESSAGE3 " Reset Stop Start" 00044 00045 /* Private macro -------------------------------------------------------------*/ 00046 /* Private variables ---------------------------------------------------------*/ 00047 RTC_InitTypeDef RTC_InitStructure; 00048 RTC_TimeTypeDef RTC_TimeStruct; 00049 00050 /* Private function prototypes -----------------------------------------------*/ 00051 /* Private functions ---------------------------------------------------------*/ 00052 00053 /** 00054 * @brief Main program. 00055 * @param None 00056 * @retval None 00057 */ 00058 int main(void) 00059 { 00060 /*!< At this stage the microcontroller clock setting is already configured, 00061 this is done through SystemInit() function which is called from startup 00062 file (startup_stm32f4xx.s) before to branch to application main. 00063 To reconfigure the default setting of SystemInit() function, refer to 00064 system_stm32f4xx.c file 00065 */ 00066 00067 /* Initialize the LCD */ 00068 STM324xG_LCD_Init(); 00069 00070 /* Clear the LCD */ 00071 LCD_Clear(White); 00072 00073 /* Set the LCD Back Color */ 00074 LCD_SetBackColor(Blue); 00075 00076 /* Set the LCD Text Color */ 00077 LCD_SetTextColor(White); 00078 00079 /* Displays MESSAGE1 on line 1 */ 00080 LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1); 00081 00082 /* RTC configuration */ 00083 RTC_Config(); 00084 00085 /* Set the LCD Text Color */ 00086 LCD_SetTextColor(Red); 00087 00088 /* Displays a rectangle on the LCD */ 00089 LCD_DrawRect(80, 290, 25, 240 ); 00090 00091 /* Configure the external interrupt "KEY", "WAKEUP" and "TAMPER" buttons */ 00092 STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); 00093 STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_EXTI); 00094 STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI); 00095 00096 /* Configure RTC AlarmA register to generate 8 interrupts per 1 Second */ 00097 RTC_AlarmConfig(); 00098 00099 /* set LCD Font */ 00100 LCD_SetFont(&Font12x12); 00101 00102 /* Set the LCD Back Color */ 00103 LCD_SetBackColor(White); 00104 00105 /* Set the LCD Text Color */ 00106 LCD_SetTextColor(Black); 00107 00108 /* Displays MESSAGE2 and MESSAGE3 on the LCD */ 00109 LCD_DisplayStringLine(LINE(18), (uint8_t *)MESSAGE2); 00110 LCD_DisplayStringLine(LINE(19), (uint8_t *)MESSAGE3); 00111 00112 /* Infinite loop */ 00113 while (1) 00114 { 00115 } 00116 } 00117 00118 /** 00119 * @brief Configures the RTC peripheral and select the clock source. 00120 * @param None 00121 * @retval None 00122 */ 00123 void RTC_Config(void) 00124 { 00125 /* Enable the PWR clock */ 00126 RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); 00127 00128 /* Allow access to RTC */ 00129 PWR_BackupAccessCmd(ENABLE); 00130 00131 /* Reset RTC Domain */ 00132 RCC_BackupResetCmd(ENABLE); 00133 RCC_BackupResetCmd(DISABLE); 00134 00135 /* Enable the LSE OSC */ 00136 RCC_LSEConfig(RCC_LSE_ON); 00137 00138 /* Wait till LSE is ready */ 00139 while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) 00140 { 00141 } 00142 00143 /* Select the RTC Clock Source */ 00144 RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); 00145 00146 /* Configure the RTC data register and RTC prescaler */ 00147 RTC_InitStructure.RTC_AsynchPrediv = 0x7F; 00148 RTC_InitStructure.RTC_SynchPrediv = 0xFF; 00149 RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; 00150 RTC_Init(&RTC_InitStructure); 00151 00152 /* Set the time to 00h 00mn 00s AM */ 00153 RTC_TimeStruct.RTC_H12 = RTC_H12_AM; 00154 RTC_TimeStruct.RTC_Hours = 0x00; 00155 RTC_TimeStruct.RTC_Minutes = 0x00; 00156 RTC_TimeStruct.RTC_Seconds = 0x00; 00157 RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct); 00158 00159 } 00160 00161 /** 00162 * @brief Configures the RTC Alarm. 00163 * @param None 00164 * @retval None 00165 */ 00166 void RTC_AlarmConfig(void) 00167 { 00168 EXTI_InitTypeDef EXTI_InitStructure; 00169 RTC_AlarmTypeDef RTC_AlarmStructure; 00170 NVIC_InitTypeDef NVIC_InitStructure; 00171 00172 /* EXTI configuration */ 00173 EXTI_ClearITPendingBit(EXTI_Line17); 00174 EXTI_InitStructure.EXTI_Line = EXTI_Line17; 00175 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; 00176 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 00177 EXTI_InitStructure.EXTI_LineCmd = ENABLE; 00178 EXTI_Init(&EXTI_InitStructure); 00179 00180 /* Enable the RTC Alarm Interrupt */ 00181 NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn; 00182 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; 00183 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 00184 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 00185 NVIC_Init(&NVIC_InitStructure); 00186 00187 /* Set the alarmA Masks */ 00188 RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All; 00189 RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure); 00190 00191 /* Set AlarmA subseconds and enable SubSec Alarm : generate 8 interripts per Second */ 00192 RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_5); 00193 00194 /* Enable AlarmA interrupt */ 00195 RTC_ITConfig(RTC_IT_ALRA, ENABLE); 00196 00197 } 00198 00199 #ifdef USE_FULL_ASSERT 00200 00201 /** 00202 * @brief Reports the name of the source file and the source line number 00203 * where the assert_param error has occurred. 00204 * @param file: pointer to the source file name 00205 * @param line: assert_param error line source number 00206 * @retval None 00207 */ 00208 void assert_failed(uint8_t* file, uint32_t line) 00209 { 00210 /* User can add his own implementation to report the file name and line number, 00211 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00212 00213 /* Infinite loop */ 00214 while (1) 00215 { 00216 } 00217 } 00218 #endif 00219 00220 /** 00221 * @} 00222 */ 00223 00224 /** 00225 * @} 00226 */ 00227 00228 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/