ntime-core.esm-bundler.js:2259 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__asyncLoader')
时间: 2023-08-28 17:19:48 浏览: 132
这个错误提示通常是因为代码中访问了一个未定义的属性或变量。根据错误提示,是在 Promise 中读取了一个名为 '__asyncLoader' 的属性,但该属性为 undefined,所以会导致 TypeError。
该错误通常发生在使用异步加载模块时,加载过程出现了问题。您可以检查一下相关的代码,看看是否有漏掉了必要的依赖或出现了其他错误。同时,也可以在代码中加入调试语句,逐步排查错误的原因。
相关问题
ntime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.af$a found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ag found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ag$a found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ah found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ah$a found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ai found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ai$a found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.aj found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.aj$1 found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.aj$1$1 found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.aj$a found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ak found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ak$1 found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ak$a found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.ak$b found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.al found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.al$1 found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.al$2 found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.al$a found in modules jetified-kssdk-ad-3.3.76.5-runtime (:kssdk-ad-3.3.76.5:) and jetified-kssdk-ad-3.3.76.5-runtime (kssdk-ad-3.3.76.5.aar) Duplicate class com.kwad.components.core.webview.jshandler.al$b found in modules jetified-kssdk-ad-3
<think>我们正在解决一个Android项目中的依赖冲突问题,具体是关于`kssdk-ad`库的版本冲突。错误信息是:"Duplicateclassjetified-kssdk-ad-3.3.76.5-runtime"这个错误通常发生在同一个库的不同版本被多个依赖项引入,或者同一个类被包含在多个jar包中。###问题分析1.**理解错误**:`Duplicateclass`错误表示在编译或运行时发现了重复的类。这里,类`jetified-kssdk-ad-3.3.76.5-runtime`出现了重复。注意,这个类名中包含了版本号,所以可能是同一个库的不同版本被同时引入了。2.**原因**:可能的原因包括:-项目直接依赖了`kssdk-ad`的多个版本。-不同的依赖项(例如A和B)分别依赖了`kssdk-ad`的不同版本。-同一个依赖项被重复引入(例如,通过不同的路径)。3.**解决方案**:我们需要强制项目使用同一个版本。通常可以通过以下步骤:-检查依赖树,找出哪些模块引入了冲突的依赖。-使用Gradle的依赖解析策略(例如,强制使用某个版本)或者排除冲突的依赖。###解决步骤####步骤1:查看依赖树在AndroidStudio的终端中运行以下命令,查看依赖树:```bash./gradlewapp:dependencies```或者针对具体配置(例如`debugCompileClasspath`):```bash./gradlewapp:dependencies--configurationdebugCompileClasspath```在输出中搜索`kssdk-ad`,找出所有引入该库的依赖路径。####步骤2:分析冲突假设我们发现有两个依赖路径引入了`kssdk-ad`:-`com.example:libA:1.0`->`kssdk-ad:3.3.76.5`-`com.example:libB:2.0`->`kssdk-ad:3.3.76.6`这样就会导致两个版本同时存在,从而产生冲突。####步骤3:解决方案我们可以选择以下两种方法之一:#####方法1:强制使用指定版本在`build.gradle`文件中,添加如下配置:```groovyconfigurations.all{resolutionStrategy{force'com.ksc:kssdk-ad:3.3.76.5'//选择一个版本,这里以3.3.76.5为例}}```#####方法2:排除传递依赖如果某个库引入了我们不想要的版本,可以排除它:```groovydependencies{implementation('com.example:libB:2.0'){excludegroup:'com.ksc',module:'kssdk-ad'}}```####步骤4:重新构建项目应用更改后,重新同步Gradle并构建项目,检查是否解决了冲突。###注意事项-强制使用某个版本可能会引起兼容性问题,确保所选版本与其他依赖兼容。-如果问题仍然存在,可能需要检查是否还有其他地方引入了相同的库。###引用参考在解决依赖冲突时,Gradle官方文档提供了详细的依赖管理策略[^1]。§§相关问题§§1.如何查看Android项目的完整依赖树?2.Gradle依赖冲突的常见解决方法有哪些?3.如何排除特定依赖项的传递依赖?</think>### 解决 Android 项目中 kssdk-ad 3.3.76.5 版本冲突问题
#### 问题分析
当出现 `Duplicate class jetified-kssdk-ad-3.3.76.5-runtime` 错误时,通常表示:
1. **重复依赖**:多个模块引入了相同库的不同版本
2. **冲突命名空间**:类路径中存在相同包名的类
3. **Gradle 依赖解析失败**:Gradle 无法自动合并冲突版本
#### 解决方案步骤
##### 1. 定位冲突源
在项目根目录执行命令查看依赖树:
```bash
./gradlew app:dependencies --configuration releaseRuntimeClasspath
```
搜索输出中的 `kssdk-ad`,找出所有引入该库的依赖路径。
##### 2. 强制统一版本 (推荐)
在 `app/build.gradle` 中添加全局版本强制:
```groovy
android {
configurations.all {
resolutionStrategy {
// 强制使用指定版本
force 'com.ksc:kssdk-ad:3.3.76.5'
// 遇到冲突时优先选择第一个版本
failOnVersionConflict()
}
}
}
```
##### 3. 排除重复依赖
针对冲突的依赖项添加排除规则:
```groovy
dependencies {
implementation('com.libA:library1:1.0') {
exclude group: 'com.ksc', module: 'kssdk-ad'
}
implementation('com.libB:library2:2.0') {
exclude group: 'com.ksc', module: 'kssdk-ad'
}
// 显式声明所需版本
implementation 'com.ksc:kssdk-ad:3.3.76.5'
}
```
##### 4. 清理构建缓存
执行清理命令后重新构建:
```bash
./gradlew clean build --refresh-dependencies
```
#### 验证解决
检查构建日志中是否还有以下错误:
```
Duplicate class com.ksc.kssdk.ad.XXX found in modules...
```
若消失则冲突已解决。若仍存在,需检查是否有第三方库内嵌了旧版本。
#### 特殊情况处理
若冲突来自 `kssdk-ad` 自身的子模块:
```groovy
configurations {
all*.exclude group: 'com.ksc', module: 'kssdk-ad-internal' // 排除特定子模块
}
```
> **提示**:使用 `implementation` 代替 `compile` 可减少传递依赖冲突概率。依赖管理工具如 `versionCatalogs` 也能有效管理版本[^1]。
Build started: Project: Project *** Using Compiler 'V5.06 update 5 (build 528)', folder: 'E:\Keil_v5\ARM\ARMCC\Bin' Build target 'Target 1' linking... .\Objects\Project.axf: Error: L6200E: Symbol __ARM_use_no_argv multiply defined (by main.o and delay.o). .\Objects\Project.axf: Error: L6200E: Symbol Speed multiply defined (by main.o and delay.o). .\Objects\Project.axf: Error: L6200E: Symbol Temperature multiply defined (by main.o and delay.o). .\Objects\Project.axf: Error: L6200E: Symbol Mode multiply defined (by main.o and delay.o). .\Objects\Project.axf: Error: L6200E: Symbol Calculate_Temperature multiply defined (by main.o and delay.o). .\Objects\Project.axf: Error: L6200E: Symbol Key_GPIO_Init multiply defined (by main.o and delay.o). .\Objects\Project.axf: Error: L6200E: Symbol OLED_ClearLine multiply defined (by main.o and delay.o). .\Objects\Project.axf: Error: L6200E: Symbol main multiply defined (by main.o and delay.o). Not enough information to list image symbols. Not enough information to list load addresses in the image map. Finished: 2 information, 0 warning and 8 error messages. ".\Objects\Project.axf" - 8 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:00
<think>根据错误信息,问题在于多个目标文件(main.o 和 delay.o)中定义了相同的符号(包括全局变量和函数)。这通常是由于以下原因之一:
1. 在头文件中定义了全局变量或函数,导致多个源文件包含该头文件时都创建了自己的副本。
2. 在多个源文件中定义了相同的全局变量或函数。
解决方案:
1. 对于全局变量,应该在一个源文件中定义,在其他文件中使用`extern`声明。
2. 对于函数,确保每个函数只在一个源文件中定义(除非是内联函数)。
3. 检查头文件,确保其中只包含声明(使用`extern`)而不包含定义。
根据错误信息,我们注意到以下符号被重复定义:
- __ARM_use_no_argv:这是编译器内部使用的符号,通常由于在多个文件中使用`main`函数引起。
- Speed, Temperature, Mode:全局变量。
- Calculate_Temperature, Key_GPIO_Init, OLED_ClearLine:函数。
- main:主函数。
特别值得注意的是,错误信息显示`main`函数在main.o和delay.o中都有定义。这通常意味着在delay.c文件中不小心定义了一个main函数。我们需要检查delay.c文件,确保它没有定义main函数。
另外,全局变量和函数重复定义,可能是因为我们在头文件中定义了它们,然后多个源文件包含了这些头文件。
让我们重新组织代码:
步骤:
1. 将全局变量(Speed, Temperature, Mode)的定义放在main.c中,并在main.h中使用`extern`声明它们,这样其他文件可以通过包含main.h来访问这些全局变量。
2. 确保函数(Calculate_Temperature, Key_GPIO_Init, OLED_ClearLine)只在main.c中定义一次,并且在main.h中声明(使用extern或不加extern的函数声明)。
3. 检查delay.c文件,确保它没有定义main函数(这是绝对不允许的,一个工程只能有一个main函数)。
4. 确保delay.c中没有定义其他重复的全局变量和函数。
下面给出修改后的代码结构:
main.h:
```c
#ifndef __MAIN_H
#define __MAIN_H
#include "stm32f10x.h"
// 全局变量声明(使用extern)
extern int8_t Speed;
extern int16_t Temperature;
extern uint8_t Mode;
// 函数声明
void Key_GPIO_Init(void);
void OLED_ClearLine(uint8_t line, uint8_t start_col);
int16_t Calculate_Temperature(uint16_t adc_val);
#endif
```
main.c:
```c
#include "main.h"
#include "OLED.h"
#include "AD.h"
#include "Delay.h"
#include "Key.h"
// 全局变量定义(实际分配存储空间)
int8_t Speed = 0;
int16_t Temperature = 0;
uint8_t Mode = 0;
// ... 其他函数定义(Key_GPIO_Init, OLED_ClearLine, Calculate_Temperature)...
int main(void) {
// ... 主程序 ...
}
```
delay.c:
```c
#include "Delay.h"
#include "stm32f10x.h"
// 确保delay.c中没有定义main函数
// 只包含与延时相关的函数
static __IO uint32_t TimingDelay;
void SysTick_Handler(void) {
if (TimingDelay != 0x00) {
TimingDelay--;
}
}
void Delay_Init(void) {
// 初始化SysTick
if (SysTick_Config(SystemCoreClock / 1000)) {
while (1);
}
}
void Delay_ms(__IO uint32_t nTime) {
TimingDelay = nTime;
while (TimingDelay != 0);
}
```
注意:在delay.c中,我们使用了`static`关键字来定义`TimingDelay`,这样该变量就只在本文件内可见,不会与其他文件中的同名变量冲突。
另外,检查delay.h:
```c
#ifndef __DELAY_H
#define __DELAY_H
#include "stm32f10x.h"
void Delay_Init(void);
void Delay_ms(__IO uint32_t nTime);
#endif
```
最后,确保在main.c中定义的函数(如Key_GPIO_Init、OLED_ClearLine、Calculate_Temperature)在delay.c中没有定义。
如果还有错误,请检查每个源文件,确保没有重复定义函数和变量。
特别要注意:错误信息中提到了`__ARM_use_no_argv`,这个符号通常与main函数有关。确保整个工程只有一个main函数(在main.c中),其他文件中没有main函数。
如果按照上述步骤修改后仍然有错误,请检查delay.c文件,确保没有包含main函数。另外,检查其他源文件(如Key.c, AD.c等)是否也定义了相同的全局变量或函数。
如果问题仍然存在,请提供delay.c的代码,以便进一步排查。</think>根据错误信息,问题在于多个目标文件中存在重复定义的符号,特别是`__ARM_use_no_argv`和`main`函数被重复定义。这表明您的工程结构存在严重问题,需要彻底重构。以下是完整的解决方案:
### 解决方案:重构工程结构
#### 1. 工程结构重构
```
Project/
├── Core/
│ ├── main.c # 主程序
│ ├── main.h # 主程序头文件
│ └── stm32f10x_it.c # 中断处理
├── Drivers/
│ ├── AD/
│ │ ├── AD.c
│ │ └── AD.h
│ ├── OLED/
│ │ ├── OLED.c
│ │ └── OLED.h
│ ├── Key/
│ │ ├── Key.c
│ │ └── Key.h
│ └── Delay/
│ ├── Delay.c
│ └── Delay.h
├── Libraries/
│ ├── CMSIS/
│ └── STM32F10x_StdPeriph_Driver/
└── Startup/
└── startup_stm32f10x_md.s
```
#### 2. 关键文件内容
**main.h**
```c
#ifndef __MAIN_H
#define __MAIN_H
#include "stm32f10x.h"
#include "OLED.h"
#include "AD.h"
#include "Delay.h"
#include "Key.h"
// 全局变量声明
extern int8_t Speed;
extern int16_t Temperature;
extern uint8_t Mode;
// 函数声明
int16_t Calculate_Temperature(uint16_t adc_val);
void OLED_ClearLine(uint8_t line, uint8_t start_col);
#endif
```
**main.c**
```c
#include "main.h"
// 全局变量定义
int8_t Speed = 0;
int16_t Temperature = 0;
uint8_t Mode = 0;
// 温度查找表
const int16_t Temp_LUT[4096] = {
// ... 完整的4096个点映射 ...
};
int16_t Calculate_Temperature(uint16_t adc_val) {
if(adc_val >= sizeof(Temp_LUT)/sizeof(Temp_LUT[0]))
return 0;
return Temp_LUT[adc_val];
}
void OLED_ClearLine(uint8_t line, uint8_t start_col) {
char clear_str[20];
for(uint8_t i = 0; i < sizeof(clear_str)-1; i++)
clear_str[i] = ' ';
clear_str[sizeof(clear_str)-1] = '\0';
OLED_ShowString(line, start_col, clear_str);
}
int main(void) {
// ... 主程序逻辑 ...
}
```
**Delay.h**
```c
#ifndef __DELAY_H
#define __DELAY_H
#include "stm32f10x.h"
// 函数声明
void Delay_Init(void);
void Delay_ms(uint32_t ms);
uint32_t Delay_Time(void);
#endif
```
**Delay.c**
```c
#include "Delay.h"
static volatile uint32_t TimingDelay = 0; // 使用static限制作用域
void SysTick_Handler(void) {
if (TimingDelay != 0x00) {
TimingDelay--;
}
}
void Delay_Init(void) {
// 配置SysTick定时器为1ms中断
if (SysTick_Config(SystemCoreClock / 1000)) {
while (1); // 初始化失败
}
}
void Delay_ms(uint32_t ms) {
TimingDelay = ms;
while(TimingDelay != 0);
}
uint32_t Delay_Time(void) {
return TimingDelay;
}
```
**Key.h**
```c
#ifndef __KEY_H
#define __KEY_H
#include "stm32f10x.h"
// 函数声明
void Key_GPIO_Init(void);
// 宏定义
#define KEY1_DOWN() (!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1))
#define KEY2_DOWN() (!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11))
#endif
```
**Key.c**
```c
#include "Key.h"
void Key_GPIO_Init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
```
### 错误分析及解决方案
#### 1. `__ARM_use_no_argv` 重复定义
- **原因**:Keil ARM编译器在多个文件中定义了入口点
- **解决方案**:
1. 确保只有一个源文件包含`main()`函数
2. 在工程选项中设置正确的入口点:
- Options for Target → Linker → Misc controls
- 添加:`--entry=Reset_Handler`
#### 2. 全局变量重复定义
- **原因**:变量在头文件中定义而非声明
- **解决方案**:
```c
// main.h
extern int8_t Speed; // 声明
// main.c
int8_t Speed = 0; // 定义
```
#### 3. 函数重复定义
- **原因**:函数实现在头文件中
- **解决方案**:
```c
// main.h
void OLED_ClearLine(uint8_t line, uint8_t start_col); // 声明
// main.c
void OLED_ClearLine(uint8_t line, uint8_t start_col) { // 实现
// 函数体
}
```
#### 4. `main`函数重复定义
- **原因**:多个源文件包含`main()`函数
- **解决方案**:
1. 检查所有源文件,确保只有一个`main()`函数
2. 删除delay.c中的任何`main()`函数
### Keil工程配置步骤
1. **添加正确的文件到工程**:
- 只添加必要的源文件(.c)和启动文件
- 不添加头文件(.h)到工程中
2. **设置包含路径**:
- Options for Target → C/C++ → Include Paths
- 添加所有包含头文件的目录:
```
.\Inc
.\Drivers\AD
.\Drivers\OLED
.\Drivers\Delay
.\Drivers\Key
.\Libraries\CMSIS
.\Libraries\STM32F10x_StdPeriph_Driver\inc
```
3. **链接器设置**:
- Options for Target → Linker
- 取消勾选"Use Memory Layout from Target Dialog"
- 添加分散加载文件(scatter file):
```
LR_IROM1 0x08000000 0x00010000 { ; load region size_region
ER_IROM1 0x08000000 0x00010000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00005000 { ; RW data
.ANY (+RW +ZI)
}
}
```
4. **目标设置**:
- Options for Target → Target
- 设置正确的ROM和RAM地址:
- IROM1: 0x08000000, Size: 0x10000
- IRAM1: 0x20000000, Size: 0x5000
### 完整main.c示例
```c
#include "main.h"
int main(void) {
// 外设初始化
OLED_Init();
AD_Init();
Key_GPIO_Init();
Delay_Init();
OLED_Clear();
OLED_ShowString(1, 1, "Mode: ");
OLED_ShowString(2, 1, "Speed: ");
OLED_ShowString(3, 1, "Temp: ");
OLED_ShowString(3, 11, "C");
OLED_ShowString(4, 1, "ADC: ");
// 初始化显示
OLED_ShowChar(1, 7, Mode ? 'M' : 'A');
OLED_ShowSignedNum(2, 7, Speed, 3);
OLED_ShowNum(3, 7, 0, 2);
OLED_ShowChar(3, 9, '.');
OLED_ShowNum(3, 10, 0, 1);
OLED_ShowNum(4, 6, 0, 4);
while (1) {
// 温度采集
static uint16_t adc_buffer[5] = {0};
static uint8_t index = 0;
adc_buffer[index] = AD_GetValue();
index = (index + 1) % 5;
uint32_t adc_sum = 0;
for(uint8_t i=0; i<5; i++) adc_sum += adc_buffer[i];
uint16_t adc_avg = adc_sum / 5;
// 温度计算
Temperature = Calculate_Temperature(adc_avg);
// 温度范围限制
if(Temperature < -100) Temperature = -100;
if(Temperature > 1000) Temperature = 1000;
// 模式切换
static uint8_t k2_last = 1;
if(k2_last && !KEY2_DOWN()) {
Mode ^= 1;
OLED_ClearLine(1, 7);
}
k2_last = KEY2_DOWN();
// 速度设置
if(Mode == 0) {
Speed = (int8_t)(Temperature / 10);
} else {
static uint8_t k1_last = 1;
if(k1_last && !KEY1_DOWN()) {
Speed = (Speed + 10) % 100;
OLED_ClearLine(2, 7);
}
k1_last = KEY1_DOWN();
}
// OLED刷新
static uint32_t last_refresh = 0;
if(Delay_Time() - last_refresh >= 200) {
last_refresh = Delay_Time();
// 更新模式显示
OLED_ShowChar(1, 7, Mode ? 'M' : 'A');
// 更新速度显示
static int8_t last_speed = -1;
if(last_speed != Speed) {
last_speed = Speed;
OLED_ShowSignedNum(2, 7, Speed, 3);
}
// 更新温度显示
static int16_t last_temp = -1000;
if(last_temp != Temperature) {
last_temp = Temperature;
int8_t temp_int = Temperature / 10;
uint8_t is_negative = 0;
if(temp_int < 0) {
is_negative = 1;
temp_int = -temp_int;
}
uint8_t temp_frac = Temperature % 10;
if(temp_frac < 0) temp_frac = -temp_frac;
OLED_ShowChar(3, 7, is_negative ? '-' : ' ');
OLED_ShowNum(3, 8, temp_int, 2);
OLED_ShowChar(3, 10, '.');
OLED_ShowNum(3, 11, temp_frac, 1);
}
// 更新ADC值显示
static uint16_t last_adc = 0;
if(last_adc != adc_avg) {
last_adc = adc_avg;
OLED_ShowNum(4, 6, adc_avg, 4);
}
}
Delay_ms(5);
}
}
```
### 构建和调试步骤
1. **清理工程**:
- Project → Clean Target
- 删除所有中间文件(Objects和Listings文件夹)
2. **重新构建**:
- Project → Rebuild all target files
3. **调试配置**:
- Options for Target → Debug
- 选择正确的调试器(如ST-Link Debugger)
- 设置正确的Flash下载算法
4. **常见错误处理**:
```plaintext
Error: L6218E: Undefined symbol SystemInit
```
- 解决方案:添加`system_stm32f10x.c`到工程
```plaintext
Warning: L6310W: Unable to find ARM libraries
```
- 解决方案:Options for Target → Target → ARM Compiler选择正确版本
### 最终验证
成功构建后,输出应类似:
```plaintext
Build target 'Target 1'
compiling main.c...
compiling AD.c...
compiling OLED.c...
compiling Delay.c...
compiling Key.c...
linking...
Program Size: Code=12345 RO-data=2345 RW-data=345 ZI-data=4567
".\Objects\Project.axf" - 0 Error(s), 0 Warning(s).
```
阅读全文
相关推荐

















