(void *)1,(void *)0 ,(void *)-1什么意思 [复制链接] http://bbs.chinaunix.net/thread-1944990-1-1.html

本文探讨了在编程中使用0和-1作为数值的普遍性和优点,特别是它们在不同CPU架构上的通用性及对代码移植性的提升。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  发表于 2009-12-15 17:01:12  | 只看该作者
一般0和-1用的比较多。对于代码的可以移植性比较好。

比如void* -1 这样得到的就是一个全ff,对于16位,32位,64位的cpu,全都适用。


发表于 2009-12-15 17:01:12 |只看该作者一般0和-1用的比较多。对于代码的可以移植性比较好。比如void* -1 这样得到的就是一个全ff,对于16位,32位,64位的cpu,全都适用。

/* * 立创开发板软硬件资料与相关扩展板软硬件资料官网全部开源 * 开发板官网:www.lckfb.com * 文档网站:wiki.lckfb.com * 技术支持常驻论坛,任何技术问题欢迎随时交流学习 * 嘉立创社区问答:https://www.jlc-bbs.com/lckfb * 关注bilibili账号:【立创开发板】,掌握我们的最新动态! * 不靠卖板赚钱,以培养中国工程师为己任 */ #include "bsp_encoder.h" #include "bsp_tb6612.h" #include "board.h" #include "PID.h" #include <ti/driverlib/driverlib.h> // 添加DriverLib头文件 // 声明外部函数(根据您的项目结构调整) #if defined(MPU6050) void Read_Quad(void); // 添加函数声明 #endif uint32_t gpio_interrup1, gpio_interrup2; int Get_Encoder_countA, Get_Encoder_countB; /******************************************************* 函数功能:外部中断模拟编码器信号 入口函数:无 返回 值:无 ***********************************************************/ void encoder_Init(void) { NVIC_ClearPendingIRQ(GPIOB_INT_IRQn); NVIC_EnableIRQ(GPIOB_INT_IRQn); } static void handle_encoder1(void); static void handle_encoder2(void); // 修复1:移除宏定义末尾的分号 #if defined(MPU6050) #define GPIO_MPU6050_INT_IIDX // 正确格式 #endif void GROUP1_IRQHandler(void) { // 获取所有编码器引脚的中断状态 uint32_t gpio_status = DL_GPIO_getEnabledInterruptStatus( ENCODER_PORT, ENCODER_E1A_PIN | ENCODER_E1B_PIN | ENCODER_E2A_PIN | ENCODER_E2B_PIN ); // 处理编码器1中断 if (gpio_status & (ENCODER_E1A_PIN | ENCODER_E1B_PIN)) { handle_encoder1(); DL_GPIO_clearInterruptStatus(ENCODER_PORT, ENCODER_E1A_PIN | ENCODER_E1B_PIN); } // 处理编码器2中断 if (gpio_status & (ENCODER_E2A_PIN | ENCODER_E2B_PIN)) { handle_encoder2(); DL_GPIO_clearInterruptStatus(ENCODER_PORT, ENCODER_E2A_PIN | ENCODER_E2B_PIN); } // 处理MPU6050中断 - 修复2:使用正确的条件编译 #if defined(GPIO_MPU6050_INT_IIDX) && defined(MPU6050) if (DL_Interrupt_getPendingGroup(DL_INTERRUPT_GROUP_1) == GPIO_MPU6050_INT_IIDX) { Read_Quad(); // 确保此函数已声明 } #endif } // 编码器1处理函数 static void handle_encoder1(void) { uint32_t gpio_interrup = DL_GPIO_getEnabledInterruptStatus( ENCODER_PORT, ENCODER_E1A_PIN | ENCODER_E1B_PIN ); // encoderB (原始逻辑) if ((gpio_interrup & ENCODER_E1A_PIN) == ENCODER_E1A_PIN) { if (!DL_GPIO_readPins(ENCODER_PORT, ENCODER_E1B_PIN)) { Get_Encoder_countB--; } else { Get_Encoder_countB++; } } else if ((gpio_interrup & ENCODER_E1B_PIN) == ENCODER_E1B_PIN) { if (!DL_GPIO_readPins(ENCODER_PORT, ENCODER_E1A_PIN)) { Get_Encoder_countB++; } else { Get_Encoder_countB--; } } } // 编码器2处理函数 static void handle_encoder2(void) { uint32_t gpio_interrup = DL_GPIO_getEnabledInterruptStatus( ENCODER_PORT, ENCODER_E2A_PIN | ENCODER_E2B_PIN ); // encoderA (原始逻辑) if ((gpio_interrup & ENCODER_E2A_PIN) == ENCODER_E2A_PIN) { if (!DL_GPIO_readPins(ENCODER_PORT, ENCODER_E2B_PIN)) { Get_Encoder_countA--; } else { Get_Encoder_countA++; } } else if ((gpio_interrup & ENCODER_E2B_PIN) == ENCODER_E2B_PIN) { if (!DL_GPIO_readPins(ENCODER_PORT, ENCODER_E2A_PIN)) { Get_Encoder_countA++; } else { Get_Encoder_countA--; } } } [0]**** Clean-only build of configuration Debug for project 111111111 **** [1]"C:\\ti\\ccs2020\\ccs\\utils\\bin\\gmake" -k -j 16 clean -O [2]**** Build of configuration Debug for project 111111111 **** [3]"C:\\ti\\ccs2020\\ccs\\utils\\bin\\gmake" -k -j 16 all -O [4]Building file: "../empty.syscfg" [5]Invoking: SysConfig [6]"C:/ti/ccs2020/ccs/utils/sysconfig_1.24.0/sysconfig_cli.bat" --script "C:/Users/Administrator/workspace_ccstheia/111111111/empty.syscfg" -o "." -s "C:/ti/mspm0_sdk_2_05_01_00/.metadata/product.json" --compiler ticlang [7]Running script... [8]Validating... [9]info: PWM_0(/ti/driverlib/PWM): Peripheral does not retain register contents in STOP or STANDBY modes. User should take care to save and restore register configuration in application. See Retention Configuration section for more details. [10]info: TIMER_1(/ti/driverlib/TIMER): Peripheral does not retain register contents in STOP or STANDBY modes. User should take care to save and restore register configuration in application. See Retention Configuration section for more details. [11]Generating Code (empty.syscfg)... [12]Writing C:\Users\Administrator\workspace_ccstheia\111111111\Debug\device_linker.cmd... [13]Writing C:\Users\Administrator\workspace_ccstheia\111111111\Debug\device.opt... [14]Writing C:\Users\Administrator\workspace_ccstheia\111111111\Debug\device.cmd.genlibs... [15]Writing C:\Users\Administrator\workspace_ccstheia\111111111\Debug\ti_msp_dl_config.c... [16]Writing C:\Users\Administrator\workspace_ccstheia\111111111\Debug\ti_msp_dl_config.h... [17]Writing C:\Users\Administrator\workspace_ccstheia\111111111\Debug\Event.dot... [18]Finished building: "../empty.syscfg" [19]Building file: "C:/ti/mspm0_sdk_2_05_01_00/source/ti/devices/msp/m0p/startup_system_files/ticlang/startup_mspm0g350x_ticlang.c" [20]Invoking: Arm Compiler [21]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"startup_mspm0g350x_ticlang.d_raw" -MT"startup_mspm0g350x_ticlang.o" @"./device.opt" -o"startup_mspm0g350x_ticlang.o" "C:/ti/mspm0_sdk_2_05_01_00/source/ti/devices/msp/m0p/startup_system_files/ticlang/startup_mspm0g350x_ticlang.c" [22]Finished building: "C:/ti/mspm0_sdk_2_05_01_00/source/ti/devices/msp/m0p/startup_system_files/ticlang/startup_mspm0g350x_ticlang.c" [23]Building file: "../empty.c" [24]Invoking: Arm Compiler [25]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"empty.d_raw" -MT"empty.o" @"./device.opt" -o"empty.o" "../empty.c" [26]Finished building: "../empty.c" [27]Building file: "ti_msp_dl_config.c" [28]Invoking: Arm Compiler [29]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"ti_msp_dl_config.d_raw" -MT"ti_msp_dl_config.o" @"./device.opt" -o"ti_msp_dl_config.o" "ti_msp_dl_config.c" [30]Finished building: "ti_msp_dl_config.c" [31]Building file: "../BSP/MPU6050/inv_mpu.c" [32]Invoking: Arm Compiler [33]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/MPU6050/inv_mpu.d_raw" -MT"BSP/MPU6050/inv_mpu.o" @"./device.opt" -o"BSP/MPU6050/inv_mpu.o" "../BSP/MPU6050/inv_mpu.c" [34]Finished building: "../BSP/MPU6050/inv_mpu.c" [35]Building file: "../BSP/MPU6050/mspm0_i2c.c" [36]Invoking: Arm Compiler [37]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/MPU6050/mspm0_i2c.d_raw" -MT"BSP/MPU6050/mspm0_i2c.o" @"./device.opt" -o"BSP/MPU6050/mspm0_i2c.o" "../BSP/MPU6050/mspm0_i2c.c" [38]Finished building: "../BSP/MPU6050/mspm0_i2c.c" [39]Building file: "../BSP/MPU6050/mpu6050.c" [40]Invoking: Arm Compiler [41]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/MPU6050/mpu6050.d_raw" -MT"BSP/MPU6050/mpu6050.o" @"./device.opt" -o"BSP/MPU6050/mpu6050.o" "../BSP/MPU6050/mpu6050.c" [42]Finished building: "../BSP/MPU6050/mpu6050.c" [43]Building file: "../BSP/src/bsp_encoder.c" [44]Invoking: Arm Compiler [45]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/src/bsp_encoder.d_raw" -MT"BSP/src/bsp_encoder.o" @"./device.opt" -o"BSP/src/bsp_encoder.o" "../BSP/src/bsp_encoder.c" [46]Building file: "../BSP/MPU6050/inv_mpu_dmp_motion_driver.c" [47]Invoking: Arm Compiler [48]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/MPU6050/inv_mpu_dmp_motion_driver.d_raw" -MT"BSP/MPU6050/inv_mpu_dmp_motion_driver.o" @"./device.opt" -o"BSP/MPU6050/inv_mpu_dmp_motion_driver.o" "../BSP/MPU6050/inv_mpu_dmp_motion_driver.c" [49]../BSP/src/bsp_encoder.c:67:84: error: expected expression [50] 67 | if (DL_Interrupt_getPendingGroup(DL_INTERRUPT_GROUP_1) == GPIO_MPU6050_INT_IIDX) { [51] | ^ [52]1 error generated. [53]gmake: *** [BSP/src/subdir_rules.mk:11: BSP/src/bsp_encoder.o] Error 1 [54]Finished building: "../BSP/MPU6050/inv_mpu_dmp_motion_driver.c" [55]Building file: "../BSP/src/PID.c" [56]Invoking: Arm Compiler [57]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/src/PID.d_raw" -MT"BSP/src/PID.o" @"./device.opt" -o"BSP/src/PID.o" "../BSP/src/PID.c" [58]Finished building: "../BSP/src/PID.c" [59]Building file: "../BSP/OLED/oled_software_i2c.c" [60]Invoking: Arm Compiler [61]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/OLED/oled_software_i2c.d_raw" -MT"BSP/OLED/oled_software_i2c.o" @"./device.opt" -o"BSP/OLED/oled_software_i2c.o" "../BSP/OLED/oled_software_i2c.c" [62]Finished building: "../BSP/OLED/oled_software_i2c.c" [63]Building file: "../BSP/src/XUNJI.c" [64]Invoking: Arm Compiler [65]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/src/XUNJI.d_raw" -MT"BSP/src/XUNJI.o" @"./device.opt" -o"BSP/src/XUNJI.o" "../BSP/src/XUNJI.c" [66]Finished building: "../BSP/src/XUNJI.c" [67]Building file: "../BSP/src/bsp_tb6612.c" [68]Invoking: Arm Compiler [69]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/src/bsp_tb6612.d_raw" -MT"BSP/src/bsp_tb6612.o" @"./device.opt" -o"BSP/src/bsp_tb6612.o" "../BSP/src/bsp_tb6612.c" [70]Finished building: "../BSP/src/bsp_tb6612.c" [71]Building file: "../BSP/src/timer.c" [72]Invoking: Arm Compiler [73]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/src/timer.d_raw" -MT"BSP/src/timer.o" @"./device.opt" -o"BSP/src/timer.o" "../BSP/src/timer.c" [74]Finished building: "../BSP/src/timer.c" [75]Building file: "../Board/board.c" [76]Invoking: Arm Compiler [77]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"Board/board.d_raw" -MT"Board/board.o" @"./device.opt" -o"Board/board.o" "../Board/board.c" [78]Finished building: "../Board/board.c" [79]Building file: "../MSPM0/interrupt.c" [80]Invoking: Arm Compiler [81]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"MSPM0/interrupt.d_raw" -MT"MSPM0/interrupt.o" @"./device.opt" -o"MSPM0/interrupt.o" "../MSPM0/interrupt.c" [82]Finished building: "../MSPM0/interrupt.c" [83]Building file: "../MSPM0/clock.c" [84]Invoking: Arm Compiler [85]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"MSPM0/clock.d_raw" -MT"MSPM0/clock.o" @"./device.opt" -o"MSPM0/clock.o" "../MSPM0/clock.c" [86]Finished building: "../MSPM0/clock.c" [87]gmake: Target 'all' not remade because of errors. [88]**** Build Finished ****
最新发布
08-01
/********************************************************************************************** Copyright 2008 - 2019 深圳市信盈达电子有限公司. All rights reserved. 描述 : 作者 : 何文宾 版本 : V1.0 修改 : 完成日期: 2019年2月17日 信盈达官网:http://www.edu118.com/ 信盈达网校:http://www.edu118.cn/ 信盈达技术论坛:http://bbs.edu118.com/ Notice :本程序只供学习使用,未经作者许可,不得用于其它任何用途。版权所有,盗版必究 ***********************************************************************************************/ /********************************************************************************************** * INCLUDES */ #include "oled.h" #include "systick.h" #include "font.h" #include "rtc.h" /********************************************************************************************** * CONSTANTS */ /********************************************************************************************** * TYPEDEFS */ /********************************************************************************************** * LOCAL VARIABLES */ /********************************************************************************************** * LOCAL FUNCTIONS DECLARE */ /********************************************************************************************** * LOCAL FUNCTIONS */ /********************************************************************************************** * PUBLIC FUNCTIONS */ /******************************************************************* * 函数名: OLED_Init() * 功能描述 : 初始化oled * 作者: 何文宾 * 参数说明: 无 * 返回值说明: 无 * 修改记录: * 其他: *******************************************************************/ /** SCK----PB13 MOSI---PB15 CS-----PA15 DC-----PA11 RES----PA12 */ void OLED_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; SPI_InitTypeDef SPI_InitStruct; /***********************管脚定义********************************************/ if(SPI_MODE) { /*************************硬件SPI*********************************************/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);//使能A&&B时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//开启AFIO时钟 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);//SPI2时钟使能 /*CS-----PA15*/ //推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_CS_PIN; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(OLED_GPIO,&GPIO_InitStruct); /*DC-----PA11*/ //推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_DC_PIN; GPIO_Init(OLED_GPIO,&GPIO_InitStruct); /*RES-----PA12*/ //推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_RES_PIN; GPIO_Init(OLED_GPIO,&GPIO_InitStruct); OLED_RES_H; /*SCK----PB13*/ //复用推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_SCK_PIN; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(OLED_SPI_GPIO,&GPIO_InitStruct); /*MOSI---PB15*/ //复用推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_MOSI_PIN; GPIO_Init(OLED_SPI_GPIO,&GPIO_InitStruct); /*MISO---PB14*/ //浮空输入 GPIO_InitStruct.GPIO_Pin = OLED_MISO_PIN; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(OLED_SPI_GPIO,&GPIO_InitStruct); SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;//波特率 SPI_InitStruct.SPI_CPHA = SPI_CPHA_2Edge;//在时钟第二个电平发送数据 SPI_InitStruct.SPI_CPOL = SPI_CPOL_High;//时钟空闲状态为高电平 SPI_InitStruct.SPI_CRCPolynomial = DISABLE; SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;//8位数据帧 SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//双线双向模式 SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;//先发高位 SPI_InitStruct.SPI_Mode = SPI_Mode_Master;//主机模式 SPI_InitStruct.SPI_NSS = SPI_NSS_Soft;//软件从设备管理 SPI_Init(SPI2,&SPI_InitStruct); SPI_Cmd(SPI2,ENABLE); spi_read_write(0xff); } else { /*软件模拟SPI*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);//使能A&&B时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//开启AFIO时钟 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE); /*SCK----PB13*/ //推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_SCK_PIN; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(OLED_SPI_GPIO,&GPIO_InitStruct); /*MOSI---PB15*/ //推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_MOSI_PIN; GPIO_Init(OLED_SPI_GPIO,&GPIO_InitStruct); /*CS-----PA15*/ //推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_CS_PIN; GPIO_Init(OLED_GPIO,&GPIO_InitStruct); /*DC-----PA11*/ //推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_DC_PIN; GPIO_Init(OLED_GPIO,&GPIO_InitStruct); /*RES-----PA12*/ //推挽输出 50MHZ GPIO_InitStruct.GPIO_Pin = OLED_RES_PIN; GPIO_Init(OLED_GPIO,&GPIO_InitStruct); OLED_RES_H; } /***********************初始化时序********************************************/ delay_ms(200); Oled_Write_Cmd(0xAE); //关闭显示 Oled_Write_Cmd(0xD5); //设置时钟分频因子,震荡频率 Oled_Write_Cmd(80); //[3:0],分频因子;[7:4],震荡频率 Oled_Write_Cmd(0xA8); //设置驱动路数 Oled_Write_Cmd(0X3F); //默认0X3F(1/64) Oled_Write_Cmd(0xD3); //设置显示偏移 Oled_Write_Cmd(0X00); //默认为0 Oled_Write_Cmd(0x40); //设置显示开始行 [5:0],行数. Oled_Write_Cmd(0x8D); //电荷泵设置 Oled_Write_Cmd(0x14); //bit2,开启/关闭 Oled_Write_Cmd(0x20); //设置内存地址模式 Oled_Write_Cmd(0x02); //[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10; Oled_Write_Cmd(0xA1); //段重定义设置,bit0:0,0->0;1,0->127; Oled_Write_Cmd(0xC8); //设置COM扫描方向;bit3:0,普通模式;1,重定义模式 COM[N-1]->COM0;N:驱动路数 Oled_Write_Cmd(0xDA); //设置COM硬件引脚配置 Oled_Write_Cmd(0x12); //[5:4]配置 Oled_Write_Cmd(0x81); //对比度设置 Oled_Write_Cmd(0xEF); //1~255;默认0X7F (亮度设置,越大越亮) Oled_Write_Cmd(0xD9); //设置预充电周期 Oled_Write_Cmd(0xf1); //[3:0],PHASE 1;[7:4],PHASE 2; Oled_Write_Cmd(0xDB); //设置VCOMH 电压倍率 Oled_Write_Cmd(0x30); //[6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc; Oled_Write_Cmd(0xA4); //全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏) Oled_Write_Cmd(0xA6); //设置显示方式;bit0:1,反相显示;0,正常显示 Oled_Write_Cmd(0xAF); //开启显示 OLED_Clear(0,128,0,8,0x00); } /******************************************************************* * 函数名: spi_read_write() * 功能描述 : SPI读写数据 * 作者: 何文宾 * 参数说明: 待发送的数据 * 返回值说明: 读取的值 * 修改记录: * 其他: *******************************************************************/ //SPI读写数据 u8 spi_read_write(u8 dat) { if (SPI_MODE) { while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE)); //等待发送缓冲为空 SPI_I2S_SendData(SPI2,dat); while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE)); //等待接收缓冲不为空 return SPI_I2S_ReceiveData(SPI2); //返回收到的数据 } else { u8 i; OLED_CS_L; for(i=0;i<8;i++) { OLED_SCK_L; if((dat&0x80)) { OLED_MOSI_H; } else OLED_MOSI_L; OLED_SCK_H; dat<<=1; } OLED_CS_H; return dat; } } /******************************************************************* * 函数名: Oled_Write_Data() * 功能描述 : OLED写数据 * 作者: 何文宾 * 参数说明: 待发送的指令 * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void Oled_Write_Data(u8 dat) { OLED_DC_H; OLED_CS_L; spi_read_write(dat); OLED_CS_H; } /******************************************************************* * 函数名: Oled_Write_Cmd() * 功能描述 : OLED写指令 * 作者: 何文宾 * 参数说明: 待发送的指令 * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void Oled_Write_Cmd(u8 cmd) { OLED_DC_L; OLED_CS_L; spi_read_write(cmd); OLED_CS_H; } /******************************************************************* * 函数名: OLED_Setpos() * 功能描述 : OLED设置位置 * 作者: 何文宾 * 参数说明: 待发送的指令 * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_Setpos(u8 sx,u8 sy) { Oled_Write_Cmd(0xb0+sy); //哪一页 Oled_Write_Cmd(0x10+(sx>>4)); //高4位地址 Oled_Write_Cmd(0x00+(sx&0x0f));//低4位地址 } /******************************************************************* * 函数名: OLED_Clear() * 功能描述 : OLED设置位置 * 作者: 何文宾 * 参数说明: 待发送的指令 * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_Clear(u8 sx,u8 ex,u8 sy,u8 ey,u8 data) { u8 i,j; for(i=sy;i<ey;i++) //页 { Oled_Write_Cmd(0xb0+i); //哪一页 Oled_Write_Cmd(0x10+(sx>>4)); //高4位地址 Oled_Write_Cmd(0x00+(sx&0x0f));//低4位地址 for(j=0;j<(ex-sx);j++) //列 { Oled_Write_Data(data); } } } /******************************************************************* * 函数名: OLED_ShowChar() * 功能描述 : 显示字符 * 作者: 何文宾 * 参数说明: x:X坐标,y:Y坐标,p:显示的字符,size:字符大小 * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_ShowChar(u8 x,u8 y,u8 p,u8 size) { u8 i; u8 ex,ey; u8 res=p-' '; ex=x;ey=y; if(size==16) { OLED_Setpos(ex,ey); for(i=0;i<16;i++) { if(((i%8)==0)&&(i!=0)) { ex=x; ey+=1; OLED_Setpos(ex,ey); } Oled_Write_Data(char16X16[res][i]); } } else if(size==12) { OLED_Setpos(ex,ey); for(i=0;i<12;i++) { if(((i%6)==0)&&(i!=0)) { ex=x; ey+=1; OLED_Setpos(ex,ey); } Oled_Write_Data(char12X12[res][i]); } } else if(size==24) { OLED_Setpos(ex,ey); for(i=0;i<36;i++) { if(((i%12)==0)&&(i!=0)) { ex=x; ey+=1; OLED_Setpos(ex,ey); } Oled_Write_Data(char24X24[res][i]); } } } /******************************************************************* * 函数名: OLED_ShowString() * 功能描述 : 显示字符串 * 作者: 何文宾 * 参数说明: x:X坐标,y:Y坐标,p:显示的字符串,size:字符串大小 * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_ShowString(u8 x,u8 y,u8 *p,u8 size) { while(*p!='\0') { OLED_ShowChar(x,y,*p,size); p+=1; x+=(size/2); } } /******************************************************************* * 函数名: OLED_ShowNum() * 功能描述 : 显示数字 * 作者: 何文宾 * 参数说明: x:X坐标,y:Y坐标,num:显示的数字,size:数字大小,len:长度 * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_ShowNum(u8 x,u8 y,u32 num,u8 size) { u8 cnum,cnum2; u8 nn; u8 i; u8 length=0; nn=1; cnum=num; cnum2=num; if(num!=0) { while(num>0) { length+=1; num/=10; } } else { length=1; } while(length) { for(i=0;i<(length-1);i++) { nn=nn*10; } cnum=cnum/nn; OLED_ShowChar(x,y,cnum+48,size); x+=(size/2); cnum=cnum2%nn; nn=1; length--; } } /******************************************************************* * 函数名: OLED_ShowTime() * 功能描述 : 显示当前时间 * 作者: 何文宾 * 参数说明: x:X坐标,y:Y坐标,size:数字大小 * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_ShowTime(u8 x,u8 y,u8 size) { u8 sx=x; /*显示当前时间*/ RTC_Get_Time(); OLED_ShowNum(sx,y,my_time.hour,16); sx+=size; OLED_ShowChar(sx,y,':',16); sx+=(size/2); OLED_ShowNum(sx,y,my_time.min,16); sx+=size; OLED_ShowChar(sx,y,':',16); sx+=(size/2); OLED_ShowNum(sx,y,my_time.sec ,16); } /******************************************************************* * 函数名: OLED_Showpic() * 功能描述 : 显示图片 * 作者: 何文宾 * 参数说明: * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_Showpic(u8 sx,u8 sy,u8 ex,u8 ey,const unsigned char * p) { u8 i,j; for(j=0;j<(ey-sy);j++) { OLED_Setpos(sx,sy+j); for(i=0;i<(ex-sx);i++) { Oled_Write_Data(*p); p++; } } } /******************************************************************* * 函数名: OLED_Show_Font() * 功能描述 : 显示单个汉字 * 作者: 何文宾 * 参数说明: * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_Show_Font(u8 x,u8 y,u8 size,u8 num) { u8 i; u8 temp; u8 ssize; u8 x0=x; u8 *zk; ssize=size*(size/8+(size%8?1:0)); //计算不同字体大小所占用的字节数 switch(size) { case 12: zk=(u8*)F12X12[num]; //得到汉字编号对应的点阵库 for(i=0;i<ssize;i++) { if(i==size) { x=x0; y++; } temp=zk[i]; //得到点阵数据 OLED_Setpos(x,y); Oled_Write_Data(temp); x++; } break; case 16: zk=(u8*)F16X16[num]; //得到汉字编号对应的点阵库 for(i=0;i<ssize;i++) { if(i==size) { x=x0; y++; } temp=zk[i]; //得到点阵数据 OLED_Setpos(x,y); Oled_Write_Data(temp); x++; } break; case 24: zk=(u8*)F24X24[num]; //得到汉字编号对应的点阵库 for(i=0;i<ssize;i++) { if(i==size) { x=x0; y++; } temp=zk[i]; //得到点阵数据 OLED_Setpos(x,y); Oled_Write_Data(temp); x++; } break; default:break; } } /******************************************************************* * 函数名: OLED_Show_Font() * 功能描述 : 显示多个汉字 * 作者: 何文宾 * 参数说明: * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_ShowMultiple_Font(u8 x,u8 y,u8 size,u8 *p) { while(*p!=0) { OLED_Show_Font(x,y,size,*p); p++; x+=size; } } /******************************************************************* * 函数名: OLED_Show_gezi() * 功能描述 : 显示下划线 * 作者: 何文宾 * 参数说明: mode:1 密码格子 0:时间格子 * 返回值说明: * 修改记录: * 其他: *******************************************************************/ void OLED_Show_gezi(u8 sx,u8 sy,u8 ex,u8 ey) { u8 i; for(i=0;i<6;i++) { OLED_Showpic(sx,sy,ex,ey,&gezi[0]); sx+=15; ex+=15; } } void show_voice(u8 sx,u8 sy,u8 vol) { u8 i=0; u8 x=sx; OLED_Clear(sx,sx+80,sy,sy+1,0x00); for(i=0;i<vol;i++) { OLED_Showpic(x,sy,x+8,sy+1,&voice[i][0]); x+=10; } } /*********************************************************************************************** ***********************************************************************************************/ 我想在此基础上添加切换屏幕的功能,并且屏幕显示请输入密码
06-08
/* * 立创开发板软硬件资料与相关扩展板软硬件资料官网全部开源 * 开发板官网:www.lckfb.com * 文档网站:wiki.lckfb.com * 技术支持常驻论坛,任何技术问题欢迎随时交流学习 * 嘉立创社区问答:https://www.jlc-bbs.com/lckfb * 关注bilibili账号:【立创开发板】,掌握我们的最新动态! * 不靠卖板赚钱,以培养中国工程师为己任 */ #include "bsp_encoder.h" #include "bsp_tb6612.h" #include "board.h" #include "PID.h" #include <ti/driverlib/driverlib.h> // 添加DriverLib头文件 uint32_t gpio_interrup1,gpio_interrup2; int Get_Encoder_countA,Get_Encoder_countB; /******************************************************* 函数功能:外部中断模拟编码器信号 入口函数:无 返回 值:无 ***********************************************************/ void encoder_Init(void) { NVIC_ClearPendingIRQ(GPIOB_INT_IRQn); NVIC_EnableIRQ(GPIOB_INT_IRQn); } static void handle_encoder1(void); static void handle_encoder2(void); #define GPIO_MPU6050_INT_IIDX; /*void GROUP1_IRQHandler(void) { switch (DL_Interrupt_getPendingGroup(DL_INTERRUPT_GROUP_1)) { #if defined GPIO_MPU6050_INT_IIDX case GPIO_MPU6050_INT_IIDX: Read_Quad(); break; #endif } //获取中断信号 gpio_interrup1 = DL_GPIO_getEnabledInterruptStatus(ENCODER_PORT,ENCODER_E1A_PIN|ENCODER_E1B_PIN); gpio_interrup2 = DL_GPIO_getEnabledInterruptStatus(ENCODER_PORT,ENCODER_E2A_PIN|ENCODER_E2B_PIN); //encoderB if((gpio_interrup1 & ENCODER_E1A_PIN)==ENCODER_E1A_PIN) { if(!DL_GPIO_readPins(ENCODER_PORT,ENCODER_E1B_PIN)) { Get_Encoder_countB--; } else { Get_Encoder_countB++; } } else if((gpio_interrup1 & ENCODER_E1B_PIN)==ENCODER_E1B_PIN) { if(!DL_GPIO_readPins(ENCODER_PORT,ENCODER_E1A_PIN)) { Get_Encoder_countB++; } else { Get_Encoder_countB--; } } //encoderA if((gpio_interrup2 & ENCODER_E2A_PIN)==ENCODER_E2A_PIN) { if(!DL_GPIO_readPins(ENCODER_PORT,ENCODER_E2B_PIN)) { Get_Encoder_countA--; } else { Get_Encoder_countA++; } } else if((gpio_interrup2 & ENCODER_E2B_PIN)==ENCODER_E2B_PIN) { if(!DL_GPIO_readPins(ENCODER_PORT,ENCODER_E2A_PIN)) { Get_Encoder_countA++; } else { Get_Encoder_countA--; } } DL_GPIO_clearInterruptStatus(ENCODER_PORT,ENCODER_E1A_PIN|ENCODER_E1B_PIN); DL_GPIO_clearInterruptStatus(ENCODER_PORT,ENCODER_E2A_PIN|ENCODER_E2B_PIN); }*/ void GROUP1_IRQHandler(void) { // 获取所有编码器引脚的中断状态(需传入引脚掩码参数) uint32_t gpio_status = DL_GPIO_getEnabledInterruptStatus( ENCODER_PORT, ENCODER_E1A_PIN | ENCODER_E1B_PIN | ENCODER_E2A_PIN | ENCODER_E2B_PIN ); // 处理编码器1中断 if (gpio_status & (ENCODER_E1A_PIN | ENCODER_E1B_PIN)) { handle_encoder1(); DL_GPIO_clearInterruptStatus(ENCODER_PORT, ENCODER_E1A_PIN | ENCODER_E1B_PIN); } // 处理编码器2中断 if (gpio_status & (ENCODER_E2A_PIN | ENCODER_E2B_PIN)) { handle_encoder2(); DL_GPIO_clearInterruptStatus(ENCODER_PORT, ENCODER_E2A_PIN | ENCODER_E2B_PIN); } // 处理MPU6050中断(根据原始代码) #if defined GPIO_MPU6050_INT_IIDX if (DL_Interrupt_getPendingGroup(DL_INTERRUPT_GROUP_1) == GPIO_MPU6050_INT_IIDX) { Read_Quad(); } #endif } // 编码器1处理函数 static void handle_encoder1(void) { // 获取编码器1引脚的中断状态(需传入引脚掩码参数) uint32_t gpio_interrup = DL_GPIO_getEnabledInterruptStatus( ENCODER_PORT, ENCODER_E1A_PIN | ENCODER_E1B_PIN ); // encoderB (原始逻辑) if ((gpio_interrup & ENCODER_E1A_PIN) == ENCODER_E1A_PIN) { if (!DL_GPIO_readPins(ENCODER_PORT, ENCODER_E1B_PIN)) { Get_Encoder_countB--; } else { Get_Encoder_countB++; } } else if ((gpio_interrup & ENCODER_E1B_PIN) == ENCODER_E1B_PIN) { if (!DL_GPIO_readPins(ENCODER_PORT, ENCODER_E1A_PIN)) { Get_Encoder_countB++; } else { Get_Encoder_countB--; } } } // 编码器2处理函数 static void handle_encoder2(void) { // 获取编码器2引脚的中断状态(需传入引脚掩码参数) uint32_t gpio_interrup = DL_GPIO_getEnabledInterruptStatus( ENCODER_PORT, ENCODER_E2A_PIN | ENCODER_E2B_PIN ); // encoderA (原始逻辑) if ((gpio_interrup & ENCODER_E2A_PIN) == ENCODER_E2A_PIN) { if (!DL_GPIO_readPins(ENCODER_PORT, ENCODER_E2B_PIN)) { Get_Encoder_countA--; } else { Get_Encoder_countA++; } } else if ((gpio_interrup & ENCODER_E2B_PIN) == ENCODER_E2B_PIN) { if (!DL_GPIO_readPins(ENCODER_PORT, ENCODER_E2A_PIN)) { Get_Encoder_countA++; } else { Get_Encoder_countA--; } } } [0]**** Build of configuration Debug for project 111111111 **** [1]"C:\\ti\\ccs2020\\ccs\\utils\\bin\\gmake" -k -j 16 all -O [2]Building file: "../BSP/src/bsp_encoder.c" [3]Invoking: Arm Compiler [4]"C:/ti/ccs2020/ccs/tools/compiler/ti-cgt-armllvm_4.0.3.LTS/bin/tiarmclang.exe" -c @"device.opt" -march=thumbv6m -mcpu=cortex-m0plus -mfloat-abi=soft -mlittle-endian -mthumb -O0 -I"C:/Users/Administrator/workspace_ccstheia/111111111" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Board" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/MPU6050" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/OLED" -I"C:/Users/Administrator/workspace_ccstheia/111111111/MSPM0" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP" -I"C:/Users/Administrator/workspace_ccstheia/111111111/BSP/inc" -I"C:/Users/Administrator/workspace_ccstheia/111111111/Debug" -I"C:/ti/mspm0_sdk_2_05_01_00/source/third_party/CMSIS/Core/Include" -I"C:/ti/mspm0_sdk_2_05_01_00/source" -DMOTION_DRIVER_TARGET_MSPM0 -DMPU6050 -D__MSPM0G3507__ -gdwarf-3 -MMD -MP -MF"BSP/src/bsp_encoder.d_raw" -MT"BSP/src/bsp_encoder.o" @"./device.opt" -o"BSP/src/bsp_encoder.o" "../BSP/src/bsp_encoder.c" [5]../BSP/src/bsp_encoder.c:35:30: warning: ISO C99 requires whitespace after the macro name [-Wc99-extensions] [6] 35 | #define GPIO_MPU6050_INT_IIDX; [7] | ^ [8]../BSP/src/bsp_encoder.c:138:63: error: expected expression [9] 138 | if (DL_Interrupt_getPendingGroup(DL_INTERRUPT_GROUP_1) == GPIO_MPU6050_INT_IIDX) { [10] | ^ [11]../BSP/src/bsp_encoder.c:35:30: note: expanded from macro 'GPIO_MPU6050_INT_IIDX' [12]../BSP/src/bsp_encoder.c:139:9: warning: call to undeclared function 'Read_Quad'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] [13] 139 | Read_Quad(); [14] | ^ [15]2 warnings and 1 error generated. [16]gmake: *** [BSP/src/subdir_rules.mk:11: BSP/src/bsp_encoder.o] Error 1 [17]gmake: Target 'all' not remade because of errors. [18]**** Build Finished ****
08-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值