📄 temperature.c
字号:
void init()
{
TRISD=0x00; //设置PORTD数据方向寄存器
TRISB=0xe1; //设置PORTB数据方向寄存器
PORTD=0x00; //设置PORTD
ADCON1=0x8e; //设置AD控制寄存器1
ADCON0=0xc1; //设置AD控制寄存器0
Delay_ms(); //延时
}
int AD_aquire()
{
unsigned int result;
ADGO=0x01; //使能AD采集
while(ADGO)
{
result=ADRESH;
result=result*256+ADRESL;
}
ADGO=0x0; //屏蔽AD采集
return result;
}
float Temperatrue(int ad_result)
{
float temp;
temp=1000*result/6-273.15;
return temp;
}
void judge_temp(temp)
{
if(temp<min_temp)
up_temp();
if(temp>max_temp)
down_temp();
}
void up_temp()
{
PORTD=0xf0;
Delay_ms();
PORTD=0x0;
}
void main()
{
unsigned int result=0x0000;
float temp;
init();
while(1)
{
result=AD_aquire()
temp=Temperatrue(result);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -