麻烦高手帮忙指正一下,片内温度传感器的使用上哪个环节出了问题,谢谢啦!
附上程序:
#include "C8051F410.h"
#define uchar unsigned char
#define uint unsigned int
#define Vref 1.5
void Port_IO_Init() //开交叉开关。
{
XBR1 = 0x40;
}
void ADC_Init() //ADC0使能,选内部温度传感器,预追踪,写“1”进AD0BUSY启动转换,累加4次。
{
ADC0MX = 0x18;
ADC0CF = 0xFA;
ADC0CN = 0xC0;
ADC0TK = 0xF9;
}
void Voltage_Reference_Init()//VDD作为参考电压,输出电压1.5V,温度传感器使能。
{
REF0CN = 0x0C;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Port_IO_Init();
ADC_Init();
Voltage_Reference_Init();
}
void main()
{
uint temp;
float Temperature;
PCA0MD &= ~0x40;
Init_Device();
while(1)
{
ADC0CN|=0x10;
while((bit)ADC0CN&0x10);
temp<<=8;
temp|=ADC0H;
temp<<=8;
temp|=ADC0L;
temp/=4;
Temperature=(Vref*(float)temp/4096-0.603)/0.0025;//公式:Vtemp = 2.5 mV/C * Temp + 0.603 V
}
}
室温环境下,在线监控得:
temp=0x061B
Temperature=-12.24492
|