在ADC实验中,结合热敏电阻,分别通过触摸芯片表面和热敏电阻,引起A/D值变化,显示芯片内部温度和当前温度。
#define GLOBLE_VAR
#include "includes.h"
int main(void)
{
uint16_t num_AD1;
uint16_t num_AD2;
uint16_t num_AD3;
uint32_t mMainLoopCount;
//关总中断
DISABLE_INTERRUPTS;
mMainLoopCount=0;
adc_init(ADC_CHANNEL_1,AD_DIFF);
adc_init(ADC_CHANNEL_15,AD_DIFF);
adc_init(ADC_CHANNEL_TEMPSENSOR,AD_SINGLE);
ENABLE_INTERRUPTS;
printf("GZHU 3210100165 MYJ\n");
for(;;)
{
mMainLoopCount++;
if (mMainLoopCount<=30000000) continue;
mMainLoopCount=0;
num_AD1 = adc_ave(ADC_CHANNEL_1,8);
num_AD2 = adc_ave(ADC_CHANNEL_15,8);
num_AD3 = adc_ave(ADC_CHANNEL_TEMPSENSOR,8);
printf("通道1(GEC47、46)的A/D值: %d\r\n",num_AD1);
printf("通道1(GEC47、46)的温度值: %f\r\n",Regression_Ext_Temp(num_AD1));
printf("通道15(GEC12、11)的A/D值:%d\r\n",num_AD2);
printf("通道15(GEC12、11)的温度值:%f\r\n",Regression_Ext_Temp(num_AD2));
printf("内部温度传感器的A/D值:%d\r\n",num_AD3);
printf("内部温度传感器的温度值:%f\r\n\n",Regression_MCU_Temp(num_AD3));
}
}
void Delay_ms(uint16_t u16ms)
{
uint32_t u32ctr;
for(u32ctr = 0; u32ctr < 8000*u16ms; u32ctr++)
{
__ASM("NOP");
}
}
float Regression_Ext_Temp(uint16_t tmpAD)
{
float Vtemp,Rtemp,temp;
if(tmpAD<=72)
{
return -274;
}
Vtemp = (tmpAD*3300.0)/4096;
Rtemp = Vtemp/(3300.0 - Vtemp)*10000.0;
temp = (1/(log(Rtemp/10000.0)/3950.0 + (1/(273.15 + 25)))) - 273.15 + 0.5;
return temp;
}
float Regression_MCU_Temp(uint16_t mcu_temp_AD)
{
float mcu_temp_result;
mcu_temp_result=(float)(55+(100*((float)(mcu_temp_AD) - AD_CAL1))/(AD_CAL2 - AD_CAL1));
return mcu_temp_result;
}
初始状态
使热敏电阻升温
用手触摸芯片表面使 mcu 升温
![](https://img-blog.csdnimg.cn/direct/a80f1a4e10394e4eb2a3583a83a2b78c.png)