C语言程序编写 温度计显示
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
adwr=1;
_nop_();
adwr=0;
_nop_();
adwr=1;
delay(1);
P1=0xff;
adrd=1;
_nop_();
adrd=0;
_nop_();
adval=P1;
adrd=1;
return adval;
lpf=(dat[1]+dat[2]+dat[3])/3;
return lpf;
}
void temp_converted() //AD转换温度函数,每段拟合线性化,scope
{
uchar i;
float k;
uchar m;
uchar temp;
uchar code tabler[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1};//led显示编码不带小数点
//AD转换的数值
uchar code tempdata[75]={11,17,34,41,52,61,69,79,90,100,111,117,126,132,138,145,149,154,160,165,169,173,178,182,186,188,193,196,199,203,205,207,208,209,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253};
{
led1=1;
led2=1;
beep=1;
}
}
void main()//主函数
{
while(1)
{
temp_converted();
//display(LPF());
}
}
sbit led1=P3^0;
sbit beep=P3^1;
sbit led2=P3^3;
sbit cs=P2^3;
sbit SD0= P2^0;
sbit CSN=P2^1;
sbit SCLK=P2^5;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//led显示编码
m=LPF();
for(i=0;i<=73;i++)
{
if((m>=tempdata[i])&(m<=tempdata[i+1]))
{
k=temptest[i]+((m-tempdata[i])*((temptest[i+1]-temptest[i])/(tempdata[i+1]-tempdata[i])));
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit adwr=P3^7;
sbit adrd=P3^6;
uchar AD;
void delay(uint n)//延迟部分,延迟n毫秒
{
uint i,j;
for(i=n;i>0;i--)
for(j=110;j>0;j--);
}
void display(uint m)//显示部分
{
uint i,j,k;
i=m/100;
cs=1;
}
*/
uchar tcl()
{
uint j;
CSN=1;
SCLK=0;
_nop_();
CSN=0;
_nop_();
AD=0;
for(j=0;j<8;j++)
{
AD=AD<<1;
SCLK=1;
_nop_();
j=m/10%10;
k=m%10;
dula=1;
P0=table[i];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(50);
dula=1;
P0=tabler[j];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(50);
dula=1;
P0=table[k];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(50);
}
/*
uchar AD() //独立AD转换功能
{
uchar adval;
cs=0;
break;
}
}
display(k*10);
if((k<15)||(k>40))
{
led1=0;
led2=1;
beep=1;
}
if((k<10)||(k>50))
{
led1=0;
led2=0;
beep=0;
}
if((k>=15)&&(k<=40))
//AD转换对应的温度值
float code temptest[75]={5.5,6.0,7.3,8.1,9.0,10.0,11.0,12.0,14.1,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,35.0,36.0,36.3,36.9,37.5,39.1,39.4,39.8,40.1,40.6,41.0,41.4,41.7,42.5,42.8,43.0,43.2,44.8,44.9,45.0,45.3,46.1,46.8,47.3,47.8,48.9,49.5,50.3,51.0,51.7,52.3,52.9,53.5,54.1,54.8,55.6,56.0,58.3,59.0,59.8,60.6,62.4,63.8,65.1,66.3,67.6};
if(SD0)
AD|=1;
SCLK=0;
_nop_();
}
return AD;
}
uchar LPF() //数据平均处理函数
{
uchar dat[5];
uchar i,j,k;
uchar lpf=0;
for(i=0;i<5[i]=tcl();
}
for(i=0;i<4;i++)
{
for(j=i+1;j<5;j++)
if(dat[j-1]>dat[j])
{
k=dat[i];
dat[i]=dat[j];
dat[j]=k;
}
}
dat[0]=dat[4]=0;
_nop_();
adwr=0;
_nop_();
adwr=1;
delay(1);
P1=0xff;
adrd=1;
_nop_();
adrd=0;
_nop_();
adval=P1;
adrd=1;
return adval;
lpf=(dat[1]+dat[2]+dat[3])/3;
return lpf;
}
void temp_converted() //AD转换温度函数,每段拟合线性化,scope
{
uchar i;
float k;
uchar m;
uchar temp;
uchar code tabler[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1};//led显示编码不带小数点
//AD转换的数值
uchar code tempdata[75]={11,17,34,41,52,61,69,79,90,100,111,117,126,132,138,145,149,154,160,165,169,173,178,182,186,188,193,196,199,203,205,207,208,209,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253};
{
led1=1;
led2=1;
beep=1;
}
}
void main()//主函数
{
while(1)
{
temp_converted();
//display(LPF());
}
}
sbit led1=P3^0;
sbit beep=P3^1;
sbit led2=P3^3;
sbit cs=P2^3;
sbit SD0= P2^0;
sbit CSN=P2^1;
sbit SCLK=P2^5;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//led显示编码
m=LPF();
for(i=0;i<=73;i++)
{
if((m>=tempdata[i])&(m<=tempdata[i+1]))
{
k=temptest[i]+((m-tempdata[i])*((temptest[i+1]-temptest[i])/(tempdata[i+1]-tempdata[i])));
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit adwr=P3^7;
sbit adrd=P3^6;
uchar AD;
void delay(uint n)//延迟部分,延迟n毫秒
{
uint i,j;
for(i=n;i>0;i--)
for(j=110;j>0;j--);
}
void display(uint m)//显示部分
{
uint i,j,k;
i=m/100;
cs=1;
}
*/
uchar tcl()
{
uint j;
CSN=1;
SCLK=0;
_nop_();
CSN=0;
_nop_();
AD=0;
for(j=0;j<8;j++)
{
AD=AD<<1;
SCLK=1;
_nop_();
j=m/10%10;
k=m%10;
dula=1;
P0=table[i];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(50);
dula=1;
P0=tabler[j];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(50);
dula=1;
P0=table[k];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(50);
}
/*
uchar AD() //独立AD转换功能
{
uchar adval;
cs=0;
break;
}
}
display(k*10);
if((k<15)||(k>40))
{
led1=0;
led2=1;
beep=1;
}
if((k<10)||(k>50))
{
led1=0;
led2=0;
beep=0;
}
if((k>=15)&&(k<=40))
//AD转换对应的温度值
float code temptest[75]={5.5,6.0,7.3,8.1,9.0,10.0,11.0,12.0,14.1,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,35.0,36.0,36.3,36.9,37.5,39.1,39.4,39.8,40.1,40.6,41.0,41.4,41.7,42.5,42.8,43.0,43.2,44.8,44.9,45.0,45.3,46.1,46.8,47.3,47.8,48.9,49.5,50.3,51.0,51.7,52.3,52.9,53.5,54.1,54.8,55.6,56.0,58.3,59.0,59.8,60.6,62.4,63.8,65.1,66.3,67.6};
if(SD0)
AD|=1;
SCLK=0;
_nop_();
}
return AD;
}
uchar LPF() //数据平均处理函数
{
uchar dat[5];
uchar i,j,k;
uchar lpf=0;
for(i=0;i<5[i]=tcl();
}
for(i=0;i<4;i++)
{
for(j=i+1;j<5;j++)
if(dat[j-1]>dat[j])
{
k=dat[i];
dat[i]=dat[j];
dat[j]=k;
}
}
dat[0]=dat[4]=0;