
给你写一个吧,累死了,要采纳哦:
#include<reg51h>
#define uchar unsigned char
#define uint unsigned int
uchar code table0[]="Tempeture:";
uchar code table1[]="welcom to text!";
sbit lcdrs=P3^5;
//sbit lcdrw=P2^1;
sbit lcden=P3^4;
sbit ds=P2^2;
sbit beep=P2^3;
sbit dula=P2^6;
sbit wela=P2^7;
bit flag;
uchar num;
uint temp,t;
uchar temp_bai,temp_shi,temp_ge,temp_little;
float xs_temp;
void delay(uint z)//延时1ms子程序
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void ds_reset( ) //DS18B20初始化
{
uint i;
bit pw=1;
while(pw)
{
ds=1;
i++;
ds=0;
i=103;
while(i>0)i--;//835us
ds=1;
i=4;
while(i>0)i--;//35us
pw=ds;
}
i=70;
while(i>0)i--;//604us
ds=1;
}
void temp_wr_byte(uchar dat)//DS18B20写一个字节的数据子程序
{
bit testb;
uchar j;
uint i;
for(j=0;j<8;j++)
{
testb=dat&0x01;
dat=dat>>1;
if(testb) //textb为真写1,
{
ds=0; //i++;i++;
i=1;
while(i>0)i--; //至少1us
ds=1;
i=8;
while(i>0)i-- ; //66us
}
else
{
ds=0; //写0
i=8;
while(i>0)i--;
ds=1; //对IO线进行写0
i=1;
while(i>0)i--;
}
}
}
bit temp_rd_bit( ) //读一位数据子程序
{
uint i;
bit dat;
ds=1;
i=0;
ds=0; //2us
i++;
i++;
ds=1; //6us
i++; //3us
dat=ds;
i=4;
while(i>0)i--; //32us
return(dat);
}
uchar tempread( )//读一个字节数据
{
uchar i,j,dat;
dat=0;
for(i=0;i<8;i++)
{
j=temp_rd_bit( );
dat=(j<<7)|(dat>>1); //读出数据最低位在最前面,刚好一个字节在dat里
}
return(dat); //读了8次即8个字节
}
void tempchange( ) //启动温度转换
{
ds_reset( );
// delay(1);
temp_wr_byte(0xcc); //跳过ROM
temp_wr_byte(0x44); //启动温度转换
}
void temp_rec( ) //读取温度数据
{
uchar a,b;
ds_reset( );
// delay(1);
temp_wr_byte(0xcc);
temp_wr_byte(0xbe); //从暂存寄存器读字节
a=tempread( );
b=tempread( );
temp=b;
temp<<=8; //保留最高位
temp=temp|a;
if(temp<0x7fff)//是否为正数?
{
flag=0;
}
else
{
flag=1; //为负数时,温度数据要反向
temp=~temp+1;
}
xs_temp=temp00625; //分辨率为1/2^12
}
void write_com(uchar com)//液晶写指令 *** 作子程序
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date)//液晶写数据 *** 作子程序
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void lcd_init( )//液晶初始化子程序
{
dula=0;
wela=0;
lcden=0;//lcdrw=0;
write_com(0x38); //基本指令集
write_com(0x0c); //整体显示开,游标和游标位置关
write_com(0x06); //写一个字节时,地址指针加1,光标加1
write_com(0x01); // 清DDRAM
// write_com(0x80); //将DDRAM地址到地址计数器AC,12864中用
while(table1[num]!='\0')
{write_date(table1[num]);
num++;
delay(50);
}
}
void shujucl( )//数据处理子函数
{
t=xs_temp10; //小数点后边只显示1位,
temp_bai=t/1000+0x30; //让其显示0x3x,对应着asc的数字
temp_shi=t%1000/100+0x30;
temp_ge=t%100/10+0x30;
temp_little=t%10+0x30;
if(xs_temp<12||xs_temp>15)
beep=0;
else beep=1;
}
void xianshi( )
{ write_com(0x80); //设定DDRAM地址
for(num=0;num<11;num++)
{
write_date(table0[num]);
delay(5);
}
write_com(0x80+0x40); //设置显示到对应的地址
if(flag==1)
write_date('-'); //表示温度为负数
else
write_date(temp_bai);
write_com(0x8a+0x40); //设定到0x8b所在位
write_date(temp_shi);
write_com(0x8b+0x40);
write_date(temp_ge);
write_com(0x8c+0x40);
write_date('');
write_com(0x8d+0x40); //设置到第二个字节
write_date(temp_little);
delay(5);
}
void main( )
{
lcd_init( );
ds_reset( ) ;
while(1)
{
tempchange( ); //启动温度转换
temp_rec( ); //读取温度数据
shujucl( ); //数据处理
xianshi( ); //数据显示
}
}
using
System;
namespace
ConsoleTest{
public
class
Temperature{
private
double
cel;
public
double
Cels{
set{cel=value;}
get{return
cel;}
}
public
void
change()
{
cel=
cel
9/
5
+
32;
}
static
public
void
Main(String
[]args){
Temperature
t
=
new
Temperature();
ConsoleWrite("温度转换\n请输入摄氏度温度值:");
tCels
=
doubleParse(ConsoleReadLine());
tchange();
ConsoleWriteLine("转换为华氏温度值为"+tCels+"度");
}
}
}温度转换
请输入摄氏度温度值:30
转换为华氏温度值为86度
请按任意键继续
尊敬的美菱用户,您好!
轻触“选择设定”键,自动、速冻、速冻时间、冷藏室温度设定值、变温室设定值、冷冻室温度设定值一次轮流闪烁,每按一次闪烁地点变化一次,并形成循环。在对冰箱进行功能或温度更改后,轻触确认键后生效,若未按“设定确认”键,则设置无效。
您可以对照冰箱使用说明书。
若您需要电子说明书,请把您所需要产品的型号和您的姓名及家庭住址发邮件至meilingkf@163com 即可。
很高兴为您服务,感谢您对美菱的支持!
以上就是关于求一个C程序:(温度控制系统)用矩阵键盘中的三个键设定温度调节然后再用1602液晶显示全部的内容,包括:求一个C程序:(温度控制系统)用矩阵键盘中的三个键设定温度调节然后再用1602液晶显示、C#温度转换:编写一个控制台程序、你好有谁知道美菱冰箱BCD-460WE9B 怎么进入参数调整程序调整温度等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)