问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

基于单片机的温度检测,要求LCD显示。要求范围0-99度,精确到0.1度

发布网友 发布时间:2022-05-14 18:06

我来回答

2个回答

热心网友 时间:2023-10-19 08:50

你想用什么做呢?
我指的是传感器。

热心网友 时间:2023-10-19 08:50

/*******************************************************************************
* LCD1602显示SHT10采集的温度和湿度,温度达上限,蜂鸣器报警 *
* 引用端口:p0,p2 控制1602液晶屏,P3.6 P3.7控制温度芯片,P3.5蜂鸣器 *
********************************************************************************/
#include<reg51.h>
#include <intrins.h>
#include <stdio.h>
#include <string.h>

#define uchar unsigned char
#define uint unsigned int

#define TEMPUP 80 //温度上限, 达到该温度蜂鸣器报警
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef bit BOOL ;
/*******************************************/
sbit buzzer = P3^5; //蜂鸣器
BOOL start;
/******************************************/

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 1602相关控制信号及变量
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sbit rs = P2^3;
sbit rw = P2^4;
sbit ep = P2^5;
BYTE dis1[16];
BYTE dis2[16];

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SHT10 相关控制信号及变量
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
enum {TEMP,HUMI};
sbit DATA = P3^6;
sbit SCK = P3^7;

unsigned char Tem[2];
unsigned char Hum[2];
uchar showbuf[6];
uchar error;
////////////////////////////////////////////////
//温湿度传感器地址定义
///////////////////////////////////////////////
#define noACK 0
#define ACK 1
//adr command r/w
#define STATUS_REG_W 0x06 //000 0011 0
#define STATUS_REG_R 0x07 //000 0011 1
#define MEASURE_TEMP 0x03 //000 0001 1
#define MEASURE_HUMI 0x05 //000 0010 1
#define RESET 0x1e //000 1111 0

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SHT10 温湿度读字节子程序
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
char s_write_byte(unsigned char value)
{
unsigned char i,error=0;
for (i=0x80;i>0;i/=2) //shift bit for masking
{
if (i & value)
DATA=1; //masking value with i , write to SENSI-BUS
else
DATA=0;
SCK=1; //clk for SENSI-BUS
_nop_();_nop_();_nop_(); //pulswith approx. 5 us
SCK=0;
}
DATA=1; //release DATA-line
SCK=1; //clk #9 for ack
error=DATA; //check ack (DATA will be pulled down by SHT11)
SCK=0;
return error; //error=1 in case of no acknowledge
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SHT10 温湿度写字节子程序
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
char s_read_byte(unsigned char ack)
{
unsigned char i,val=0;
DATA=1; //release DATA-line
for (i=0x80;i>0;i/=2) //shift bit for masking
{
SCK=1; //clk for SENSI-BUS
if (DATA) val=(val | i); //read bit
SCK=0;
}
DATA=!ack; //in case of "ack==1" pull down DATA-Line
SCK=1; //clk #9 for ack
_nop_();_nop_();_nop_(); //pulswith approx. 5 us
SCK=0;
DATA=1; //release DATA-line
return val;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SHT10 温湿度传输其始子程序
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void s_transstart(void)
{
DATA=1; SCK=0; //Initial state
_nop_();
SCK=1;
_nop_();
DATA=0;
_nop_();
SCK=0;
_nop_();_nop_();_nop_();
SCK=1;
_nop_();
DATA=1;
_nop_();
SCK=0;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SHT10 温湿度连接复位子程序
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void s_connectionreset(void)
{
unsigned char i;
DATA=1; SCK=0; //Initial state
for(i=0;i<9;i++) //9 SCK cycles
{
SCK=1;
SCK=0;
}
s_transstart(); //transmission start
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SHT10 温湿度获取温度或湿度子程序
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
{
unsigned error=0;
unsigned int i;

s_transstart(); //transmission start
switch(mode)
{ //send command to sensor
case TEMP : error+=s_write_byte(MEASURE_TEMP); break;
case HUMI : error+=s_write_byte(MEASURE_HUMI); break;
default : break;
}
for (i=0;i<65535;i++)
if(DATA==0) break; //wait until sensor has finished the measurement
if(DATA) error+=1; // or timeout (~2 sec.) is reached
*(p_value) =s_read_byte(ACK); //read the first byte (MSB)
*(p_value+1)=s_read_byte(ACK); //read the second byte (LSB)
*p_checksum =s_read_byte(noACK); //read checksum
return error;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//延时子程序
//若机器周期为1us,则本延时程序为延时x(ms)
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void delay(BYTE x)
{
BYTE i;
while(x--)
{
for(i = 0; i< 250; i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//LCD状态检测子程序
//测试LCD忙碌状态
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BOOL lcd_bz()
{
BOOL result;
rs = 0;
rw = 1;
ep = 1;
_nop_();
_nop_();
_nop_();
_nop_();
result = (BOOL)(P0 & 0x80);
ep = 0;
return result;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//LCD写指令子程序
// 写入指令数据到LCD
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void lcd_wcmd(BYTE cmd)
{
while(lcd_bz());
rs = 0;
rw = 0;
ep = 0;
_nop_();
_nop_();
P1 = cmd;
_nop_();
_nop_();
_nop_();
_nop_();
ep = 1;
_nop_();
_nop_();
_nop_();
_nop_();
ep = 0;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//LCD显示位置设置子程序
//设定显示位置
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void lcd_pos(BYTE pos)
{
lcd_wcmd(pos | 0x80);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//LCD写数据子程序
//写入字符显示数据到LCD
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void lcd_wdat(BYTE dat)
{
while(lcd_bz());
rs = 1;
rw = 0;
ep = 0;
P1 = dat;
_nop_();
_nop_();
_nop_();
_nop_();
ep = 1;
_nop_();
_nop_();
_nop_();
_nop_();
ep = 0;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//LCD初始化子程序
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void lcd_init()
{ //LCD初始化设定
lcd_wcmd(0x38); //
delay(1);
lcd_wcmd(0x0c); //
delay(1);
lcd_wcmd(0x06); //
delay(1);
lcd_wcmd(0x01); //清除LCD的显示内容
delay(1);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//显示温湿度子程序
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void ShowTem(uchar *ptem,uchar *phum)
{
int ntemp,i,t1,t0,len;
int nhum;
float flt1;

ntemp= (*ptem)*256+ (*(ptem+1));
t1=(ntemp)/100-40;
t0=(ntemp)%100;
memset(dis1,0x20,16);
sprintf(dis1,"Temp %d.%02d C ",t1,t0);
lcd_pos(0); // 设置显示位置为第一行的第1个字符
len=strlen(dis1);
for(i=0;i<len;i++)
{
lcd_wdat(dis1[i]);
}
if(t1>TEMPUP-1)
{
start=1;
}
else
{
buzzer=1;
start=0;
}

nhum = (*phum)*256+ (*(phum+1));
flt1=0.0405*nhum-0.0000028*nhum*nhum-4;
memset(dis2,0x20,16);
sprintf(dis2,"Humi %f ",flt1);
len=strlen(dis2);
len=9;
lcd_pos(40); // 设置显示位置为第二行的第1个字符
for(i=0;i<len;i++)
{
lcd_wdat(dis2[i]);
}
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//主程序
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void main()
{
uchar checksum,i;
buzzer=1;
start=0;

lcd_init(); // 初始化LCD
delay(10);
s_connectionreset();
while(1)
{
error=0;
error+=s_measure(&Tem,&checksum,TEMP); //measure temperature
error=0;
error+=s_measure(&Hum,&checksum,HUMI); //measure temperature
ShowTem(&Tem,&Hum);
delay(500);
if(start)
{
for(i=0;i<255;i++)
{
buzzer =!buzzer;
delay(1);
}
}
}
}

/********************************** EDN SHT10_1602.c **************************************/
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
ef英语哪个好 EF英孚英语培训怎么样? 英孚英语好不好 EF英孚教育到底好不好 大佬们,麦芒7和荣耀10那个值得入手?2500以下的机子还有啥好推荐的么... 介绍几款2500元以前的手机 像素一定要高 其他的不做要求 近期想入手一部安卓手机,价格2200到2500左右…买HTC desire Z还是 三星... 笔记本忘记开机密码怎么办急死了 笔记本电脑屏幕开机锁忘记密码 怎么办?急死了 华硕笔记本电脑开机密码忘记了怎样找回?系统是Windows 7旗舰版... 里加偏旁再组词? 单片机lcd显示温度,显示的不对。求问 里字加可以什么偏旁组词 12864lcd上如何显示温度单位 单片机系统lcd显示屏只显示温度不显示湿度是怎么回事? NHR-216 LCD智能温度变送器显示屏显示哪些内容? 一加9pro好不好用?刷剧体验可好? 格子间女人 ,这部电视剧值得看吗? 格子间的女人下载 谁知道《格子间女人》一共有多少集?影剧基本资料及演员表介绍_百度知 ... 格子间女人沈培的结局 格子间的女人电视剧全集在哪里能看了? 录音软件CE对笔记本配置要求 求《格子间女人》txt,急! 用笔记本做音乐.还有录音要怎么配置? 请问:两个人在一起想那个时候,男的下面总是硬不起来怎么回事呀? 是不是得什么病了?以前没有这种情况_百度问一问 [格子间女人]电视剧网上上哪能看? 哪个手机视频软件可以看格子间女人?!!! 和女朋友在一起的时候,明明很想做,可反而硬不起来,怎么办? 格子间女人哪边可以看全集呢? 用51单片机实现温湿度测控,lcd显示屏不显示 将18b20采集到的数据显示到lcd上 求烟雾报警器制作,要求有LCD液晶显示,温度显示,用单片机控制 温度低了会对lcd显示器造成影响吗?都有哪些症状?急急急! 一公里两公里的里字加个偏旁组成一个字并组词 给下列字加上偏旁或部首,并组词。(至少三个) 华为nova3i怎么连接汽车互联 我想用微商水印相机来做一些聊天 收款的截图,但是现在好像版本更新 昆明坐地铁要怎么收费? 中国工商银行是不是就是俗称的花旗银行? 佳能打印机能进纸但不能打印 中国工商银行怎么英语称lCBC!不明白怎么这样称呼:每个银行都是不一样 canon喷墨打印机mp236连续供墨为什么光走纸,不打印,在ps里只打一点,有哪位大师能帮忙解决,在此感谢了 空间直角坐标系中,点A(2,3,-1)关于xoy面的对称点的坐标是 佳能mp259的打印机。不知为什么打印的时候出现了只过纸不打印的的情况。 芥菜怎么炒的做法大全 为什么在给定了空间直角坐标系的三维空间中,所有 自原点引出的向量添加上零向量构成了一个三维线性空间R3 建立空间直角坐标系需要的条件 除了手机乐园网站 还有什么手机网站 要专业的宝软LJ什么的就不要了 空间直角坐标系法向量