#include 'bsp_led.h'/n#include 'bsp_key.h'/n/n#include /'stm32f10x.h/'/n/nvoid delay(uint32_t count)/n{/n/tfor(; count!=0; count--);/n}/n/nint main(void)/n{/n/t/n/tLED_GPIO_Config();/n/tKEY_GPIO_Config();/n/t/nwhile(1)/n{/n/n/t/n/t/tif (KEY_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN)==KEY_ON)/n/t/t{/n/t/t/t/n/t/t/tLED1_TOGGLE;/n/t/t}/n/t/t/n/t/t/GPIO_SetBits(LED1_GPIO_PORT, LED1_GPIO_PIN);/n/t/tdelay(0xfffff);/n/t/tGPIO_ResetBits(LED1_GPIO_PORT, LED1_GPIO_PIN);/n/t/tdelay(0xfffff);//n/t/t/n/t/t/n/t/t/GPIO_SetBits(LED2_GPIO_PORT, LED2_GPIO_PIN);/n/t/tdelay(0xfffff);/n/t/tGPIO_ResetBits(LED2_GPIO_PORT, LED2_GPIO_PIN);/n/t/tdelay(0xfffff);//n/t}/n}/n/n*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'C://Keil_v5//ARM//ARMCC//Bin'/nBuild target 'Target 1'/ncompiling main.c.../n'no source': Warning: #2774-D: '=' assumed following macro name /'STM32F10X_HD/' in command-line definition/nD://FWLIB-LED//User//main.c(15): warning: #223-D: function /'KEY_GPIO_Config/' declared implicitly/n /tKEY_GPIO_Config();/nD://FWLIB-LED//User//main.c(21): warning: #223-D: function /'KEY_Scan/' declared implicitly/n /t/tif (KEY_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN)==KEY_ON)/nD://FWLIB-LED//User//main.c(21): error: #20: identifier /'KEY1_GPIO_PORT/' is undefined/n /t/tif (KEY_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN)==KEY_ON)/nD://FWLIB-LED//User//main.c(21): error: #20: identifier /'KEY1_GPIO_PIN/' is undefined/n /t/tif (KEY_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN)==KEY_ON)/nD://FWLIB-LED//User//main.c(21): error: #20: identifier /'KEY_ON/' is undefined/n /t/tif (KEY_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN)==KEY_ON)/nD://FWLIB-LED//User//main.c(24): error: #20: identifier /'LED1_TOGGLE/' is undefined/n /t/t/tLED1_TOGGLE;/nD://FWLIB-LED//User//main.c: 3 warnings, 4 errors/ncompiling bsp_led.c.../n'no source': Warning: #2774-D: '=' assumed following macro name /'STM32F10X_HD/' in command-line definition/nD://FWLIB-LED//User//led//bsp_led.c: 1 warning, 0 errors/n'../Output//king.axf' - 4 Error(s), 4 Warning(s)./nTarget not created./nBuild Time Elapsed: 00:00:01还是不行呀内容:根据您提供的代码,似乎存在一些错误和未定义的变量。以下是我对您的代码的分析和更正:/n/nc/n#include 'bsp_led.h'/n#include 'bsp_key.h'/n/n#include /'stm32f10x.h/'/n/nvoid delay(uint32_t count)/n{/n for(; count!=0; count--);/n}/n/nint main(void)/n{/n LED_GPIO_Config();/n KEY_GPIO_Config();/n/n while(1)/n {/n if (KEY_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN)==KEY_ON)/n {/n LED1_TOGGLE;/n }/n/n /*GPIO_SetBits(LED1_GPIO_PORT, LED1_GPIO_PIN);/n delay(0xfffff);/n GPIO_ResetBits(LED1_GPIO_PORT, LED1_GPIO_PIN);/n delay(0xfffff);*//n/n /*GPIO_SetBits(LED2_GPIO_PORT, LED2_GPIO_PIN);/n delay(0xfffff);/n GPIO_ResetBits(LED2_GPIO_PORT, LED2_GPIO_PIN);/n delay(0xfffff);*//n }/n}/n/n/n根据您提供的代码,我注意到以下问题:/n/n1. 在主函数中,使用了KEY1_GPIO_PORTKEY1_GPIO_PINKEY_ONLED1_TOGGLE这些未定义的变量。您需要根据您的硬件定义和要求,在代码中定义或包含这些变量或宏。/n2. 在主函数中,注释掉了一些与LED2相关的代码。如果您需要使用LED2,请确保在代码中定义了LED2_GPIO_PORTLED2_GPIO_PIN并进行了相应的配置。/n/n修复这些错误后,您可以重新尝试编译和运行代码。如果您有具体的问题或需求,请提供更多信息,以便我能够更好地帮助您。

STM32F10x LED控制和按键扫描示例

原文地址: https://www.cveoy.top/t/topic/S5q 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录