在AT32F407的A/D转换器中配置了内部的温度检测通道,利用它与OLED屏相配合,可以轻松地实现一个片内温度检测器,其显示效果如图所示。 片内温度检测器 实现该显示功能的主程序为: int main(void)
{
int num;
RCC_Configuration();
Delay_init();
DMA_Reset(DMA1_Channel1);
DMA_DefaultInitParaConfig(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue;
DMA_InitStructure.DMA_Direction = DMA_DIR_PERIPHERALSRC;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE;
DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_DISABLE;
DMA_InitStructure.DMA_PeripheralDataWidth = DMA_PERIPHERALDATAWIDTH_HALFWORD;
DMA_InitStructure.DMA_MemoryDataWidth = DMA_MEMORYDATAWIDTH_HALFWORD;
DMA_InitStructure.DMA_Mode = DMA_MODE_CIRCULAR;
DMA_InitStructure.DMA_Priority = DMA_PRIORITY_HIGH;
DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_ChannelEnable(DMA1_Channel1, ENABLE);
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanMode = DISABLE;
ADC_InitStructure.ADC_ContinuousMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrig = ADC_ExternalTrig_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NumOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_TempSensor, 1, ADC_SampleTime_239_5);
ADC_DMACtrl(ADC1, ENABLE);
ADC_TempSensorVrefintCtrl(ENABLE);
ADC_Ctrl(ADC1, ENABLE);
ADC_RstCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCtrl(ADC1, ENABLE);
AT32_OLED_Init();
OLED_Init();
OLED_Clear();
OLED_ShowString(0,0,"AT-START-F407",16);
OLED_ShowString(0,2,"OLED & ADC ",16);
Delay_ms(1000u);
OLED_Clear();
OLED_ShowString(0,0,"AT-START-F407",16);
OLED_ShowString(0,2,"Temp: deg C",16);
while (1)
{
num=(ADC_TEMP_BASE-(double)ADCConvertedValue*ADC_VREF/4096)/ADC_TEMP_SLOPE+25;
OLED_ShowNum(40,2,num,3,16);
Delay_sec(1);
}
}
|