/** * @brief Example main entry point. * @par Parameters: * None * @retval * None */ void main(void) { u8 i = 0; u16 Timer2Count; /* Configuration of the GPIO*/ GPIO_Configuration(); /* Clock divider to HSI/1 */ CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); /* BEEP calibration */ BEEP_LSICalibrationConfig(LSIMeasurment()); /* TS Library Initialisation */ TSL_Init(); /* TS Application Initialisation */ ExtraCode_Init(); /* Tim2 Configuration */ InitializeTim2(); while (1) { ExtraCode_StateMachine(); TSL_Action(); BeepDriver_Action(); //SubCounterSounds(); } }
/** * @brief Configure the AWU time base to 12s * @param None * @retval None */ void AWU_Config(void) { /* Initialization of AWU */ /* LSI calibration for accurate auto wake up time base*/ AWU_LSICalibrationConfig(LSIMeasurment()); //slow Active halt //CLK_SlowActiveHaltWakeUpCmd(ENABLE); AWU_Cmd(ENABLE); /* The delay corresponds to the time we will stay in Halt mode */ //AWU_Init(AWU_TIMEBASE_12S); AWU_Init(AWU_TIMEBASE_2S); }
/** * @brief Example main entry point. * @par Parameters: * None * @retval * None */ void main(void) { u8 i = 0; /* Initialization of the clock */ /* Clock divider to HSI/1 */ CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); /* Initialization of I/Os in Output Mode */ GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN), GPIO_MODE_OUT_PP_LOW_FAST); /* Initialization of I/O in Input Mode with Interrupt */ GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT); /* Initialization of the Interrupt sensitivity */ EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY); /* BEEP calibration */ BEEP_LSICalibrationConfig(LSIMeasurment()); GPIO_Write(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN)); /* All LEDs ON */ /* Initialize SPI for LCD */ SPI_DeInit(); SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07); SPI_Cmd(ENABLE); /* Initialize LCD */ LCD_Init(); /* Clear LCD lines */ LCD_Clear(); /* Enable general interrupts for Key button reading */ enableInterrupts(); LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER OFF"); LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, " Press Key"); while (1) { /* Check button status */ if (ButtonPressed == TRUE) /* Button is pressed */ { ButtonPressed = FALSE; /* Change BEEP frequency */ switch (i) { case 0: BEEP_Cmd(DISABLE); Delay(100); BEEP_Init(BEEP_FREQUENCY_1KHZ); BEEP_Cmd(ENABLE); GPIO_Write(LEDS_PORT, LED1_PIN); /* LED1 ON */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER 1kHz"); i = 1; break; case 1: BEEP_Cmd(DISABLE); Delay(100); BEEP_Init(BEEP_FREQUENCY_2KHZ); BEEP_Cmd(ENABLE); GPIO_Write(LEDS_PORT, LED2_PIN); /* LED2 ON */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER 2kHz"); i = 2; break; case 2: BEEP_Cmd(DISABLE); Delay(100); BEEP_Init(BEEP_FREQUENCY_4KHZ); BEEP_Cmd(ENABLE); GPIO_Write(LEDS_PORT, LED3_PIN); /* LED3 ON */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER 4kHz"); i = 3; break; case 3: BEEP_Cmd(DISABLE); GPIO_Write(LEDS_PORT, LED4_PIN); /* LED4 ON */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER OFF"); i = 0; break; default: break; } } } }
/*主程序*/ void main() { u8 i = 0; /*时钟初始化*/ CLK_Config(); #ifdef _IWDG_ /* Check if the system has resumed from IWDG reset */ if (RST_GetFlagStatus(RST_FLAG_IWDGF) != RESET) { /* Clear IWDGF Flag */ RST_ClearFlag(RST_FLAG_IWDGF); } /* get measured LSI frequency */ LsiFreq = LSIMeasurment(); /* IWDG Configuration */ IWDG_Config(); #endif /*初始化电源控制*/ GPIO_DeInit(GPIOD); GPIO_Init(GPIOD,GPIO_PIN_3,GPIO_MODE_OUT_PP_LOW_FAST); GPIO_DeInit(GPIOC); GPIO_Init(GPIOC,GPIO_PIN_1,GPIO_MODE_OUT_PP_LOW_FAST); #ifdef __DEBUG__ /*底板MCU调试串口配置*/ DBG_Config(); #endif /*按键初始化*/ KEY_Init(); /*串口初始化*/ COMM_Init(); /*遥控器硬件初始化*/ IR_Init(); /*初始化CAN*/ CAN_Initialize(); /*打开全局中断*/ enableInterrupts(); /*上电,3.3V/12V*/ VDD3V3_ON(); VDD12_ON(); while (1) { /*按键检测*/ KEY_Process(); /*红外遥控器处理*/ IR_Process(); /*CAN通信处理*/ CAN_Process(); #ifdef _IWDG_ /*独立看门狗喂狗*/ IWDG_ReloadCounter(); #endif } }