00001
00014
00015
00016
00017 #include "circle.h"
00018
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00040
00041 NODEBUG2 void RTC_Init( void )
00042 {
00043
00044 RCC_APB1PeriphClockCmd( RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE );
00045
00046
00047 PWR_BackupAccessCmd( ENABLE );
00048
00049
00050 RCC_LSEConfig( RCC_LSE_ON );
00051
00052
00053
00054
00055
00056 #ifndef BUG_RTC_CRYSTAL
00057 #if LED_INV
00058 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED0, Bit_RESET );
00059 #else
00060 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED0, Bit_SET );
00061 #endif
00062
00063 while ( RCC_GetFlagStatus( RCC_FLAG_LSERDY ) == RESET )
00064 {}
00065
00066 #if LED_INV
00067 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED0, Bit_SET );
00068 #else
00069 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED0, Bit_RESET );
00070 #endif
00071 #endif
00072
00073
00074 RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE );
00075
00076
00077 RCC_RTCCLKCmd( ENABLE );
00078
00079 #ifndef BUG_RTC_CRYSTAL
00080 #if LED_INV
00081 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_RESET );
00082 #else
00083 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_SET );
00084 #endif
00085
00086
00087 RTC_WaitForSynchro();
00088
00089 #if LED_INV
00090 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_SET );
00091 #else
00092 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_RESET );
00093 #endif
00094 #endif
00095
00096
00097 RTC_WaitForLastTask();
00098
00099
00100 RTC_ITConfig( RTC_IT_SEC, ENABLE );
00101
00102
00103 RTC_WaitForLastTask();
00104
00105
00106
00107 RTC_SetPrescaler( 32767 );
00108
00109 #ifndef BUG_RTC_CRYSTAL
00110 #if LED_INV
00111 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_RESET );
00112 #else
00113 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_SET );
00114 #endif
00115
00116
00117 RTC_WaitForLastTask();
00118
00119 #if LED_INV
00120 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_SET );
00121 #else
00122 GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_RESET );
00123 #endif
00124 #endif
00125 }
00126
00128
00129
00130
00131
00132
00133
00134
00135
00145
00146 void RTC_GetTime( u8* THH, u8* TMM, u8* TSS )
00147 {
00148 counter_t Tmp;
00149
00150
00151 Tmp = RTC_GetCounter();
00152
00153
00154 *THH = ( Tmp / 3600 ) % 24;
00155
00156
00157 *TMM = ( Tmp / 60 ) % 60;
00158
00159
00160 *TSS = Tmp % 60;
00161 }
00162
00163
00164
00165
00166
00167
00177
00178 void RTC_SetTime( u8 THH, u8 TMM, u8 TSS )
00179 {
00180
00181 RTC_SetCounter( THH * 3600 + TMM * 60 + TSS );
00182 }
00183
00184
00185
00186
00187
00188
00196
00197 void RTC_DisplayTime( void )
00198 {
00199 static counter_t last_time = 0;
00200 counter_t new_time = RTC_GetCounter();
00201
00202
00203
00204 if ( last_time != new_time )
00205 {
00206 last_time = new_time ;
00207
00208 if ( fDisplayTime == 1 )
00209 {
00210 DRAW_DisplayTime( 6, 0 ) ;
00211
00212 #if DISPLAY_TEMP
00213 UTIL_SetTempMode(0);
00214 DRAW_DisplayTemp( 90, 0 );
00215 #endif
00216 }
00217 }
00218 }