进气温度信号的处理过程

进气温度信号的处理过程,第1张

1、查进气温度传感器的搭铁线是否有虚接情况,导致传感器信号电压增高;特别是插头有无水渍等情况,若有虚接,修理并插紧。

2、拔掉进气温度传感器的线锋此插头,检测线插头部分的电源线电压是否过高,导致传感器信号电压增高;若有携基和,更换电脑版。

3、查进气温度传感器本身是否阻值增大,出现故障导致信辩盯号电压增高;若有,更换进气温度传感器。

#include<reg52.h> #include<math.h>

#include<INTRINS.H>

#define uchar unsigned char

#define uint unsigned int

/******************************************************************/

/*定义端口*/

/******************************************************************/

sbit seg1=P2^0

sbit seg2=P2^1

sbit seg3=P2^2

sbit DQ=P1^7//ds18b20 端口

sfr dataled=0x80//前数显示数据端口

/******************************************************************/

/*全局变量*/

/******************************************************************/

uint temp

uchar flag_get,count,num,minute,second

uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}

//7段数码管段码表共阳

uchar str[6]

/******************************************************************/

/* 函数声明 */

/******************************************************************/

void delay1(uchar MS)

unsigned int ReadTemperature(void)

void Init_DS18B20(void)

unsigned char ReadOneChar(void)

void WriteOneChar(unsigned char dat)

void delay(unsigned int i)

/******************************************************************/

/*主函数 */

/******************************************************************/

main()

{

unsigned char TempH,TempL

TMOD|=0x01//定时器设置游码

TH0=0xef

TL0=0xf0

IE=0x82

TR0=1

P2=0x00

count=0

while(1)

{

str[5]=0x39//显示C符号

str[1]=tab[TempH/100]//十位温度

str[2]=tab[(TempH%100)/10]//十位温度

str[3]=tab[(TempH%100)%10]|0x80//个位温度,带小数点

str[4]=tab[TempL]

if(flag_get==1) //神悔哪定时读取当前温度

{

temp=ReadTemperature()

if(temp&0x8000)

{

str[0]=0x40//负号标志

temp=~temp // 取反加1

temp +=1

}

else

str[0]=0

TempH=temp>>4

TempL=temp&0x0F

TempL=TempL*6/10//小数近似处理

flag_get=0

}

}

}

/******************************************************************/

/* 定时器中断*/

/******************************************************************/

void tim(void) interrupt 1 using 1//中断,用于数码管扫描和温度检测间隔

{

TH0=0xef//定时器重装值

TL0=0xf0

num++

if (num==50)

{num=0

flag_get=1//标志位有效

second++

if(second>=60)

{second=0

minute++

}

}

count++

if(count==1)

{P2=0

dataled=str[0]}//数码管扫描

if(count==2)

{P2=1

dataled=str[1]}

if(count==3)

{ P2=2

dataled=str[2]

}

if(count==4)

{ P2=3

dataled=str[3]

}

if(count==5)

{ P2=4

dataled=str[4]

}

if(count==6)

{ P2=5

dataled=str[5]

count=0}

}

/******************************************************************/

/*延时函数*/

/******************************************************************/

void delay(unsigned int i)//延时函数

{

while(i--)

}

/******************************************************************/

/*初始化 */

/******************************************************************/

void Init_DS18B20(void)

{

unsigned char x=0

DQ = 1 //DQ复位

delay(8) //稍做延时

DQ = 0 //单片机将DQ拉低

delay(80)//精确延时 大于 480us

DQ = 1 //拉高总线

delay(10)

x=DQ //稍做延时后 如果x=0则初始化成功 x=1则初始化失败

delay(5)

}

/******************************************************************/

/*读一个字节 */

/******************************************************************/

unsigned char ReadOneChar(void)

{

unsigned char i=0

unsigned char dat = 0

for (i=8i>0i--)

{

DQ = 0// 给脉冲信号

dat>>=1

DQ = 1// 给脉冲信号

if(DQ)

dat|=0x80

delay(5)

}

return(dat)

}

/******************************************************************/

/* 写一个字节 */

/******************************************************************/

void WriteOneChar(unsigned char dat)

{

unsigned char i=0

for (i=8i>0i--)

{

DQ = 0

DQ = dat&0x01

delay(5)

DQ = 1

dat>>=1

}

delay(5)

}

/******************************************************************/

/* 读取温度 */

/******************************************************************/

unsigned int ReadTemperature(void)

{

unsigned char a=0

unsigned int b=0

unsigned int t=0

Init_DS18B20()

WriteOneChar(0xCC)// 跳过读序号列号的 *** 作

WriteOneChar(0x44)// 启动温度转换

delay(200)

Init_DS18B20()

WriteOneChar(0xCC)//跳过读序号列号的 *** 作

WriteOneChar(0xBE)//读取温度寄存器等(共可读9个寄存器) 前两个就是温度

a=ReadOneChar() //低位

b=ReadOneChar() //高位

b<<=8

t=a+b

return(t)

}

//LZ,这是测温并且用数码管显示程序,报警可以自己另行添加!主要程序就是这些!

()

我做过DS18B20温控设备,单总线传感这是念衫一个不错的选择哦。下面是C语言程序,硬件接线如下:

(1)把“单片机系统”区域中的P0.0-P0.7用8芯排线连接到“动态数码显示”区域中的ABCDEFGH端子上。

(2)把“单片机系统”区域中的P2.0-P2.7用8芯排线连接到“动态数码显示”区域中的S1S2S3S4S5S6S7S8端子上。

(3)把DS18B20芯片插入“四路单总线”区域中的任一个插座中,注意电源与地信号不要接反。

(4)把“四路单总线”行蔽区域中的对应的DQ端子连接到“单片机系仔带腔统”区域中的P3.7/RD端子上。

#include <REG52.h>//at89c52

#include <INTRINS.h>

unsigned char code displaybit[]={0xfe,0xfd,0xfb,0xf7,

0xef,0xdf,0xbf,0x7f}

unsigned char code displaycode[]={0x3f,0x06,0x5b,0x4f,

0x66,0x6d,0x7d,0x07,

0x7f,0x6f,0x77,0x7c,

0x39,0x5e,0x79,0x71,0x00,0x40}

unsigned char code dotcode[32]={0,3,6,9,12,16,19,22,

25,28,31,34,38,41,44,48,

50,53,56,59,63,66,69,72,

75,78,81,84,88,91,94,97}

unsigned char displaycount

unsigned char displaybuf[8]={16,16,16,16,16,16,16,16}

unsigned char timecount

unsigned char readdata[8]

sbit DQ=P3^7

bit sflag

bit resetpulse(void)

{

unsigned char i

DQ=0

for(i=255i>0i--)

DQ=1

for(i=60i>0i--)

return(DQ)

for(i=200i>0i--)

}

void writecommandtods18b20(unsigned char command)

{

unsigned char i

unsigned char j

for(i=0i<8i++)

{

if((command &0x01)==0)

{

DQ=0

for(j=35j>0j--)

DQ=1

}

else

{

DQ=0

for(j=2j>0j--)

DQ=1

for(j=33j>0j--)

}

command=_cror_(command,1)

}

}

unsigned char readdatafromds18b20(void)

{

unsigned char i

unsigned char j

unsigned char temp

temp=0

for(i=0i<8i++)

{

temp=_cror_(temp,1)

DQ=0

_nop_()

_nop_()

DQ=1

for(j=10j>0j--)

if(DQ==1)

{

temp=temp | 0x80

}

else

{

temp=temp | 0x00

}

for(j=200j>0j--)

}

return(temp)

}

void main(void)

{

TMOD=0x01

TH0=(65536-4000)/256

TL0=(65536-4000)%256

ET0=1

EA=1

while(resetpulse())

writecommandtods18b20(0xcc)

writecommandtods18b20(0x44)

TR0=1

while(1)

{

}

}

void t0(void) interrupt 1 using 0

{

unsigned char x

unsigned int result

TH0=(65536-4000)/256

TL0=(65536-4000)%256

if(displaycount==2)

{

P0=displaycode[displaybuf[displaycount]] | 0x80

}

else

{

P0=displaycode[displaybuf[displaycount]]

}

P2=displaybit[displaycount]

displaycount++

if(displaycount==8)

{

displaycount=0

}

timecount++

if(timecount==150)

{

timecount=0

while(resetpulse())

writecommandtods18b20(0xcc)

writecommandtods18b20(0xbe)

readdata[0]=readdatafromds18b20()

readdata[1]=readdatafromds18b20()

for(x=0x<8x++)

{

displaybuf[x]=16

}

sflag=0

if((readdata[1] &0xf8)!=0x00)

{

sflag=1

readdata[1]=~readdata[1]

readdata[0]=~readdata[0]

result=readdata[0]+1

readdata[0]=result

if(result>255)

{

readdata[1]++

}

}

readdata[1]=readdata[1]<<4

readdata[1]=readdata[1] &0x70

x=readdata[0]

x=x>>4

x=x &0x0f

readdata[1]=readdata[1] | x

x=2

result=readdata[1]

while(result/10)

{

displaybuf[x]=result%10

result=result/10

x++

}

displaybuf[x]=result

if(sflag==1)

{

displaybuf[x+1]=17

}

x=readdata[0] &0x0f

x=x<<1

displaybuf[0]=(dotcode[x])%10

displaybuf[1]=(dotcode[x])/10

while(resetpulse())

writecommandtods18b20(0xcc)

writecommandtods18b20(0x44)

}

}

Good luck!


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12414670.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-23
下一篇2023-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存