功能描述:
1、采用51单片机作为主控单元芯片;
2、采用PT100热电偶检测温度;
3、采用AD623作为信号放大电路;
4、采用MAX1240对信号进行模数转换;
5、采用LCD1602作为显示模块;
6、可通过按键修改ADC运算周期;
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
二、 操作说明
KEY1:进入ADC运算周期设置模式;
KEY2: 退出ADC运算周期设置模式;
KEY3:ADC运算周期时间加;
KEY4:ADC运算周期时间减;
点击器件上的按钮,可以调节参数;
单片机源程序如下:
- #include <reg52.h>
- #include <string.h>
- #include <math.h>
- #include "intrins.h"
- #define ROW1 0x80
- #define ROW2 0xC0
- #define Ts_CONST 1 //AD采样时间系数,采样时间为0.1xTs_CONST(s)
- #define NOACT 0
- #define FC 1
- #define Start_AD 2
- #define Cal_Temperature 3
- #define Kpt 0.02732644 //AD芯片max1240的采样值到温度值的转化系数
- void LCD_Init(void);
- void ClearDisp(unsigned char Row);
- void Display(unsigned char Addr, unsigned char *pstr);
- void DecToASC(unsigned int Dec,unsigned char *p, unsigned char n);
- void Disp_Initize(void);
- void Write_CMD(unsigned char CMD);
- unsigned int AD_MAX1240(void);
- sbit RS=P2^2;
- sbit RW=P2^1;
- sbit E=P2^0;
- sbit SDA=P1^5;
- sbit SCL=P1^6;
- sbit CS=P1^7;
- sbit Key=P3^5;
- sbit up=P3^6;
- sbit down=P3^7;
- unsigned char DispBuf[16];
- unsigned char RunState=NOACT;
- unsigned int AD_Reslut,tsflag,ts=1;
- float fz,tmp,tmp1,Pt;
- void delay(unsigned int j)//延时jms
- {
- unsigned int m,n;
- for(n=0;n<j;n++)
- {
- for(m=0;m<120;m++);
- }
- }
- void main(void)
- { LCD_Init();
- ClearDisp(ROW1);
- Disp_Initize();
- CS=1;
- SDA=1;
- SCL=0;
- TMOD=0x11;
- TF0=0; //开始程序前先延时65ms,等待max1240上电,以保证AD采样准确
-
- TH0=0;
- TL0=0;
- TR0=1;
- while(!TF0);
- TF0=0;
- TR0=0;
- TH0=0x3C; //12M晶振时延时50ms
- TL0=0xB0;
- ET0=1;
- TR0=1;
- EX1=1;
- IT1=1;
- EA=1;
- while(1)
- switch(RunState)
- { case NOACT:
- break;
- case FC: //F0计算及显示
- fz=pow(10,(tmp-121.0000)/10);
- DecToASC(fz,DispBuf,1);
- DispBuf[1]='.';
- DecToASC((fz-(unsigned int)fz)*1000,DispBuf+2,3);
- DispBuf[5]='\0';
- Display(0x80+11,DispBuf);
-
-
- RunState=NOACT;
- break;
- case Start_AD: //开始AD采样
- AD_Reslut=AD_MAX1240();
- RunState=Cal_Temperature;
- break;
- case Cal_Temperature: //将AD值转化为温度并进行线性化
- {
-
- Pt=AD_Reslut*Kpt;
- Pt+=100; //温度值
-
- tmp=Pt/100;
- tmp=1-tmp;
- tmp=2.31e-6L*tmp;
- tmp+=1.527480889e-5L;
- tmp=sqrt(tmp);
- tmp+=-3.9083e-3L;
- tmp/=-1.155e-6L;//AD采样值线性化修正
- tmp1=tmp;
- tmp=(tmp+tmp1)/2;//取平均温度
- tmp=((float)((unsigned int)(tmp*10)))/10 ;
- DecToASC(tmp,DispBuf,3);
- DispBuf[3]='.';
- DecToASC((tmp-(unsigned int)tmp)*10,DispBuf+4,1);
- DispBuf[5]='\0';
- Display(0xC0+2,DispBuf); //显示函数
- }
-
- RunState=NOACT;
- break;
- }
- }
- /*******************************************************************************/
- unsigned int AD_MAX1240(void) //读取AD,AD芯片为串口数据形式
- { unsigned int adtmp=0;
- unsigned char i;
- CS=0;
- while(!SDA);
- SCL=1;
- adtmp<<=1;
- SCL=0;
- for(i=0;i<12;i++)
- { SCL=1;
- adtmp<<=1;
- if(SDA==1)adtmp++;
- SCL=0;
- }
- CS=1;
- return adtmp;
- }
- /*******************************************************************************/
- void Disp_Initize(void) //LCD初始化,将Ts,F0,t等提示字符显示在屏幕上
- { //unsigned char *p;
-
-
- DispBuf[0]='T';
- DispBuf[1]='s';
- DispBuf[2]='=';
- DecToASC(ts,DispBuf+3,2);
- DispBuf[5]='s';
-
- DispBuf[8]='f' ;
- DispBuf[9]='0' ;
- DispBuf[10]='=' ;
- DispBuf[16]='\0';
- Display(0x80,DispBuf);
- DispBuf[0]='t';
- DispBuf[1]='=';
- DispBuf[2]='\0';
- Display(0xc0,DispBuf);
- }
- /*******************************************************************************/
- void INT1_ISR(void) interrupt 2 //切换采样时间的中断函数,用于开关量识别和改变Ts(采样时间)
- {
- EA=0;
- TR0=0;
- ET0=0;
- strcpy(DispBuf," ");
- Display(0x80+11,DispBuf);
- while(1)
- {
-
- if(up==0)
- {
- delay(100);
- if(up==0)
- ts++;
- }
-
- if(down==0)
-
- { delay(100);
- if(down==0)
- ts--;
- }
-
- if(ts>60)
- ts=1;
- if(ts<=0)
- ts=60;
- DecToASC(ts,DispBuf,2);
- DispBuf[2]='s';
- DispBuf[3]='\0';
- Display(0x80+3,DispBuf);
- if(Key==0)
- break;
- }
- EA=1;
- TR0=1;
- ET0=1;
-
- }
- /*******************************************************************************/
- void T0_ISR(void) interrupt 1 //定时中断程序
- { static unsigned char T0_CNT=Ts_CONST;
- //static bit Flag=0;
- TH0=0x3C;
- TL0=0xB0;
- //Flag=!Flag;
- //if(Flag)return;
- T0_CNT--;
- tsflag++;
- if(!T0_CNT)
- { T0_CNT=Ts_CONST;
- RunState=Start_AD; //AD采样
- }
- if(tsflag>=ts*20)
- {
- tsflag=0;
- RunState =FC; //Ts到时进行F0值运算
- }
- }
- /*******************************************************************************/
- void DecToASC(unsigned int Dec,unsigned char *p, unsigned char n) //将Dec变量编程可以在1602上直接显示的ASICII值
- { unsigned char i;
- p+=n;
- p--;
- for(i=0;i<n;i++)
- { *p=Dec%10+0x30;
- p--;
- Dec/=10;
- }
- }
- /*LCD显示*******************************************************************************/
- void Check_Busy(void)
- {// return;
- do
- { P0=0xFF;
- E=0;
- RS=0;
- RW=1;
- E=1;
- _nop_();
- }while(P0&0x80);
- E=0;
- }
- /*******************************************************************************/
- void Write_CMD(unsigned char CMD)
- {
- Check_Busy();
- E=0;
- RS=0;
- RW=0;
- P0=CMD;
- E=1;
- _nop_();
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码 所有资料51hei附件下载(含仿真代码等):
热电偶测温-仿真设计(51+PT100+MAX1240+1602+KEY4).7z
(9.27 MB, 下载次数: 174)
|