设计Pt100铂电阻测量温度的电路,温度测量范围是0-100摄氏度,要求LCD显示。画出电路图,标注元器件参数,简单说明测量原理和调节方式。根据要求,本设计的测温模拟电路使用热电阻Pt100温度传感器利用其感温效应,热电阻随环境温度的变化而变化,在电路图中将电阻值的变化转换成电压的变化,再将电压值作为输入信号输入至AD转换器中进行模拟信号到数字信号的转换,其输出端接单片机,向单片机内依据公式写入源程序,将被测温度在显示器上显示出来: 测量温度范围0℃~100℃; 分辨率为0.1℃; LCD数码直读显示。 本设计系统包括了温度测量单元,信号处理单元,A/D 转换模块,数据处理与控制模块,温度显示五个部分。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include <mega8.h>
- //#include <delay.h>
- #include <stdlib.h>
- #include <string.h>
- // Alphanumeric LCD Module functions
- #asm
- .equ __lcd_port=0x18 ;PORTB
- #endasm
- #include <lcd.h>
- #include <delay.h>
- #define ADC_VREF_TYPE 0xC0
- #define MCPCS PORTD.0
- #define MCPSCK PORTD.1
- #define MCPDATA PIND.2
- #define A 3.9083e-3
- #define B -5.775e-7
- #define C -4.183e-12
- unsigned long read_spi(void);
- float CalTem(float PT100R)
- {
- double fT,fR,fT0;
- char i=0;
- fR=PT100R;
- fT0=(fR/100-1)/A;
- return fT0;
- };
- unsigned long read_mcp(void)
- {
- long a[]={0,0,0,0,0};
- long x=0;
- char i=0;
- char k=5; // 数组大小 -1
- for (i=0;i<5;i++)
- {
- a[i]=read_spi(); // 连续3次读出数据
- delay_us(5);
- }
- //中值滤波
- while (k>0)
- {
- for (i=0;(i<(k-1));i++) // 从低到高排序
- {
- if (a[i]>a[i+1])
- {
- x=a[i+1];
- a[i+1]=a[i];
- a[i]=x;
- };
- };
- k--;
- };
- return a[2]; // 舍弃最大数据和最小数据。
- }
- unsigned long read_spi(void)
- {
- volatile char i=0;
- volatile long int result=0,x=0;
- MCPCS=0;// CS 先一个100us 低电平脉冲
- delay_us(100);
- MCPCS=1;
- delay_ms(80); // 高电平等待80ms 等待转换完成
- MCPCS=0; // 置 CS 低电平 开始发生 sck 脉冲
- for (i=0; i<24;i++) // 24 位数据
- {
- MCPSCK=0; // sck 脉冲下降沿
- delay_us(1); // 等5us 等待稳定
- //result=result<<1;
- x=MCPDATA; // 读出一位
- while (MCPDATA!=x) // 抖动处理 2次读出电平相同说明数据稳定
- {
- delay_us(1);
- x=MCPDATA;
- };
- result<<=1;
- result|=x;//(x<<(23-i));
- delay_us(5);
- MCPSCK=1; // 发送sck 上升沿
- delay_us(10);
- };
- MCPCS=1; // cs=1
- return result>>6;
- }
- // Read the AD conversion result
- unsigned int read_adc(unsigned char adc_input)
- {
- ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
- // Delay needed for the stabilization of the ADC input voltage
- delay_us(10);
- // Start the AD conversion
- ADCSRA|=0x40;
- // Wait for the AD conversion to complete
- while ((ADCSRA & 0x10)==0);
- ADCSRA|=0x10;
- return ADCW;
- }
- // 校准温度计查表 没20度一个校准,
- // -50 -30 -10 10 30 50 70 90 110 130 150
- const float CAL_Tem[]={4.7 ,4.65,4.65,4.6,4.6 ,4.55,4.55,4.50,4.45,4.45,4.45};
- const int ADCSTEP[]={ 1 ,96 ,189 ,282, 374,466 ,557 ,648,738,827 ,916};
- float CalcuTem(int ADC) // 温度校准计算 没有使用
- {
- int i=0;
- float r;
- for (i=0; i<10;i++)
- {
- if ((ADC<ADCSTEP[i+1])&&(ADC>=ADCSTEP[i])) break;
- };
- r=(ADC-ADCSTEP[i]);
- r=r/CAL_Tem[i];
- r=r-50;///CAL_Tem[i]-50+i*20+;
- r=r+i*20.0;
- return r;
- }
- volatile char stradc[15]="\0";
- void main(void)
- {
- // Declare your local variables here
- volatile long int MCPADC=0;
- volatile unsigned int adc=0;
- volatile float fadc=0;
- // Input/Output Ports initialization
- // Port B initialization
- // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
- // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
- PORTB=0x00;
- DDRB=0x00;
- // Port C initialization
- // Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
- // State6=T State5=T State4=T State3=T State2=T State1=T State0=T
- PORTC=0x00;
- DDRC=0x00;
- // Port D initialization
- // Func7=out Func6=out Func5=out Func4=out Func3=out Func2=int Func1=out Func0=out
- // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=1
- PORTD=0x07;
- DDRD=0xFB;
- // Timer/Counter 0 initialization
- // Clock source: System Clock
- // Clock value: Timer 0 Stopped
- TCCR0=0x00;
- TCNT0=0x00;
- // Timer/Counter 1 initialization
- // Clock source: System Clock
- // Clock value: Timer 1 Stopped
- // Mode: Normal top=FFFFh
- // OC1A output: Discon.
- // OC1B output: Discon.
- // Noise Canceler: Off
- // Input Capture on Falling Edge
- // Timer 1 Overflow Interrupt: Off
- // Input Capture Interrupt: Off
- // Compare A Match Interrupt: Off
- // Compare B Match Interrupt: Off
- TCCR1A=0x00;
- TCCR1B=0x00;
- TCNT1H=0x00;
- TCNT1L=0x00;
- ICR1H=0x00;
- ICR1L=0x00;
- OCR1AH=0x00;
- OCR1AL=0x00;
- OCR1BH=0x00;
- OCR1BL=0x00;
- // Timer/Counter 2 initialization
- // Clock source: System Clock
- // Clock value: Timer 2 Stopped
- // Mode: Normal top=FFh
- // OC2 output: Disconnected
- ASSR=0x00;
- TCCR2=0x00;
- TCNT2=0x00;
- OCR2=0x00;
- // External Interrupt(s) initialization
- // INT0: Off
- // INT1: Off
- MCUCR=0x00;
- // Timer(s)/Counter(s) Interrupt(s) initialization
- TIMSK=0x00;
- // Analog Comparator initialization
- // Analog Comparator: Off
- // Analog Comparator Input Capture by Timer/Counter 1: Off
- ACSR=0x80;
- SFIOR=0x00;
- // ADC initialization
- // ADC Clock frequency: 125.000 kHz
- // ADC Voltage Reference: Int., cap. on AREF
- ADMUX=ADC_VREF_TYPE & 0xff;
- ADCSRA=0x86;
- // LCD module initialization
- lcd_init(16);
- while (1)
- {
-
-
- MCPADC=0;
- MCPADC=read_mcp();
- // memset(stradc,' ',15);
- // lcd_gotoxy(0,0);
- // lcd_puts(stradc);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
Pt100仿真程序.zip
(89.83 KB, 下载次数: 35)
|