解决Stm32出现main.c(136): error: #20: identifier "ADC_Channel_1" is undefined异常问题

在这里插入图片描述只需要把stm32f10x_conf.h中间的关于stm32f10x_adc.h的注释删掉就可以。
在这里插入图片描述

*** Using Compiler ‘V5.06 update 1 (build 61)’, folder: ‘D:\Keil_v5\ARM\ARMCC\Bin’ Rebuild target ‘ADC-DEMO’ assembling startup_stm32f10x_md.s… compiling main.c… compiling led.c… compiling usart1.c… compiling delay.c… compiling dht11.c… dht11.c(18): warning: #188-D: enumerated type mixed with another type HT11_DQ_OUT(0); //拉??DQ dht11.c(20): warning: #188-D: enumerated type mixed with another type HT11_DQ_OUT(1); //DQ=1 dht11.c: 2 warnings, 0 errors compiling sys.c… compiling stm32f10x_it.c… compiling adc.c… adc.h(41): error: #20: identifierADC_HandleTypeDef” is undefined void adc_channel_set(ADC_HandleTypeDef adc_handle, uint32_t ch,uint32_t rank, uint32_t stime); / ADC通??? / adc.c(25): error: #20: identifierADC_HandleTypeDef” is undefined ADC_HandleTypeDef g_adc_handle; / ADC?浔? / adc.c(38): error: #20: identifierADC_DATAALIGN_RIGHT” is undefined g_adc_handle.Init.DataAlign = ADC_DATAALIGN_RIGHT; / ?荻??敕?式:?叶??? / adc.c(39): error: #20: identifierADC_SCAN_DISABLE” is undefined g_adc_handle.Init.ScanConvMode = ADC_SCAN_DISABLE; / ??扫??模式,???玫?一??通?? / adc.c(44): error: #20: identifierADC_SOFTWARE_START” is undefined g_adc_handle.Init.ExternalTrigConv = ADC_SOFTWARE_START; / 触发转换方式:?砑シ? / adc.c(45): warning: #223-D: function “HAL_ADC_Init” declared implicitly HAL_ADC_Init(&g_adc_handle); / ??始化 / adc.c(47): warning: #223-D: function “HAL_ADCEx_Calibration_Start” declared implicitly HAL_ADCEx_Calibration_Start(&g_adc_handle); / 校准ADC */ adc.c(56): error: #20: identifierADC_HandleTypeDef” is undefined void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) adc.c(61): error: #20: identifier “RCC_PeriphCLKInitTypeDef” is undefined RCC_PeriphCLKInitTypeDef adc_clk_init = {0}; adc.c(63): warning: #223-D: function “__HAL_RCC_ADC1_CLK_ENABLE” declared implicitly DC_ADCX_CHY_CLK_ENABLE(); /* 使??ADCx时?? */ adc.c(64): warning: #223-D: function “__HAL_RCC_GPIOA_CLK_ENABLE” declared implicitly DC_ADCX_CHY_GPIO_CLK_ENABLE(); /* 开??GPIO时?? / adc.c(67): error: #20: identifier “RCC_PERIPHCLK_ADCis undefined adc_clk_init.PeriphClockSelection = RCC_PERIPHCLK_ADC; / ADC???时?? / adc.c(68): error: #20: identifier “RCC_ADCPCLK2_DIV6” is undefined adc_clk_init.AdcClockSelection = RCC_ADCPCLK2_DIV6; / ??频???6时??为72M/6=12MHz / adc.c(69): warning: #223-D: function “HAL_RCCEx_PeriphCLKConfig” declared implicitly HAL_RCCEx_PeriphCLKConfig(&adc_clk_init); / ???ADC时?? / adc.c(72): error: #136: struct “” has no field “Pin” gpio_init_struct.Pin = ADC_ADCX_CHY_GPIO_PIN; / ADC通??IO?? / adc.c(72): error: #20: identifier “GPIO_PIN_2is undefined gpio_init_struct.Pin = DC_ADCX_CHY_GPIO_PIN; / ADC通??IO?? / adc.c(73): error: #136: struct “” has no field “Mode” gpio_init_struct.Mode = GPIO_MODE_ANALOG; / 模?? / adc.c(73): error: #20: identifier “GPIO_MODE_ANALOG” is undefined gpio_init_struct.Mode = GPIO_MODE_ANALOG; / 模?? */ adc.c(74): warning: #223-D: function “HAL_GPIO_Init” declared implicitly HAL_GPIO_Init(ADC_ADCX_CHY_GPIO_PORT, &gpio_init_struct); adc.c(94): error: #20: identifierADC_HandleTypeDef” is undefined void adc_channel_set(ADC_HandleTypeDef adc_handle, uint32_t ch, uint32_t rank, uint32_t stime) adc.c(96): error: #20: identifierADC_ChannelConfTypeDef” is undefined ADC_ChannelConfTypeDef adc_ch_conf; adc.c(101): warning: #223-D: function “HAL_ADC_ConfigChannel” declared implicitly HAL_ADC_ConfigChannel(adc_handle, &adc_ch_conf); / 通??? / adc.c(111): error: #20: identifierADC_REGULAR_RANK_1is undefined adc_channel_set(&g_adc_handle , ch, ADC_REGULAR_RANK_1, ADC_SAMPLETIME_239CYCLES_5); / ???通?溃???泻筒???时?? / adc.c(111): error: #20: identifierADC_SAMPLETIME_239CYCLES_5” is undefined adc_channel_set(&g_adc_handle , ch, ADC_REGULAR_RANK_1, ADC_SAMPLETIME_239CYCLES_5); / ???通?溃???泻筒???时?? / adc.c(113): warning: #223-D: function “HAL_ADC_Start” declared implicitly HAL_ADC_Start(&g_adc_handle); / 开??ADC / adc.c(114): warning: #223-D: function “HAL_ADC_PollForConversion” declared implicitly HAL_ADC_PollForConversion(&g_adc_handle, 10); / ??询转换 / adc.c(115): warning: #223-D: function “HAL_ADC_GetValue” declared implicitly return (uint16_t)HAL_ADC_GetValue(&g_adc_handle); / 返???罱?一??ADC1???榈?转换?峁? / adc.c(132): warning: #223-D: function “delay_ms” declared implicitly delay_ms(5); adc.c: 11 warnings, 17 errors compiling atim.c… atim.h(44): error: #20: identifier “TIM_HandleTypeDef” is undefined extern TIM_HandleTypeDef g_timx_cplm_pwm_handle; / 定时??x?浔? / atim.c(26): error: #20: identifier “TIM_HandleTypeDef” is undefined TIM_HandleTypeDef g_timx_cplm_pwm_handle; / 定时??x?浔? */ atim.c(46): error: #20: identifier “TIM_OC_InitTypeDef” is undefined TIM_OC_InitTypeDef tim_oc_cplm_pwm = {0}; atim.c(48): warning: #223-D: function “__HAL_RCC_TIM1_CLK_ENABLE” declared implicitly TIM_TIMX_CPLM_CLK_ENABLE(); /* TIMx 时??使?? */ atim.c(49): warning: #223-D: function “__HAL_RCC_GPIOA_CLK_ENABLE” declared implicitly TIM_TIMX_CPLM_CHY_GPIO_CLK_ENABLE(); /* 通??X??应IO??时??使?? */ atim.c(50): warning: #223-D: function “__HAL_RCC_GPIOB_CLK_ENABLE” declared implicitly TIM_TIMX_CPLM_CHYN_GPIO_CLK_ENABLE(); /* 通??X互补通?蓝?应IO??时??使?? / atim.c(52): error: #136: struct “” has no field “Pin” gpio_init_struct.Pin = ATIM_TIMX_CPLM_CHY_GPIO_PIN; atim.c(52): error: #20: identifier “GPIO_PIN_8” is undefined gpio_init_struct.Pin = TIM_TIMX_CPLM_CHY_GPIO_PIN; atim.c(53): error: #136: struct “” has no field “Mode” gpio_init_struct.Mode = GPIO_MODE_AF_PP; atim.c(53): error: #20: identifier “GPIO_MODE_AF_PP” is undefined gpio_init_struct.Mode = GPIO_MODE_AF_PP; atim.c(54): error: #136: struct “” has no field “Pull” gpio_init_struct.Pull = GPIO_PULLDOWN; atim.c(54): error: #20: identifier “GPIO_PULLDOWN” is undefined gpio_init_struct.Pull = GPIO_PULLDOWN; atim.c(55): error: #136: struct “” has no field “Speed” gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH ; atim.c(55): error: #20: identifier “GPIO_SPEED_FREQ_HIGH” is undefined gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH ; atim.c(56): warning: #223-D: function “HAL_GPIO_Init” declared implicitly HAL_GPIO_Init(ATIM_TIMX_CPLM_CHY_GPIO_PORT, &gpio_init_struct); atim.c(58): error: #136: struct “” has no field “Pin” gpio_init_struct.Pin = ATIM_TIMX_CPLM_CHYN_GPIO_PIN; atim.c(58): error: #20: identifier “GPIO_PIN_13” is undefined gpio_init_struct.Pin = TIM_TIMX_CPLM_CHYN_GPIO_PIN; atim.c(63): error: #20: identifier “TIM_COUNTERMODE_UP” is undefined g_timx_cplm_pwm_handle.Init.CounterMode = TIM_COUNTERMODE_UP; / ???黾???模式 / atim.c(65): error: #20: identifier “TIM_CLOCKDIVISION_DIV4” is undefined g_timx_cplm_pwm_handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; / CKD[1:0] = 10, tDTS = 4 * tCK_INT = Ft / 4 = 18Mhz / atim.c(66): error: #20: identifier “TIM_AUTORELOAD_PRELOAD_ENABLE” is undefined g_timx_cplm_pwm_handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; / 使??影?蛹拇???TIMx_ARR / atim.c(67): warning: #223-D: function “HAL_TIM_PWM_Init” declared implicitly HAL_TIM_PWM_Init(&g_timx_cplm_pwm_handle); atim.c(69): error: #20: identifier “TIM_OCMODE_PWM1is undefined tim_oc_cplm_pwm.OCMode = TIM_OCMODE_PWM1; / PWM模式1 / atim.c(70): error: #20: identifier “TIM_OCPOLARITY_HIGH” is undefined tim_oc_cplm_pwm.OCPolarity = TIM_OCPOLARITY_HIGH; / OCy ?偷?平??效 / atim.c(71): error: #20: identifier “TIM_OCNPOLARITY_HIGH” is undefined tim_oc_cplm_pwm.OCNPolarity = TIM_OCNPOLARITY_HIGH; / OCyN ?偷?平??效 / atim.c(72): error: #20: identifier “TIM_OCIDLESTATE_RESET” is undefined tim_oc_cplm_pwm.OCIdleState = TIM_OCIDLESTATE_RESET; / 当MOE=0,OCx=1 / atim.c(73): error: #20: identifier “TIM_OCNIDLESTATE_RESET” is undefined tim_oc_cplm_pwm.OCNIdleState = TIM_OCNIDLESTATE_RESET; / 当MOE=0,OCxN=1 / atim.c(75): warning: #223-D: function “HAL_TIM_PWM_ConfigChannel” declared implicitly HAL_TIM_PWM_ConfigChannel(&g_timx_cplm_pwm_handle, &tim_oc_cplm_pwm, ATIM_TIMX_CPLM_CHY); atim.c(75): error: #20: identifier “TIM_CHANNEL_1is undefined HAL_TIM_PWM_ConfigChannel(&g_timx_cplm_pwm_handle, &tim_oc_cplm_pwm, TIM_TIMX_CPLM_CHY); atim.c(77): warning: #223-D: function “HAL_TIM_PWM_Start” declared implicitly HAL_TIM_PWM_Start(&g_timx_cplm_pwm_handle, ATIM_TIMX_CPLM_CHY); / 使??OCy?涑? / atim.c(78): warning: #223-D: function “HAL_TIMEx_PWMN_Start” declared implicitly HAL_TIMEx_PWMN_Start(&g_timx_cplm_pwm_handle, ATIM_TIMX_CPLM_CHY); / 使??OCyN?涑? / atim.c: 8 warnings, 22 errors compiling atk_fan.c… atim.h(44): error: #20: identifier “TIM_HandleTypeDef” is undefined extern TIM_HandleTypeDef g_timx_cplm_pwm_handle; / 定时??x?浔? / atk_fan.c(43): warning: #223-D: function “HAL_TIM_PWM_Stop” declared implicitly HAL_TIM_PWM_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); / ?乇???通???涑? / atk_fan.c(43): error: #20: identifier “TIM_CHANNEL_1is undefined HAL_TIM_PWM_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); / ?乇???通???涑? / atk_fan.c(44): warning: #223-D: function “HAL_TIMEx_PWMN_Stop” declared implicitly HAL_TIMEx_PWMN_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); / ?乇栈ゲ?通???涑? / atk_fan.c(55): warning: #223-D: function “HAL_TIM_PWM_Stop” declared implicitly HAL_TIM_PWM_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); / ?乇???通???涑? / atk_fan.c(55): error: #20: identifier “TIM_CHANNEL_1is undefined HAL_TIM_PWM_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); / ?乇???通???涑? / atk_fan.c(56): warning: #223-D: function “HAL_TIMEx_PWMN_Stop” declared implicitly HAL_TIMEx_PWMN_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); / ?乇栈ゲ?通???涑? / atk_fan.c(60): warning: #223-D: function “HAL_TIM_PWM_Start” declared implicitly HAL_TIM_PWM_Start(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); / 开???通???涑? / atk_fan.c(64): warning: #223-D: function “HAL_TIMEx_PWMN_Start” declared implicitly HAL_TIMEx_PWMN_Start(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); / 开?艋ゲ?通???涑? / atk_fan.c(75): warning: #223-D: function “__HAL_TIM_GetAutoreload” declared implicitly if (para < (__HAL_TIM_GetAutoreload(&g_timx_cplm_pwm_handle))) / ??? */ atk_fan.c(77): warning: #223-D: function “__HAL_TIM_SetCompare” declared implicitly __HAL_TIM_SetCompare(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1, para); atk_fan.c(77): error: #20: identifier “TIM_CHANNEL_1is undefined __HAL_TIM_SetCompare(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1, para); atk_fan.c: 8 warnings, 4 errors compiling atk_light.c… adc.h(41): error: #20: identifierADC_HandleTypeDef” is undefined void adc_channel_set(ADC_HandleTypeDef adc_handle, uint32_t ch,uint32_t rank, uint32_t stime); / ADC通??? */ atk_light.c(33): warning: #223-D: function “__HAL_RCC_GPIOA_CLK_ENABLE” declared implicitly TK_LIGHT_DO_GPIO_CLK_ENABLE(); /* DO时??使?? / atk_light.c(35): error: #136: struct “” has no field “Pin” gpio_init_struct.Pin = ATK_LIGHT_DO_GPIO_PIN; / DO?? / atk_light.c(35): error: #20: identifier “GPIO_PIN_3” is undefined gpio_init_struct.Pin = TK_LIGHT_DO_GPIO_PIN; / DO?? / atk_light.c(36): error: #136: struct “” has no field “Mode” gpio_init_struct.Mode = GPIO_MODE_INPUT; / ??? / atk_light.c(36): error: #20: identifier “GPIO_MODE_INPUT” is undefined gpio_init_struct.Mode = GPIO_MODE_INPUT; / ??? / atk_light.c(37): error: #136: struct “” has no field “Pull” gpio_init_struct.Pull = GPIO_NOPULL; / ???拉 / atk_light.c(37): error: #20: identifier “GPIO_NOPULL” is undefined gpio_init_struct.Pull = GPIO_NOPULL; / ???拉 / atk_light.c(38): warning: #223-D: function “HAL_GPIO_Init” declared implicitly HAL_GPIO_Init(ATK_LIGHT_DO_GPIO_PORT, &gpio_init_struct); / DO?懦?始化 / atk_light.c(51): error: #20: identifierADC_CHANNEL_2is undefined temp_val = adc_get_result_average( DC_ADCX_CHY, 10); / ??取平??值 */ atk_light.c: 2 warnings, 8 errors compiling stm32f10x_gpio.c… compiling stm32f10x_rcc.c… compiling stm32f10x_usart.c… compiling stm32f10x_adc.c… compiling stm32f10x_dma.c… compiling stm32f10x_flash.c… compiling stm32f10x_rtc.c… compiling misc.c… compiling stm32f10x_tim.c… compiling stm32f10x_exti.c… compiling core_cm3.c… compiling system_stm32f10x.c… “.\STM32-DEMO.axf” - 51 Error(s), 31 Warning(s). Target not created. Build Time Elapsed: 00:00:06
06-26
*** Using Compiler &#39;V5.06 update 1 (build 61)&#39;, folder: &#39;D:\Keil_v5\ARM\ARMCC\Bin&#39; Rebuild target &#39;ADC-DEMO&#39; assembling startup_stm32f10x_md.s... compiling main.c... compiling led.c... compiling usart1.c... compiling delay.c... compiling dht11.c... dht11.c(18): warning: #188-D: enumerated type mixed with another type HT11_DQ_OUT(0); //拉??DQ dht11.c(20): warning: #188-D: enumerated type mixed with another type HT11_DQ_OUT(1); //DQ=1 dht11.c: 2 warnings, 0 errors compiling sys.c... compiling stm32f10x_it.c... compiling adc.c... adc.h(41): error: #20: identifier "ADC_HandleTypeDef" is undefined void adc_channel_set(ADC_HandleTypeDef *adc_handle, uint32_t ch,uint32_t rank, uint32_t stime); /* ADC通?????? */ adc.c(25): error: #20: identifier "ADC_HandleTypeDef" is undefined ADC_HandleTypeDef g_adc_handle; /* ADC?浔? */ adc.c(38): error: #20: identifier "ADC_DATAALIGN_RIGHT" is undefined g_adc_handle.Init.DataAlign = ADC_DATAALIGN_RIGHT; /* ?荻??敕?式:?叶??? */ adc.c(39): error: #20: identifier "ADC_SCAN_DISABLE" is undefined g_adc_handle.Init.ScanConvMode = ADC_SCAN_DISABLE; /* ??扫??模式,???玫?一??通?? */ adc.c(44): error: #20: identifier "ADC_SOFTWARE_START" is undefined g_adc_handle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* 触发转换方式:?砑シ? */ adc.c(45): warning: #223-D: function "HAL_ADC_Init" declared implicitly HAL_ADC_Init(&g_adc_handle); /* ??始化 */ adc.c(47): warning: #223-D: function "HAL_ADCEx_Calibration_Start" declared implicitly HAL_ADCEx_Calibration_Start(&g_adc_handle); /* 校准ADC */ adc.c(56): error: #20: identifier "ADC_HandleTypeDef" is undefined void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) adc.c(61): error: #20: identifier "RCC_PeriphCLKInitTypeDef" is undefined RCC_PeriphCLKInitTypeDef adc_clk_init = {0}; adc.c(63): warning: #223-D: function "__HAL_RCC_ADC1_CLK_ENABLE" declared implicitly DC_ADCX_CHY_CLK_ENABLE(); /* 使??ADCx时?? */ adc.c(64): warning: #223-D: function "__HAL_RCC_GPIOA_CLK_ENABLE" declared implicitly DC_ADCX_CHY_GPIO_CLK_ENABLE(); /* 开??GPIO时?? */ adc.c(67): error: #20: identifier "RCC_PERIPHCLK_ADC" is undefined adc_clk_init.PeriphClockSelection = RCC_PERIPHCLK_ADC; /* ADC????时?? */ adc.c(68): error: #20: identifier "RCC_ADCPCLK2_DIV6" is undefined adc_clk_init.AdcClockSelection = RCC_ADCPCLK2_DIV6; /* ??频????6时??为72M/6=12MHz */ adc.c(69): warning: #223-D: function "HAL_RCCEx_PeriphCLKConfig" declared implicitly HAL_RCCEx_PeriphCLKConfig(&adc_clk_init); /* ????ADC时?? */ adc.c(72): error: #136: struct "<unnamed>" has no field "Pin" gpio_init_struct.Pin = ADC_ADCX_CHY_GPIO_PIN; /* ADC通??IO?? */ adc.c(72): error: #20: identifier "GPIO_PIN_2" is undefined gpio_init_struct.Pin = DC_ADCX_CHY_GPIO_PIN; /* ADC通??IO?? */ adc.c(73): error: #136: struct "<unnamed>" has no field "Mode" gpio_init_struct.Mode = GPIO_MODE_ANALOG; /* 模?? */ adc.c(73): error: #20: identifier "GPIO_MODE_ANALOG" is undefined gpio_init_struct.Mode = GPIO_MODE_ANALOG; /* 模?? */ adc.c(74): warning: #223-D: function "HAL_GPIO_Init" declared implicitly HAL_GPIO_Init(ADC_ADCX_CHY_GPIO_PORT, &gpio_init_struct); adc.c(94): error: #20: identifier "ADC_HandleTypeDef" is undefined void adc_channel_set(ADC_HandleTypeDef *adc_handle, uint32_t ch, uint32_t rank, uint32_t stime) adc.c(96): error: #20: identifier "ADC_ChannelConfTypeDef" is undefined ADC_ChannelConfTypeDef adc_ch_conf; adc.c(101): warning: #223-D: function "HAL_ADC_ConfigChannel" declared implicitly HAL_ADC_ConfigChannel(adc_handle, &adc_ch_conf); /* 通?????? */ adc.c(111): error: #20: identifier "ADC_REGULAR_RANK_1" is undefined adc_channel_set(&g_adc_handle , ch, ADC_REGULAR_RANK_1, ADC_SAMPLETIME_239CYCLES_5); /* ????通?溃????泻筒???时?? */ adc.c(111): error: #20: identifier "ADC_SAMPLETIME_239CYCLES_5" is undefined adc_channel_set(&g_adc_handle , ch, ADC_REGULAR_RANK_1, ADC_SAMPLETIME_239CYCLES_5); /* ????通?溃????泻筒???时?? */ adc.c(113): warning: #223-D: function "HAL_ADC_Start" declared implicitly HAL_ADC_Start(&g_adc_handle); /* 开??ADC */ adc.c(114): warning: #223-D: function "HAL_ADC_PollForConversion" declared implicitly HAL_ADC_PollForConversion(&g_adc_handle, 10); /* ??询转换 */ adc.c(115): warning: #223-D: function "HAL_ADC_GetValue" declared implicitly return (uint16_t)HAL_ADC_GetValue(&g_adc_handle); /* 返???罱?一??ADC1?????榈?转换?峁? */ adc.c(132): warning: #223-D: function "delay_ms" declared implicitly delay_ms(5); adc.c: 11 warnings, 17 errors compiling atim.c... atim.h(44): error: #20: identifier "TIM_HandleTypeDef" is undefined extern TIM_HandleTypeDef g_timx_cplm_pwm_handle; /* 定时??x?浔? */ atim.c(26): error: #20: identifier "TIM_HandleTypeDef" is undefined TIM_HandleTypeDef g_timx_cplm_pwm_handle; /* 定时??x?浔? */ atim.c(46): error: #20: identifier "TIM_OC_InitTypeDef" is undefined TIM_OC_InitTypeDef tim_oc_cplm_pwm = {0}; atim.c(48): warning: #223-D: function "__HAL_RCC_TIM1_CLK_ENABLE" declared implicitly TIM_TIMX_CPLM_CLK_ENABLE(); /* TIMx 时??使?? */ atim.c(49): warning: #223-D: function "__HAL_RCC_GPIOA_CLK_ENABLE" declared implicitly TIM_TIMX_CPLM_CHY_GPIO_CLK_ENABLE(); /* 通??X??应IO??时??使?? */ atim.c(50): warning: #223-D: function "__HAL_RCC_GPIOB_CLK_ENABLE" declared implicitly TIM_TIMX_CPLM_CHYN_GPIO_CLK_ENABLE(); /* 通??X互补通?蓝?应IO??时??使?? */ atim.c(52): error: #136: struct "<unnamed>" has no field "Pin" gpio_init_struct.Pin = ATIM_TIMX_CPLM_CHY_GPIO_PIN; atim.c(52): error: #20: identifier "GPIO_PIN_8" is undefined gpio_init_struct.Pin = TIM_TIMX_CPLM_CHY_GPIO_PIN; atim.c(53): error: #136: struct "<unnamed>" has no field "Mode" gpio_init_struct.Mode = GPIO_MODE_AF_PP; atim.c(53): error: #20: identifier "GPIO_MODE_AF_PP" is undefined gpio_init_struct.Mode = GPIO_MODE_AF_PP; atim.c(54): error: #136: struct "<unnamed>" has no field "Pull" gpio_init_struct.Pull = GPIO_PULLDOWN; atim.c(54): error: #20: identifier "GPIO_PULLDOWN" is undefined gpio_init_struct.Pull = GPIO_PULLDOWN; atim.c(55): error: #136: struct "<unnamed>" has no field "Speed" gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH ; atim.c(55): error: #20: identifier "GPIO_SPEED_FREQ_HIGH" is undefined gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH ; atim.c(56): warning: #223-D: function "HAL_GPIO_Init" declared implicitly HAL_GPIO_Init(ATIM_TIMX_CPLM_CHY_GPIO_PORT, &gpio_init_struct); atim.c(58): error: #136: struct "<unnamed>" has no field "Pin" gpio_init_struct.Pin = ATIM_TIMX_CPLM_CHYN_GPIO_PIN; atim.c(58): error: #20: identifier "GPIO_PIN_13" is undefined gpio_init_struct.Pin = TIM_TIMX_CPLM_CHYN_GPIO_PIN; atim.c(63): error: #20: identifier "TIM_COUNTERMODE_UP" is undefined g_timx_cplm_pwm_handle.Init.CounterMode = TIM_COUNTERMODE_UP; /* ???黾???模式 */ atim.c(65): error: #20: identifier "TIM_CLOCKDIVISION_DIV4" is undefined g_timx_cplm_pwm_handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; /* CKD[1:0] = 10, tDTS = 4 * tCK_INT = Ft / 4 = 18Mhz */ atim.c(66): error: #20: identifier "TIM_AUTORELOAD_PRELOAD_ENABLE" is undefined g_timx_cplm_pwm_handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; /* 使??影?蛹拇???TIMx_ARR */ atim.c(67): warning: #223-D: function "HAL_TIM_PWM_Init" declared implicitly HAL_TIM_PWM_Init(&g_timx_cplm_pwm_handle); atim.c(69): error: #20: identifier "TIM_OCMODE_PWM1" is undefined tim_oc_cplm_pwm.OCMode = TIM_OCMODE_PWM1; /* PWM模式1 */ atim.c(70): error: #20: identifier "TIM_OCPOLARITY_HIGH" is undefined tim_oc_cplm_pwm.OCPolarity = TIM_OCPOLARITY_HIGH; /* OCy ?偷?平??效 */ atim.c(71): error: #20: identifier "TIM_OCNPOLARITY_HIGH" is undefined tim_oc_cplm_pwm.OCNPolarity = TIM_OCNPOLARITY_HIGH; /* OCyN ?偷?平??效 */ atim.c(72): error: #20: identifier "TIM_OCIDLESTATE_RESET" is undefined tim_oc_cplm_pwm.OCIdleState = TIM_OCIDLESTATE_RESET; /* 当MOE=0,OCx=1 */ atim.c(73): error: #20: identifier "TIM_OCNIDLESTATE_RESET" is undefined tim_oc_cplm_pwm.OCNIdleState = TIM_OCNIDLESTATE_RESET; /* 当MOE=0,OCxN=1 */ atim.c(75): warning: #223-D: function "HAL_TIM_PWM_ConfigChannel" declared implicitly HAL_TIM_PWM_ConfigChannel(&g_timx_cplm_pwm_handle, &tim_oc_cplm_pwm, ATIM_TIMX_CPLM_CHY); atim.c(75): error: #20: identifier "TIM_CHANNEL_1" is undefined HAL_TIM_PWM_ConfigChannel(&g_timx_cplm_pwm_handle, &tim_oc_cplm_pwm, TIM_TIMX_CPLM_CHY); atim.c(77): warning: #223-D: function "HAL_TIM_PWM_Start" declared implicitly HAL_TIM_PWM_Start(&g_timx_cplm_pwm_handle, ATIM_TIMX_CPLM_CHY); /* 使??OCy?涑? */ atim.c(78): warning: #223-D: function "HAL_TIMEx_PWMN_Start" declared implicitly HAL_TIMEx_PWMN_Start(&g_timx_cplm_pwm_handle, ATIM_TIMX_CPLM_CHY); /* 使??OCyN?涑? */ atim.c: 8 warnings, 22 errors compiling atk_fan.c... atim.h(44): error: #20: identifier "TIM_HandleTypeDef" is undefined extern TIM_HandleTypeDef g_timx_cplm_pwm_handle; /* 定时??x?浔? */ atk_fan.c(43): warning: #223-D: function "HAL_TIM_PWM_Stop" declared implicitly HAL_TIM_PWM_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); /* ?乇???通???涑? */ atk_fan.c(43): error: #20: identifier "TIM_CHANNEL_1" is undefined HAL_TIM_PWM_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); /* ?乇???通???涑? */ atk_fan.c(44): warning: #223-D: function "HAL_TIMEx_PWMN_Stop" declared implicitly HAL_TIMEx_PWMN_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); /* ?乇栈ゲ?通???涑? */ atk_fan.c(55): warning: #223-D: function "HAL_TIM_PWM_Stop" declared implicitly HAL_TIM_PWM_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); /* ?乇???通???涑? */ atk_fan.c(55): error: #20: identifier "TIM_CHANNEL_1" is undefined HAL_TIM_PWM_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); /* ?乇???通???涑? */ atk_fan.c(56): warning: #223-D: function "HAL_TIMEx_PWMN_Stop" declared implicitly HAL_TIMEx_PWMN_Stop(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); /* ?乇栈ゲ?通???涑? */ atk_fan.c(60): warning: #223-D: function "HAL_TIM_PWM_Start" declared implicitly HAL_TIM_PWM_Start(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); /* 开????通???涑? */ atk_fan.c(64): warning: #223-D: function "HAL_TIMEx_PWMN_Start" declared implicitly HAL_TIMEx_PWMN_Start(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1); /* 开?艋ゲ?通???涑? */ atk_fan.c(75): warning: #223-D: function "__HAL_TIM_GetAutoreload" declared implicitly if (para < (__HAL_TIM_GetAutoreload(&g_timx_cplm_pwm_handle))) /* ???? */ atk_fan.c(77): warning: #223-D: function "__HAL_TIM_SetCompare" declared implicitly __HAL_TIM_SetCompare(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1, para); atk_fan.c(77): error: #20: identifier "TIM_CHANNEL_1" is undefined __HAL_TIM_SetCompare(&g_timx_cplm_pwm_handle, TIM_CHANNEL_1, para); atk_fan.c: 8 warnings, 4 errors compiling atk_light.c... adc.h(41): error: #20: identifier "ADC_HandleTypeDef" is undefined void adc_channel_set(ADC_HandleTypeDef *adc_handle, uint32_t ch,uint32_t rank, uint32_t stime); /* ADC通?????? */ atk_light.c(33): warning: #223-D: function "__HAL_RCC_GPIOA_CLK_ENABLE" declared implicitly TK_LIGHT_DO_GPIO_CLK_ENABLE(); /* DO时??使?? */ atk_light.c(35): error: #136: struct "<unnamed>" has no field "Pin" gpio_init_struct.Pin = ATK_LIGHT_DO_GPIO_PIN; /* DO?? */ atk_light.c(35): error: #20: identifier "GPIO_PIN_3" is undefined gpio_init_struct.Pin = TK_LIGHT_DO_GPIO_PIN; /* DO?? */ atk_light.c(36): error: #136: struct "<unnamed>" has no field "Mode" gpio_init_struct.Mode = GPIO_MODE_INPUT; /* ???? */ atk_light.c(36): error: #20: identifier "GPIO_MODE_INPUT" is undefined gpio_init_struct.Mode = GPIO_MODE_INPUT; /* ???? */ atk_light.c(37): error: #136: struct "<unnamed>" has no field "Pull" gpio_init_struct.Pull = GPIO_NOPULL; /* ??????拉 */ atk_light.c(37): error: #20: identifier "GPIO_NOPULL" is undefined gpio_init_struct.Pull = GPIO_NOPULL; /* ??????拉 */ atk_light.c(38): warning: #223-D: function "HAL_GPIO_Init" declared implicitly HAL_GPIO_Init(ATK_LIGHT_DO_GPIO_PORT, &gpio_init_struct); /* DO?懦?始化 */ atk_light.c(51): error: #20: identifier "ADC_CHANNEL_2" is undefined temp_val = adc_get_result_average( DC_ADCX_CHY, 10); /* ??取平??值 */ atk_light.c: 2 warnings, 8 errors compiling stm32f10x_gpio.c... compiling stm32f10x_rcc.c... compiling stm32f10x_usart.c... compiling stm32f10x_adc.c... compiling stm32f10x_dma.c... compiling stm32f10x_flash.c... compiling stm32f10x_rtc.c... compiling misc.c... compiling stm32f10x_tim.c... compiling stm32f10x_exti.c... compiling core_cm3.c... compiling system_stm32f10x.c... ".\STM32-DEMO.axf" - 51 Error(s), 31 Warning(s). Target not created. Build Time Elapsed: 00:00:06
06-26
*** Using Compiler &#39;V5.06 update 1 (build 61)&#39;, folder: &#39;D:\Keil_v5\ARM\ARMCC\Bin&#39; *** Note: Rebuilding project, since &#39;Options->Output->Create Batch File&#39; is selected. Rebuild target &#39;ADC-DEMO&#39; assembling startup_stm32f10x_md.s... compiling main.c... compiling led.c... compiling usart1.c... compiling delay.c... compiling dht11.c... dht11.c(18): warning: #188-D: enumerated type mixed with another type HT11_DQ_OUT(0); //拉??DQ dht11.c(20): warning: #188-D: enumerated type mixed with another type HT11_DQ_OUT(1); //DQ=1 dht11.c: 2 warnings, 0 errors compiling sys.c... compiling stm32f10x_it.c... compiling stm32f10x_gpio.c... compiling stm32f10x_rcc.c... compiling stm32f10x_usart.c... compiling stm32f10x_adc.c... compiling stm32f10x_dma.c... compiling stm32f10x_flash.c... compiling stm32f10x_rtc.c... compiling misc.c... compiling stm32f10x_tim.c... compiling stm32f10x_exti.c... compiling core_cm3.c... compiling system_stm32f10x.c... compiling adc.c... ..\Drivers\BSP\ADC\adc.h(41): error: #20: identifier "ADC_HandleTypeDef" is undefined void adc_channel_set(ADC_HandleTypeDef *adc_handle, uint32_t ch,uint32_t rank, uint32_t stime); /* ADC通?????? */ ..\Drivers\BSP\ADC\adc.c(25): error: #20: identifier "ADC_HandleTypeDef" is undefined ADC_HandleTypeDef g_adc_handle; /* ADC?浔? */ ..\Drivers\BSP\ADC\adc.c(38): error: #20: identifier "ADC_DATAALIGN_RIGHT" is undefined g_adc_handle.Init.DataAlign = ADC_DATAALIGN_RIGHT; /* ?荻??敕?式:?叶??? */ ..\Drivers\BSP\ADC\adc.c(39): error: #20: identifier "ADC_SCAN_DISABLE" is undefined g_adc_handle.Init.ScanConvMode = ADC_SCAN_DISABLE; /* ??扫??模式,???玫?一??通?? */ ..\Drivers\BSP\ADC\adc.c(44): error: #20: identifier "ADC_SOFTWARE_START" is undefined g_adc_handle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* 触发转换方式:?砑シ? */ ..\Drivers\BSP\ADC\adc.c(45): warning: #223-D: function "HAL_ADC_Init" declared implicitly HAL_ADC_Init(&g_adc_handle); /* ??始化 */ ..\Drivers\BSP\ADC\adc.c(47): warning: #223-D: function "HAL_ADCEx_Calibration_Start" declared implicitly HAL_ADCEx_Calibration_Start(&g_adc_handle); /* 校准ADC */ ..\Drivers\BSP\ADC\adc.c(56): error: #20: identifier "ADC_HandleTypeDef" is undefined void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) ..\Drivers\BSP\ADC\adc.c(61): error: #20: identifier "RCC_PeriphCLKInitTypeDef" is undefined RCC_PeriphCLKInitTypeDef adc_clk_init = {0}; ..\Drivers\BSP\ADC\adc.c(63): warning: #223-D: function "__HAL_RCC_ADC1_CLK_ENABLE" declared implicitly DC_ADCX_CHY_CLK_ENABLE(); /* 使??ADCx时?? */ ..\Drivers\BSP\ADC\adc.c(64): warning: #223-D: function "__HAL_RCC_GPIOA_CLK_ENABLE" declared implicitly DC_ADCX_CHY_GPIO_CLK_ENABLE(); /* 开??GPIO时?? */ ..\Drivers\BSP\ADC\adc.c(67): error: #20: identifier "RCC_PERIPHCLK_ADC" is undefined adc_clk_init.PeriphClockSelection = RCC_PERIPHCLK_ADC; /* ADC????时?? */ ..\Drivers\BSP\ADC\adc.c(68): error: #20: identifier "RCC_ADCPCLK2_DIV6" is undefined adc_clk_init.AdcClockSelection = RCC_ADCPCLK2_DIV6; /* ??频????6时??为72M/6=12MHz */ ..\Drivers\BSP\ADC\adc.c(69): warning: #223-D: function "HAL_RCCEx_PeriphCLKConfig" declared implicitly HAL_RCCEx_PeriphCLKConfig(&adc_clk_init); /* ????ADC时?? */ ..\Drivers\BSP\ADC\adc.c(72): error: #136: struct "<unnamed>" has no field "Pin" gpio_init_struct.Pin = ADC_ADCX_CHY_GPIO_PIN; /* ADC通??IO?? */ ..\Drivers\BSP\ADC\adc.c(72): error: #20: identifier "GPIO_PIN_2" is undefined gpio_init_struct.Pin = DC_ADCX_CHY_GPIO_PIN; /* ADC通??IO?? */ ..\Drivers\BSP\ADC\adc.c(73): error: #136: struct "<unnamed>" has no field "Mode" gpio_init_struct.Mode = GPIO_MODE_ANALOG; /* 模?? */ ..\Drivers\BSP\ADC\adc.c(73): error: #20: identifier "GPIO_MODE_ANALOG" is undefined gpio_init_struct.Mode = GPIO_MODE_ANALOG; /* 模?? */ ..\Drivers\BSP\ADC\adc.c(74): warning: #223-D: function "HAL_GPIO_Init" declared implicitly HAL_GPIO_Init(ADC_ADCX_CHY_GPIO_PORT, &gpio_init_struct); ..\Drivers\BSP\ADC\adc.c(94): error: #20: identifier "ADC_HandleTypeDef" is undefined void adc_channel_set(ADC_HandleTypeDef *adc_handle, uint32_t ch, uint32_t rank, uint32_t stime) ..\Drivers\BSP\ADC\adc.c(96): error: #20: identifier "ADC_ChannelConfTypeDef" is undefined ADC_ChannelConfTypeDef adc_ch_conf; ..\Drivers\BSP\ADC\adc.c(101): warning: #223-D: function "HAL_ADC_ConfigChannel" declared implicitly HAL_ADC_ConfigChannel(adc_handle, &adc_ch_conf); /* 通?????? */ ..\Drivers\BSP\ADC\adc.c(111): error: #20: identifier "ADC_REGULAR_RANK_1" is undefined adc_channel_set(&g_adc_handle , ch, ADC_REGULAR_RANK_1, ADC_SAMPLETIME_239CYCLES_5); /* ????通?溃????泻筒???时?? */ ..\Drivers\BSP\ADC\adc.c(111): error: #20: identifier "ADC_SAMPLETIME_239CYCLES_5" is undefined adc_channel_set(&g_adc_handle , ch, ADC_REGULAR_RANK_1, ADC_SAMPLETIME_239CYCLES_5); /* ????通?溃????泻筒???时?? */ ..\Drivers\BSP\ADC\adc.c(113): warning: #223-D: function "HAL_ADC_Start" declared implicitly HAL_ADC_Start(&g_adc_handle); /* 开??ADC */ ..\Drivers\BSP\ADC\adc.c(114): warning: #223-D: function "HAL_ADC_PollForConversion" declared implicitly HAL_ADC_PollForConversion(&g_adc_handle, 10); /* ??询转换 */ ..\Drivers\BSP\ADC\adc.c(115): warning: #223-D: function "HAL_ADC_GetValue" declared implicitly return (uint16_t)HAL_ADC_GetValue(&g_adc_handle); /* 返???罱?一??ADC1?????榈?转换?峁? */ ..\Drivers\BSP\ADC\adc.c(132): warning: #223-D: function "delay_ms" declared implicitly delay_ms(5); ..\Drivers\BSP\ADC\adc.c: 11 warnings, 17 errors compiling atk_fan.c... ..\Drivers\BSP\ATK_FAN\atk_fan.c(22): error: #5: cannot open source input file "atim.h": No such file or directory #include "atim.h" ..\Drivers\BSP\ATK_FAN\atk_fan.c: 0 warnings, 1 error compiling atk_light.c... ..\Drivers\BSP\ATK_LIGHT\atk_light.c(22): error: #5: cannot open source input file "adc.h": No such file or directory #include "adc.h" ..\Drivers\BSP\ATK_LIGHT\atk_light.c: 0 warnings, 1 error compiling atim.c... ..\Drivers\BSP\TIM\atim.h(44): error: #20: identifier "TIM_HandleTypeDef" is undefined extern TIM_HandleTypeDef g_timx_cplm_pwm_handle; /* 定时??x?浔? */ ..\Drivers\BSP\TIM\atim.c(26): error: #20: identifier "TIM_HandleTypeDef" is undefined TIM_HandleTypeDef g_timx_cplm_pwm_handle; /* 定时??x?浔? */ ..\Drivers\BSP\TIM\atim.c(46): error: #20: identifier "TIM_OC_InitTypeDef" is undefined TIM_OC_InitTypeDef tim_oc_cplm_pwm = {0}; ..\Drivers\BSP\TIM\atim.c(48): warning: #223-D: function "__HAL_RCC_TIM1_CLK_ENABLE" declared implicitly TIM_TIMX_CPLM_CLK_ENABLE(); /* TIMx 时??使?? */ ..\Drivers\BSP\TIM\atim.c(49): warning: #223-D: function "__HAL_RCC_GPIOA_CLK_ENABLE" declared implicitly TIM_TIMX_CPLM_CHY_GPIO_CLK_ENABLE(); /* 通??X??应IO??时??使?? */ ..\Drivers\BSP\TIM\atim.c(50): warning: #223-D: function "__HAL_RCC_GPIOB_CLK_ENABLE" declared implicitly TIM_TIMX_CPLM_CHYN_GPIO_CLK_ENABLE(); /* 通??X互补通?蓝?应IO??时??使?? */ ..\Drivers\BSP\TIM\atim.c(52): error: #136: struct "<unnamed>" has no field "Pin" gpio_init_struct.Pin = ATIM_TIMX_CPLM_CHY_GPIO_PIN; ..\Drivers\BSP\TIM\atim.c(52): error: #20: identifier "GPIO_PIN_8" is undefined gpio_init_struct.Pin = TIM_TIMX_CPLM_CHY_GPIO_PIN; ..\Drivers\BSP\TIM\atim.c(53): error: #136: struct "<unnamed>" has no field "Mode" gpio_init_struct.Mode = GPIO_MODE_AF_PP; ..\Drivers\BSP\TIM\atim.c(53): error: #20: identifier "GPIO_MODE_AF_PP" is undefined gpio_init_struct.Mode = GPIO_MODE_AF_PP; ..\Drivers\BSP\TIM\atim.c(54): error: #136: struct "<unnamed>" has no field "Pull" gpio_init_struct.Pull = GPIO_PULLDOWN; ..\Drivers\BSP\TIM\atim.c(54): error: #20: identifier "GPIO_PULLDOWN" is undefined gpio_init_struct.Pull = GPIO_PULLDOWN; ..\Drivers\BSP\TIM\atim.c(55): error: #136: struct "<unnamed>" has no field "Speed" gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH ; ..\Drivers\BSP\TIM\atim.c(55): error: #20: identifier "GPIO_SPEED_FREQ_HIGH" is undefined gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH ; ..\Drivers\BSP\TIM\atim.c(56): warning: #223-D: function "HAL_GPIO_Init" declared implicitly HAL_GPIO_Init(ATIM_TIMX_CPLM_CHY_GPIO_PORT, &gpio_init_struct); ..\Drivers\BSP\TIM\atim.c(58): error: #136: struct "<unnamed>" has no field "Pin" gpio_init_struct.Pin = ATIM_TIMX_CPLM_CHYN_GPIO_PIN; ..\Drivers\BSP\TIM\atim.c(58): error: #20: identifier "GPIO_PIN_13" is undefined gpio_init_struct.Pin = TIM_TIMX_CPLM_CHYN_GPIO_PIN; ..\Drivers\BSP\TIM\atim.c(63): error: #20: identifier "TIM_COUNTERMODE_UP" is undefined g_timx_cplm_pwm_handle.Init.CounterMode = TIM_COUNTERMODE_UP; /* ???黾???模式 */ ..\Drivers\BSP\TIM\atim.c(65): error: #20: identifier "TIM_CLOCKDIVISION_DIV4" is undefined g_timx_cplm_pwm_handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; /* CKD[1:0] = 10, tDTS = 4 * tCK_INT = Ft / 4 = 18Mhz */ ..\Drivers\BSP\TIM\atim.c(66): error: #20: identifier "TIM_AUTORELOAD_PRELOAD_ENABLE" is undefined g_timx_cplm_pwm_handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; /* 使??影?蛹拇???TIMx_ARR */ ..\Drivers\BSP\TIM\atim.c(67): warning: #223-D: function "HAL_TIM_PWM_Init" declared implicitly HAL_TIM_PWM_Init(&g_timx_cplm_pwm_handle); ..\Drivers\BSP\TIM\atim.c(69): error: #20: identifier "TIM_OCMODE_PWM1" is undefined tim_oc_cplm_pwm.OCMode = TIM_OCMODE_PWM1; /* PWM模式1 */ ..\Drivers\BSP\TIM\atim.c(70): error: #20: identifier "TIM_OCPOLARITY_HIGH" is undefined tim_oc_cplm_pwm.OCPolarity = TIM_OCPOLARITY_HIGH; /* OCy ?偷?平??效 */ ..\Drivers\BSP\TIM\atim.c(71): error: #20: identifier "TIM_OCNPOLARITY_HIGH" is undefined tim_oc_cplm_pwm.OCNPolarity = TIM_OCNPOLARITY_HIGH; /* OCyN ?偷?平??效 */ ..\Drivers\BSP\TIM\atim.c(72): error: #20: identifier "TIM_OCIDLESTATE_RESET" is undefined tim_oc_cplm_pwm.OCIdleState = TIM_OCIDLESTATE_RESET; /* 当MOE=0,OCx=1 */ ..\Drivers\BSP\TIM\atim.c(73): error: #20: identifier "TIM_OCNIDLESTATE_RESET" is undefined tim_oc_cplm_pwm.OCNIdleState = TIM_OCNIDLESTATE_RESET; /* 当MOE=0,OCxN=1 */ ..\Drivers\BSP\TIM\atim.c(75): warning: #223-D: function "HAL_TIM_PWM_ConfigChannel" declared implicitly HAL_TIM_PWM_ConfigChannel(&g_timx_cplm_pwm_handle, &tim_oc_cplm_pwm, ATIM_TIMX_CPLM_CHY); ..\Drivers\BSP\TIM\atim.c(75): error: #20: identifier "TIM_CHANNEL_1" is undefined HAL_TIM_PWM_ConfigChannel(&g_timx_cplm_pwm_handle, &tim_oc_cplm_pwm, TIM_TIMX_CPLM_CHY); ..\Drivers\BSP\TIM\atim.c(77): warning: #223-D: function "HAL_TIM_PWM_Start" declared implicitly HAL_TIM_PWM_Start(&g_timx_cplm_pwm_handle, ATIM_TIMX_CPLM_CHY); /* 使??OCy?涑? */ ..\Drivers\BSP\TIM\atim.c(78): warning: #223-D: function "HAL_TIMEx_PWMN_Start" declared implicitly HAL_TIMEx_PWMN_Start(&g_timx_cplm_pwm_handle, ATIM_TIMX_CPLM_CHY); /* 使??OCyN?涑? */ ..\Drivers\BSP\TIM\atim.c: 8 warnings, 22 errors ".\STM32-DEMO.axf" - 41 Error(s), 21 Warning(s). Target not created. Build Time Elapsed: 00:00:07
06-26
*** Using Compiler &#39;V5.06 update 7 (build 960)&#39;, folder: &#39;D:\Keil_v5\ARM\ARMCC\Bin&#39; Build target &#39;Target 1&#39; compiling PWM.c... Hardware\common.h(6): error: #101: "RESET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #101: "SET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(8): error: #101: "DISABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #101: "ENABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\Start\stm32f10x.h") typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\PWM.c: 0 warnings, 7 errors compiling Buzzer.c... Hardware\Buzzer.c(28): error: #20: identifier "KEY_S2" is undefined if(key_val == KEY_S2) { Hardware\Buzzer.c(36): warning: #223-D: function "HAL_GetTick" declared implicitly if(buzzerState && (HAL_GetTick() - lastToggle > 500)) { Hardware\Buzzer.c(38): warning: #223-D: function "GPIO_ToggleBits" declared implicitly GPIO_ToggleBits(BUZZER_PORT, BUZZER_PIN); // 鍒囨崲鐘舵€? Hardware\Buzzer.c: 2 warnings, 1 error compiling LightSensor.c... Hardware\LightSensor.c(2): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\LightSensor.c: 0 warnings, 1 error compiling OLED.c... Hardware\OLED.c(3): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\OLED.c: 0 warnings, 1 error compiling main.c... .\Hardware\lightsensor.h(3): error: #3: #include file ".\Hardware\lightsensor.h" includes itself #include "lightsensor.h" // 去掉下划线[^1] User\main.c: 0 warnings, 1 error compiling Key.c... Hardware\Key.c(13): error: #20: identifier "KEY_S0_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S0_PIN; Hardware\Key.c(15): error: #20: identifier "KEY_S0_PORT" is undefined GPIO_Init(KEY_S0_PORT, &GPIO_InitStructure); Hardware\Key.c(18): error: #20: identifier "KEY_S1_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S1_PIN; Hardware\Key.c(19): error: #20: identifier "KEY_S1_PORT" is undefined GPIO_Init(KEY_S1_PORT, &GPIO_InitStructure); Hardware\Key.c(22): error: #20: identifier "KEY_S2_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S2_PIN; Hardware\Key.c(23): error: #20: identifier "KEY_S2_PORT" is undefined GPIO_Init(KEY_S2_PORT, &GPIO_InitStructure); Hardware\Key.c(26): error: #20: identifier "KEY_S3_PIN" is undefined GPIO_InitStructure.GPIO_Pin = KEY_S3_PIN; Hardware\Key.c(27): error: #20: identifier "KEY_S3_PORT" is undefined GPIO_Init(KEY_S3_PORT, &GPIO_InitStructure); Hardware\Key.c(34): error: #20: identifier "KEY_S0_PORT" is undefined if(key_up && (GPIO_ReadInputDataBit(KEY_S0_PORT, KEY_S0_PIN) == Bit_SET || Hardware\Key.c(34): error: #20: identifier "KEY_S0_PIN" is undefined if(key_up && (GPIO_ReadInputDataBit(KEY_S0_PORT, KEY_S0_PIN) == Bit_SET || Hardware\Key.c(35): error: #20: identifier "KEY_S1_PORT" is undefined GPIO_ReadInputDataBit(KEY_S1_PORT, KEY_S1_PIN) == Bit_SET || Hardware\Key.c(35): error: #20: identifier "KEY_S1_PIN" is undefined GPIO_ReadInputDataBit(KEY_S1_PORT, KEY_S1_PIN) == Bit_SET || Hardware\Key.c(36): error: #20: identifier "KEY_S2_PORT" is undefined GPIO_ReadInputDataBit(KEY_S2_PORT, KEY_S2_PIN) == Bit_SET || Hardware\Key.c(36): error: #20: identifier "KEY_S2_PIN" is undefined GPIO_ReadInputDataBit(KEY_S2_PORT, KEY_S2_PIN) == Bit_SET || Hardware\Key.c(37): error: #20: identifier "KEY_S3_PORT" is undefined GPIO_ReadInputDataBit(KEY_S3_PORT, KEY_S3_PIN) == Bit_SET)) { Hardware\Key.c(37): error: #20: identifier "KEY_S3_PIN" is undefined GPIO_ReadInputDataBit(KEY_S3_PORT, KEY_S3_PIN) == Bit_SET)) { Hardware\Key.c(38): warning: #223-D: function "Delay_ms" declared implicitly Delay_ms(10); // 娑堟姈寤舵椂 Hardware\Key.c(48): error: #20: identifier "KEY_S3" is undefined return KEY_S3; Hardware\Key.c(57): error: #20: identifier "KEY_NONE" is undefined return KEY_NONE; Hardware\Key.c: 1 warning, 18 errors compiling LED.c... Hardware\LED.c(7): error: #20: identifier "LED_FlowMode" is undefined static LED_FlowMode flowMode = LED_FLOW_OFF; Hardware\LED.c(9): error: #20: identifier "BREATH_OFF" is undefined static BreathState breathState = BREATH_OFF; Hardware\LED.c(23): error: #20: identifier "LED_PINS" is undefined GPIO_InitStructure.GPIO_Pin = LED_PINS; Hardware\LED.c(37): error: #20: identifier "KEY_S0" is undefined if(key_val == KEY_S0) { Hardware\LED.c(40): error: #20: identifier "LED_PINS" is undefined GPIO_SetBits(LED_PORT, LED_PINS); // 鍏抽棴鎵€鏈塋ED Hardware\LED.c(47): error: #20: identifier "LED_FLOW_FORWARD" is undefined case LED_FLOW_FORWARD: OLED_ShowString(72, 0, "FWD"); break; Hardware\LED.c(48): error: #20: identifier "LED_FLOW_BACKWARD" is undefined case LED_FLOW_BACKWARD: OLED_ShowString(72, 0, "REV"); break; Hardware\LED.c(53): error: #20: identifier "KEY_S1" is undefined if(key_val == KEY_S1) { Hardware\LED.c(54): warning: #188-D: enumerated type mixed with another type breathState = (breathState + 1) % 3; Hardware\LED.c(61): error: #20: identifier "LED_PINS" is undefined GPIO_SetBits(LED_PORT, LED_PINS); // 鍏抽棴LED Hardware\LED.c(63): error: #20: identifier "BREATH_ON" is undefined case BREATH_ON: Hardware\LED.c(67): error: #20: identifier "BREATH_FULL" is undefined case BREATH_FULL: Hardware\LED.c(75): warning: #223-D: function "HAL_GetTick" declared implicitly if(flowMode != LED_FLOW_OFF && (HAL_GetTick() - lastUpdate > 200)) { Hardware\LED.c(79): error: #20: identifier "LED_PINS" is undefined GPIO_SetBits(LED_PORT, LED_PINS); Hardware\LED.c(82): error: #20: identifier "LED_FLOW_FORWARD" is undefined if(flowMode == LED_FLOW_FORWARD) { Hardware\LED.c(93): error: #20: identifier "BREATH_ON" is undefined if(breathState == BREATH_ON && (HAL_GetTick() - lastUpdate > 10)) { Hardware\LED.c(93): warning: #223-D: function "HAL_GetTick" declared implicitly if(breathState == BREATH_ON && (HAL_GetTick() - lastUpdate > 10)) { Hardware\LED.c(34): warning: #177-D: variable "flowDir" was declared but never referenced static uint8_t flowDir = 0; // 0:宸︹啋鍙? 1:鍙斥啋宸? Hardware\LED.c: 4 warnings, 14 errors ".\Objects\Project.axf" - 43 Error(s), 7 Warning(s). Target not created.所有要修改的模块
07-12
<think>我们正在处理一个STM32项目,在Keil编译中出现了多个错误。用户要求提供所有需要修改的模块的完整代码或解决方案。根据之前的上下文,错误主要集中在头文件缺失、标识符未定义、枚举类型重定义、函数隐式声明、函数调用参数错误以及枚举与整型混合使用等问题。 我们将针对每个模块(PWM、Buzzer、LightSensor、OLED、Key、LED)提供修复后的完整代码。同时,我们也会修改main.c以适配这些修复。 注意:以下代码基于标准外设库(Standard Peripherals Library)编写。如果使用HAL库,需要相应调整。 1. LightSensor模块 问题:头文件名称不一致,缺少保护宏,函数参数不一致。 修复:统一头文件名,添加保护宏,修正函数参数。 lightsensor.h: ```c #ifndef __LIGHTSENSOR_H #define __LIGHTSENSOR_H #include "stm32f10x.h" typedef enum { LIGHT_DAY = 0, LIGHT_NIGHT } LightState; void LightSensor_Init(uint8_t is_analog_mode); uint16_t LightSensor_GetRawValue(void); LightState LightSensor_GetState(void); #endif ``` lightsensor.c: ```c #include "lightsensor.h" #include "adc.h" // 如果使用ADC #include "gpio.h" // 如果使用GPIO // 初始化函数,根据is_analog_mode选择模拟或数字模式 void LightSensor_Init(uint8_t is_analog_mode) { // 初始化代码,根据模式配置ADC或GPIO } uint16_t LightSensor_GetRawValue(void) { // 获取原始值 return 0; // 示例 } LightState LightSensor_GetState(void) { // 获取状态 return LIGHT_DAY; // 示例 } ``` 2. Key模块 问题:宏定义缺失(如KEY_S0, KEY0_PRES等) 修复:在key.h中正确定义这些宏。 key.h: ```c #ifndef __KEY_H #define __KEY_H #include "stm32f10x.h" #define KEY_S0 0x01 #define KEY_S1 0x02 #define KEY_S2 0x04 #define KEY0_PRES 1 #define KEY1_PRES 2 #define KEY2_PRES 3 #define KEY3_PRES 4 void KEY_Init(void); uint8_t KEY_Scan(void); // 修改为无参数 #endif ``` key.c: ```c #include "key.h" #include "delay.h" // 初始化按键 void KEY_Init(void) { // 初始化代码 } // 扫描按键,无参数 uint8_t KEY_Scan(void) { // 扫描逻辑 return 0; // 示例 } ``` 3. LED模块 问题:引脚宏定义缺失(如LED1_PIN),枚举类型使用不当,函数参数类型问题。 修复:在led.h中定义引脚,调整枚举类型使用,修正函数参数。 led.h: ```c #ifndef __LED_H #define __LED_H #include "stm32f10x.h" // LED引脚定义 #define LED_PORT GPIOB #define LED1_PIN GPIO_Pin_0 #define LED2_PIN GPIO_Pin_1 #define LED3_PIN GPIO_Pin_2 #define LED4_PIN GPIO_Pin_3 #define LED5_PIN GPIO_Pin_4 #define LED6_PIN GPIO_Pin_5 #define LED7_PIN GPIO_Pin_6 // 呼吸灯状态 typedef enum { LED_BREATH_OFF = 0, LED_BREATH_ON } BreathState; // 流水灯模式 typedef enum { FLOW_MODE_0 = 0, FLOW_MODE_1, FLOW_MODE_2 } FlowMode; void LED_Init(void); void LED_Flow_SetMode(FlowMode mode); void LED_Breath_SetState(BreathState state); void LED_Breath_SetPeriod(uint16_t period); void LED_Flow_Task(void); void LED_Breath_Task(void); #endif ``` led.c: ```c #include "led.h" #include "stm32f10x_gpio.h" #include "stm32f10x_tim.h" // 如果使用定时器 #include "delay.h" // 全局变量 static FlowMode flowMode = FLOW_MODE_0; static BreathState breathState = LED_BREATH_OFF; static uint16_t breathPeriod = 500; void LED_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(LED_PORT, &GPIO_InitStructure); GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); } void LED_Flow_SetMode(FlowMode mode) { flowMode = mode; } void LED_Breath_SetState(BreathState state) { breathState = state; } void LED_Breath_SetPeriod(uint16_t period) { breathPeriod = period; } void LED_Flow_Task(void) { // 流水灯任务 // 注意:避免直接使用整型算术操作枚举,先转换为整型再转回 flowMode = (FlowMode)(((uint8_t)flowMode + 1) % 3); // 示例:循环切换模式 // 实际任务逻辑 } void LED_Breath_Task(void) { // 呼吸灯任务 } ``` 4. Buzzer模块 问题:函数隐式声明,可能缺少包含文件。 修复:添加必要的头文件,并修正函数定义。 buzzer.h: ```c #ifndef __BUZZER_H #define __BUZZER_H #include "stm32f10x.h" void Buzzer_Init(void); void Buzzer_Task(void); #endif ``` buzzer.c: ```c #include "buzzer.h" #include "stm32f10x_gpio.h" // 初始化蜂鸣器 void Buzzer_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; // 假设蜂鸣器接在PB8 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_ResetBits(GPIOB, GPIO_Pin_8); } void Buzzer_Task(void) { // 蜂鸣器任务 } ``` 5. OLED模块 问题:头文件包含错误(lightsensor.h写成light_sensor.h),可能还有其他未定义。 修复:修正头文件包含,并确保函数声明正确。 oled.h: ```c #ifndef __OLED_H #define __OLED_H #include "stm32f10x.h" void OLED_Init(void); void OLED_UpdateLightState(void); // 声明函数 #endif ``` oled.c: ```c #include "oled.h" #include "lightsensor.h" // 修正头文件名 void OLED_Init(void) { // 初始化OLED } void OLED_UpdateLightState(void) { LightState state = LightSensor_GetState(); // 更新OLED显示 } ``` 6. main.c 修改 问题:函数调用参数错误,使用了未定义的标识符。 修复:按照修改后的函数原型调用,使用正确的宏定义。 ```c #include "stm32f10x.h" #include "delay.h" #include "led.h" #include "key.h" #include "lightsensor.h" // 修正头文件名 #include "buzzer.h" #include "oled.h" // 系统状态结构体(假设) typedef struct { FlowMode ledFlowMode; } SystemState; static SystemState sysState = {FLOW_MODE_0}; int main(void) { // 初始化 delay_init(); LED_Init(); KEY_Init(); LightSensor_Init(1); // 带参数初始化(1表示模拟模式) Buzzer_Init(); OLED_Init(); while(1) { uint8_t key = KEY_Scan(); // 无参数调用 if (key == KEY0_PRES) { LED_Flow_SetMode(sysState.ledFlowMode); } if (key == KEY1_PRES) { LED_Breath_SetState(LED_BREATH_ON); LED_Breath_SetPeriod(500); } // 其他任务处理 LED_Flow_Task(); LED_Breath_Task(); Buzzer_Task(); OLED_UpdateLightState(); delay_ms(10); } } ``` 7. 其他注意事项 - 删除common.h中与标准库冲突的枚举定义(如RESET, SET等),因为标准库(stm32f10x.h)中已有定义。 - 确保所有头文件都有保护宏(#ifndef ... #define ... #endif)。 - 在Keil中设置正确的头文件包含路径。 最终,清理工程并重新编译。 如果问题仍然存在,请检查是否有其他未覆盖的模块或错误。 相关问题1. 如何解决STM32项目中的重复定义错误? 2. 在Keil中如何设置头文件包含路径? 3. STM32标准外设库与HAL库在函数命名上有何区别? 4. 枚举类型在C语言中如何安全使用以避免警告? 5. 如何优化STM32工程的编译速度?</think>针对 Keil 编译中出现的重复定义和未定义标识符错误,以下是所有硬件模块的完整修复方案: ### 一、PWM 模块修复 **pwm.h**(解决枚举冲突和引脚定义): ```c #ifndef PWM_H #define PWM_H #include "stm32f10x.h" // 使用标准库的枚举避免冲突 typedef enum { PWM_CH1 = TIM_Channel_1, PWM_CH2 = TIM_Channel_2, PWM_CH3 = TIM_Channel_3, PWM_CH4 = TIM_Channel_4 } PWM_Channel; void PWM_Init(TIM_TypeDef* TIMx, PWM_Channel channel, uint16_t period, uint16_t pulse); #endif ``` **pwm.c**(修正函数实现): ```c #include "pwm.h" #include "stm32f10x_tim.h" void PWM_Init(TIM_TypeDef* TIMx, PWM_Channel channel, uint16_t period, uint16_t pulse) { TIM_TimeBaseInitTypeDef TIM_BaseStruct; TIM_OCInitTypeDef TIM_OCStruct; // 时基配置 TIM_BaseStruct.TIM_Prescaler = 72 - 1; // 72MHz/72 = 1MHz TIM_BaseStruct.TIM_CounterMode = TIM_CounterMode_Up; TIM_BaseStruct.TIM_Period = period - 1; TIM_BaseStruct.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseInit(TIMx, &TIM_BaseStruct); // PWM配置 TIM_OCStruct.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCStruct.TIM_OutputState = TIM_OutputState_Enable; TIM_OCStruct.TIM_Pulse = pulse; TIM_OCStruct.TIM_OCPolarity = TIM_OCPolarity_High; switch(channel) { case PWM_CH1: TIM_OC1Init(TIMx, &TIM_OCStruct); break; case PWM_CH2: TIM_OC2Init(TIMx, &TIM_OCStruct); break; case PWM_CH3: TIM_OC3Init(TIMx, &TIM_OCStruct); break; case PWM_CH4: TIM_OC4Init(TIMx, &TIM_OCStruct); break; } TIM_Cmd(TIMx, ENABLE); } ``` ### 二、Buzzer 模块修复 **buzzer.h**(添加头文件保护): ```c #ifndef BUZZER_H #define BUZZER_H #include "stm32f10x.h" #define BUZZER_PORT GPIOB #define BUZZER_PIN GPIO_Pin_8 void Buzzer_Init(void); void Buzzer_Beep(uint16_t duration_ms); #endif ``` **buzzer.c**(修正初始化): ```c #include "buzzer.h" #include "stm32f10x_gpio.h" #include "stm32f10x_rcc.h" void Buzzer_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStruct.GPIO_Pin = BUZZER_PIN; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(BUZZER_PORT, &GPIO_InitStruct); GPIO_ResetBits(BUZZER_PORT, BUZZER_PIN); } void Buzzer_Beep(uint16_t duration_ms) { GPIO_SetBits(BUZZER_PORT, BUZZER_PIN); Delay_ms(duration_ms); GPIO_ResetBits(BUZZER_PORT, BUZZER_PIN); } ``` ### 三、LightSensor 模块修复 **lightsensor.h**(统一命名和枚举): ```c #ifndef LIGHTSENSOR_H #define LIGHTSENSOR_H #include "stm32f10x.h" #include "stm32f10x_adc.h" typedef enum { LIGHT_DAY = 0, LIGHT_NIGHT } LightState; void LightSensor_Init(uint8_t is_analog_mode); LightState LightSensor_GetState(void); #endif ``` **lightsensor.c**(修正ADC初始化): ```c #include "lightsensor.h" #include "stm32f10x_gpio.h" #define LIGHT_SENSOR_PIN GPIO_Pin_0 #define LIGHT_SENSOR_PORT GPIOA void LightSensor_Init(uint8_t is_analog_mode) { GPIO_InitTypeDef GPIO_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); if(is_analog_mode) { GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN; } else { GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU; } GPIO_InitStruct.GPIO_Pin = LIGHT_SENSOR_PIN; GPIO_Init(LIGHT_SENSOR_PORT, &GPIO_InitStruct); } LightState LightSensor_GetState(void) { if(GPIO_ReadInputDataBit(LIGHT_SENSOR_PORT, LIGHT_SENSOR_PIN) == Bit_SET) { return LIGHT_DAY; } return LIGHT_NIGHT; } ``` ### 四、OLED 模块修复 **oled.h**(修正头文件包含): ```c #ifndef OLED_H #define OLED_H #include "stm32f10x.h" #include "i2c.h" // 假设使用I2C驱动 void OLED_Init(void); void OLED_DisplayLightState(LightState state); #endif ``` **oled.c**(修正函数实现): ```c #include "oled.h" #include "lightsensor.h" // 修正头文件名 void OLED_Init(void) { // I2C初始化代码 // ... } void OLED_DisplayLightState(LightState state) { const char* status = (state == LIGHT_DAY) ? "DAY" : "NIGHT"; // OLED显示代码 // ... } ``` ### 五、Key 模块修复 **key.h**(添加所有必需定义): ```c #ifndef KEY_H #define KEY_H #include "stm32f10x.h" // 按键引脚定义 #define KEY0_PIN GPIO_Pin_0 #define KEY1_PIN GPIO_Pin_1 #define KEY2_PIN GPIO_Pin_2 #define KEY_PORT GPIOA // 按键状态宏 #define KEY0_PRES 1 #define KEY1_PRES 2 #define KEY2_PRES 3 void KEY_Init(void); uint8_t KEY_Scan(void); #endif ``` **key.c**(修正扫描逻辑): ```c #include "key.h" #include "stm32f10x_gpio.h" #include "delay.h" void KEY_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStruct.GPIO_Pin = KEY0_PIN | KEY1_PIN | KEY2_PIN; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(KEY_PORT, &GPIO_InitStruct); } uint8_t KEY_Scan(void) { if(GPIO_ReadInputDataBit(KEY_PORT, KEY0_PIN) == RESET) { Delay_ms(10); // 消抖 if(GPIO_ReadInputDataBit(KEY_PORT, KEY0_PIN) == RESET) return KEY0_PRES; } // 其他按键类似处理 return 0; } ``` ### 六、LED 模块修复 **led.h**(完整枚举和宏定义): ```c #ifndef LED_H #define LED_H #include "stm32f10x.h" // LED引脚定义 #define LED_PORT GPIOB #define LED1_PIN GPIO_Pin_0 #define LED2_PIN GPIO_Pin_1 #define LED3_PIN GPIO_Pin_2 #define LED4_PIN GPIO_Pin_3 #define LED5_PIN GPIO_Pin_4 #define LED6_PIN GPIO_Pin_5 #define LED7_PIN GPIO_Pin_6 // 呼吸灯状态 typedef enum { LED_BREATH_OFF = 0, LED_BREATH_ON } BreathState; // 流水灯模式 typedef enum { FLOW_MODE_0 = 0, FLOW_MODE_1, FLOW_MODE_2 } FlowMode; void LED_Init(void); void LED_Toggle(uint16_t pin); #endif ``` **led.c**(修正类型转换): ```c #include "led.h" #include "stm32f10x_gpio.h" void LED_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStruct.GPIO_Pin = LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(LED_PORT, &GPIO_InitStruct); GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); } void LED_Toggle(uint16_t pin) { GPIO_WriteBit(LED_PORT, pin, (BitAction)(1 - GPIO_ReadOutputDataBit(LED_PORT, pin))); } ``` ### 七、main.c 统一修复 ```c #include "stm32f10x.h" #include "delay.h" #include "led.h" #include "key.h" #include "lightsensor.h" #include "buzzer.h" #include "oled.h" int main(void) { // 外设初始化 delay_init(); LED_Init(); KEY_Init(); LightSensor_Init(1); // 模拟模式 Buzzer_Init(); OLED_Init(); FlowMode currentMode = FLOW_MODE_0; while(1) { uint8_t key = KEY_Scan(); // 按键处理 if(key == KEY0_PRES) { currentMode = (FlowMode)((uint8_t)currentMode + 1) % 3; } // 光敏传感器处理 LightState light = LightSensor_GetState(); OLED_DisplayLightState(light); // LED流水灯 if(currentMode == FLOW_MODE_0) { LED_Toggle(LED1_PIN); } // 其他模式处理... delay_ms(100); } } ``` ### 关键修复总结: 1. **头文件保护**:所有头文件添加 `#ifndef ... #define ... #endif` 结构 2. **枚举冲突**:删除自定义的 `RESET/SET` 等枚举,使用标准库定义[^1] 3. **引脚统一定义**:在各自模块头文件中明确定义所有引脚 4. **函数参数匹配**:修正 `LightSensor_Init()` 等函数的参数传递 5. **类型转换**:对枚举算术操作添加显式类型转换 `(FlowMode)((uint8_t)currentMode + 1)` 6. **包含路径**:确保 Keil 包含所有模块路径(`Options for Target → C/C++ → Include Paths`) > **编译后操作**: > 1. 执行 `Project → Clean Target` > 2. 点击 `Rebuild All` 按钮 > 3. 确认输出窗口显示 `0 Error(s), 0 Warning(s)`
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值