/** * @brief Main program. * @param None * @retval None */ void main(void) { /* Enable LSE */ CLK_LSEConfig(CLK_LSE_ON); /* Wait for LSE clock to be ready */ while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET); /* wait for 1 second for the LSE Stabilisation */ LSE_StabTime(); /* Select LSE (32.768 KHz) as RTC clock source */ CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1); CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE); /* Calendar Configuration */ Calendar_Init(); /*RTC Tamper Configuration*/ Tamper_Init(); /* EvalBoard Configuration */ EvalBoard_Init(); Tamper_DelayShow(TampFilterIndex); while (1) { EnterSafeCode(); Time_Show(LCD_LINE2, SHOW_POINT2); ExitSafeCode(); } }
/** * @brief Pause Chronometer * @param None. * @retval None. */ void Time_Pause(void) { Time_Show(LCD_LINE2); LCD_SetCursorPos(LCD_LINE1, 0); if (PauseStatus == RESET) { STM_EVAL_LEDOn(LED2); LCD_Print(RESETDISPLAY); LastDisplay = 'P'; CLK_RTCClockConfig(CLK_RTCCLKSource_Off, CLK_RTCCLKDiv_1); STM_EVAL_LEDOff(LED1); } else { STM_EVAL_LEDOn(LED1); LCD_Print(DEFAULTDISPLAY); LastDisplay = 'D'; CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1); STM_EVAL_LEDOff(LED2); } /* Invert Pause Status */ PauseStatus = (BitStatus)(~PauseStatus); }
void RTC_Test(void) { /* 配置RTC秒中断优先级 */ RTC_NVIC_Config(); //USART1_Config(); RTC_CheckAndConfig(&systmtime); /* Display time in infinite loop */ Time_Show(&systmtime); }
/** * @brief Main program. * @param None * @retval : None */ int main() { /* 配置RTC秒中断优先级 */ RTC_NVIC_Config(); USART1_Config(); RTC_CheckAndConfig(&systmtime); /* Display time in infinite loop */ Time_Show(&systmtime); }
/** * @brief Main program. * @param None * @retval None */ void main(void) { /* Enable LSE */ CLK_LSEConfig(CLK_LSE_ON); /* Wait for LSE clock to be ready */ while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET); /* wait for 1 second for the LSE Stabilisation */ Delay_Seconds(1); /* Select LSE (32.768 KHz) as RTC clock source */ CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1); CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE); /*RTC Tamper Configuration*/ Tamper_Init(); /* Calendar Configuration */ Calendar_Init(); /* EvalBoard Configuration */ EvalBoard_Init(); /* RTC Time fields reset*/ Time_Reset(); /* RTC Time pause waiting for a press on SEL Key */ Time_Pause(); while (1) { EnterSafeCode(); Time_Show(LCD_LINE2); ExitSafeCode(); } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* Initialize LED1 mounted on STM3210X-EVAL board */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA , ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ; // USART 2 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ; // USART 2 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART1,&USART_InitStructure); USART_Cmd(USART1, ENABLE); /* NVIC configuration */ NVIC_Configuration(); if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { /* Backup data register value is not correct or not yet programmed (when the first time the program is executed) */ printf("\r\n\n RTC not yet configured...."); /* RTC Configuration */ RTC_Configuration(); printf("\r\n RTC configured...."); /* Adjust time by values entered by the user on the hyperterminal */ Time_Adjust(); BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { printf("\r\n\n Power On Reset occurred...."); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { printf("\r\n\n External Reset occurred...."); } printf("\r\n No need to configure RTC...."); /* 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(); /* Display time in infinite loop */ Time_Show(); }
/** * @brief Setting up the time by Serial USART1. * @param None * @retval None */ void RTC_SetTimeBySerial(void) { if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { /* Backup data register value is not correct or not yet programmed (when the first time the program is executed) */ printf("\r\n\n RTC not yet configured...."); /* RTC Configuration */ RTC_Configuration(); printf("\r\n RTC configured...."); /* Adjust time by values entered by the user on the hyperterminal */ Time_Adjust(); BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { printf("\r\n\n Power On Reset occurred...."); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { printf("\r\n\n External Reset occurred...."); } printf("\r\n No need to configure RTC...."); /* 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(); /* Display time in infinite loop */ Time_Show(); }
/**************************************************************/ //程 序 名: main() //开 发 者: MingH //入口参数: 无 //功能说明: 主函数 //**************************************************************/ int main(void) { unsigned char err_code; RCC_Config(); // 时钟初始化配置 Beep_Init(); // 蜂鸣器初始化配置 Touch_Init(); Pcie_Gpio_Init(); Tim3_Init(); RGB_Init(); //RGB 初始化 RCC_GetClocksFreq(&RCC_ClockFreq); SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); USB2Serial_Init(); // 串口初始化配置 Pwm_Init(); Adc_Init(); I2C_GPIO_Configuration(); err_code = LIS3DH_Init(); if (NO_ERROR == err_code) { printf("\r\nLIS3DH Init is succeed! \r\n"); } else { printf("\r\nLIS3DH Init is failed! \r\n"); } RTC_Init(); // RTC 初始化配置 if(SD_Init() == SD_OK) { printf ("\r\n发现SD卡!\r\n"); } else { printf("\r\n没有发现 SD 卡设备! \r\n"); } printf("\r\n\r\n"); save_sd_detect = SD_Detect(); //初始化SD卡插入状态 SysTick_Delay_ms(500); TIM_Cmd(TIM1, DISABLE); TIM_CtrlPWMOutputs(TIM1, DISABLE); while (1) { if(read_sd_detect_flag){ if (save_sd_detect != SD_Detect()){ /* 蜂鸣器响 */ TIM_Cmd(TIM1, ENABLE); TIM_CtrlPWMOutputs(TIM1, ENABLE); sd_detect_change = 1; //SD卡插入状态有变 buzzer_delay = 0; if (SD_Detect() != SD_NOT_PRESENT){ if(SD_Init() == SD_OK) { printf ("\r\n发现SD卡!\r\n"); } else { printf("\r\n没有发现 SD 卡设备! \r\n"); } printf("\r\n\r\n"); } } save_sd_detect = SD_Detect(); read_sd_detect_flag = 0; } Time_Show(); Test_Pcie_Gpio(); Touch_Key_Proc(); if (read_lis3dh_flag){ Collect_Data(ACCdata); for (i=0; i<3; i++){ if (oldACCdata[i] < ACCdata[i]){ ACCdiff[i] = ACCdata[i] - oldACCdata[i]; } else{ ACCdiff[i] = oldACCdata[i] - ACCdata[i]; } } RGB_Control(ACCdiff[0]<<1, ACCdiff[1]<<1, ACCdiff[2]<<1); for (i=0; i<3; i++){ oldACCdata[i] = ACCdata[i]; } read_lis3dh_flag = 0; } if (one_second_flag){ printf("X=%d, Y=%d, Z=%d\r\n\r\n", ACCdata[1], ACCdata[0], ACCdata[2]); Adc_Proc(); one_second_flag = 0; } } }