本帖最后由 jinglixixi 于 2023-10-26 22:42 编辑
CW32L031开发板内置了多个ADC模数转换通道,且内置了温度传感器,利用它与LCD5110显示屏相配合可完成片内温度的检测与显示功能,其效果如下图所示。
片内温度检测与显示
在ADC参考电压为1.5V时,其读取片内温度传感器的函数为: void ADC_GetTsVref1V5(float *fAdcTsDegree)
{
uint16_t u16AdcResult;
uint8_t temp1;
uint16_t temp2;
temp1 = *((uint8_t*) (ADDR_T0));
temp2 = *((uint16_t*) (ADDR_TRIM_1P5));
u16AdcResult = ADC_GetConversionValue();
*fAdcTsDegree = temp1 * 0.5f + COEFF_TS * 1.5f * (u16AdcResult - temp2);
}
在单次转换模式下,其采样与显示主程序为: int main(void)
{
ADC_InitTypeDef ADC_InitStructure = {0};
ADC_WdtTypeDef ADC_WdtStructure = {0};
ADC_SingleChTypeDef ADC_SingleChStructure = {0};
RCC_HSI_Enable(RCC_HSIOSC_DIV6);
ADC_PortInit();
GTIM_Init();
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_VrefSel = ADC_Vref_BGR1p5;
ADC_WdtInit(&ADC_WdtStructure);
ADC_SingleChStructure.ADC_DiscardEn = ADC_DiscardNull;
ADC_SingleChStructure.ADC_Chmux = ADC_TsInput;
ADC_SingleChStructure.ADC_InitStruct = ADC_InitStructure;
ADC_SingleChStructure.ADC_WdtStruct = ADC_WdtStructure;
ADC_SingleChOneModeCfg(&ADC_SingleChStructure);
ADC_ITConfig(ADC_IT_EOC, ENABLE);
ADC_EnableIrq(ADC_INT_PRIORITY);
ADC_ClearITPendingAll();
ADC_Enable();
ADC_ExtTrigCfg(ADC_TRIG_GTIM1, ENABLE);
GTIM_Cmd(CW_GTIM1, ENABLE);
LCD5510_CONFIG();
LED_SetHigh();
CS_SetLow();
LCD5510_Init();
LCD_prints(0,0,"CW32L031");
LCD_printc(0,1,'T');
LCD_printc(1,1,'=');
LCD_printc(8,1,'C');
while (1)
{
while (!(gFlagIrq & ADC_ISR_EOC_Msk));
gFlagIrq = 0u;
valueAdc = ADC_GetConversionValue();
LCD_printc(2,1,valueAdc/1000+'0');
LCD_printc(3,1,valueAdc%1000/100+'0');
LCD_printc(4,1,'.');
LCD_printc(5,1,valueAdc%100/10+'0');
LCD_printc(6,1,valueAdc%10+'0');
ADC_GetTsVref1V5(&fTsDegree);
}
}
经程序的编译与下载,则可得到上图所示的检测效果。
|