📄 adc0_temp.c
字号:
//内部温度传感器调试程序//
//ADC0_TEMP.c
#include "C8051F340.h"
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long ulong;
uchar temppage;
uint kk;
float temp;
data float t[20];//存放温度检测数据,为20个数据
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void adc0_ini(){
REF0CN = 0x07;
AMX0P = 0x1E;
AMX0N = 0x1F;
ADC0CF = 0x78;
ADC0CN = 0x80;
EIE1 |= 0x08;
}
void PCA_Init()
{
PCA0MD &= ~0x40;
}
void Port_IO_Init()
{
//P2MDIN = 0xDF;
//P2SKIP = 0x20;
XBR1 = 0x40;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
PCA_Init();
Port_IO_Init();
adc0_ini();
}
void main(){
char i;
Init_Device();
EA=1;
AD0BUSY=1;
i=0;
while(1){
if(AD0INT){//由该位查询ADC0转化值是否更新
AD0INT=0;
kk=ADC0H*256;
kk+=ADC0L;//可用sfr16一次性读取
temp=(float)kk/1024;
temp*=2.40;
temp-=0.776;
temp/=0.00286;//将测量值转化成真实温度值
t[i]=temp;//将温度检测值存入长度为20的数组中
i++;
if(i>19)
i=0;
AD0BUSY=1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -