/**************** (C) COPYRIGHT 2023 山东云唐智能科技有限公司 ******************* * 文 件 名: * 创 建 者: Kaiser * 描 述 : * 最后修改: *********************************** 修订记录 ************************************ * 版 本: * 修订人: ********************************************************************************/ /******************************** 功能说明 ************************************* * *******************************************************************************/ #include "stm32f10x.h" #include "BSP.H" /******************************** 功能说明 ************************************* * 系统所有异常配置上电优先集中处理 *******************************************************************************/ void BIOS_NVIC_Init(void) { NVIC_SetPriorityGrouping(7); // 本系统设置为禁止中断抢占,即没有中断嵌套 见下图 /* 表7.4 抢占优先级和子优先级的表达,位数与分组位置的关系 分组位置 表达抢占优先级的位段 表达子优先级的位段 0 [7:1] [0:0] 1 [7:2] [1:0] 2 [7:3] [2:0] 3 [7:4] [3:0] 4 [7:5] [4:0] 5 [7:6] [5:0] 6 [7:7] [6:0] 7 无 [7:0](所有位) */ // __set_CONTROL( 0x03u ); // 切换到PSP, 并转入非特权模式 } // 初始化 ADC1 void ADC1_Init() { // 使能 ADC1 时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); // 初始化 GPIO 设置(可根据实际连接调整) // ... // 配置 ADC 参数 ADC_InitTypeDef ADC_InitStruct; ADC_StructInit(&ADC_InitStruct); ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStruct.ADC_ContinuousConvMode = DISABLE; ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_Init(ADC1, &ADC_InitStruct); // 配置 ADC 通道 16 用于测量内部温度传感器 ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_55Cycles5); // 使能内部温度传感器 ADC_TempSensorVrefintCmd(ENABLE); // 使能 ADC1 ADC_Cmd(ADC1, ENABLE); // 校准 ADC1 ADC_ResetCalibration(ADC1); while (ADC_GetResetCalibrationStatus(ADC1)); ADC_StartCalibration(ADC1); while (ADC_GetCalibrationStatus(ADC1)); } // 读取内部温度传感器的值 uint16_t Read_Internal_Temperature() { // 启动 ADC1 转换 ADC_SoftwareStartConvCmd(ADC1, ENABLE); // 等待转换完成 while (!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)); // 返回 ADC1 转换结果 return ADC_GetConversionValue(ADC1); } void GPIO_InPutset(void) { //ADC1_Init(); GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Init(GPIOA, &GPIO_InitStructure); } uint8_t InstrumentTypeRead(void) { return ((GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) | GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13) << 1) | (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14) << 2) | (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15) << 3) ); } bool SafeCheck(void) { return GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8); } /******** (C) COPYRIGHT 2023 山东云唐智能科技有限公司 **** End Of File ********/