#include <reg51.h>
#include <intrins.h>
#include <math.h> //Keil library
#include <stdio.h> //Keil library
/***************SHT10设置****************************************/
sbit DATA = P1^7; //定义通讯数据端口
sbit SCK = P1^6; //定义通讯时钟端口
typedef union
{ unsigned int i; //定义了两个共用体
float f;
} value;
enum {TEMP,HUMI}; //TEMP=0,HUMI=1
#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
/****************定义函数****************/
void s_transstart(void); //启动传输函数
void s_connectionreset(void); //连接复位函数
char s_write_byte(unsigned char value);//SHT10写函数
char s_read_byte(unsigned char ack); //SHT10读函数
char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode);
//测量温湿度函数
void calc_sht10(float *p_humidity ,float *p_temperature);//温湿度补偿
/******************** LCD1602设置****************************************/
#define LCD_DB P0
sbit LCD_RS=P2^4;
sbit LCD_RW=P2^5;
sbit LCD_E=P2^6;
/******定义函数****************/
#define uchar unsigned char
#define uint unsigned int
void LCD_init(void); //初始化函数
void LCD_write_command(uchar command); //写指令函数
void LCD_write_data(uchar dat); //写数据函数
void LCD_disp_char(uchar x,uchar y,uchar dat);//在某个屏幕位置上显示一个字符,X(0-15),y(1-2)
void LCD_disp_str(uchar x,uchar y,uchar *str); //LCD1602显示字符串函数
void delay_n10us(uint n); //延时函数
/**************************************
模块名称:LCD_init(); 功能:初始化LCD1602
***************************************/
void LCD_init(void)
{
delay_n10us(10);
LCD_write_command(0x38);//设置8位格式,2行,5x7
delay_n10us(10);
LCD_write_command(0x0c);//整体显示,关光标,不闪烁
delay_n10us(10);
LCD_write_command(0x06);//设定输入方式,增量不移位
delay_n10us(10);
LCD_write_command(0x01);//清除屏幕显示
delay_n10us(100); //延时清屏,延时函数,延时约n个10us
}
/*****************************************
模块名称:LCD_write_command();
功 能:LCD1602写指令函数
******************************************/
void LCD_write_command(uchar dat)
{
delay_n10us(10);
LCD_RS=0; //指令
LCD_RW=0; //写入
LCD_E=1; //允许
LCD_DB=dat;
delay_n10us(10); // 用for循环1次就能完成普通写指令。
LCD_E=0;
delay_n10us(10); // 用for循环1次就能完成普通写指令。
}
/****************************************
模块名称:LCD_write_data();
功 能:LCD1602写数据函数
******************************************/
void LCD_write_data(uchar dat)
{
delay_n10us(10);
LCD_RS=1; //数据
LCD_RW=0; //写入
LCD_E=1; //允许
LCD_DB=dat;
delay_n10us(10);
LCD_E=0;
delay_n10us(10);
}
/*******************************************************
模块名称:LCD_disp_char();
功 能:LCD1602显示一个字符函数,在某个屏幕位置上显示一个字符,X(0-15),y(1-2)。
*********************************************************/
void LCD_disp_char(uchar x,uchar y,uchar dat)
{
uchar address;
if(y==1)
address=0x80+x;
else
address=0xc0+x;
LCD_write_command(address);
LCD_write_data(dat);
}
/***************************************************
模块名称:LCD_disp_str();
功 能:LCD1602显示字符串函数,在某个屏幕起始位置{X(0-15),y(1-2)}上显示字符串。
***************************************************/
void LCD_disp_str(uchar x,uchar y,uchar *str)
{ uchar address;
if(y==1) address=0x80+x;
else
address=0xc0+x; LCD_write_command(address);
while(*str!='\0')
{ LCD_write_data(*str); str++; } }
/****************************************
模块名称:delay_n10us();
功 能:延时函数,延时约n个10us
*****************************************/
void delay_n10us(uint n) //延时n个10us-12M晶振
{
uint i;
for(i=n;i>0;i--)
{
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
}
}
/************************************************
模块名称:s_transstart();
功 能:启动传输函数
*************************************************/
void s_transstart(void)
// generates a transmission start
// _____ ________
// DATA: |_______|
// ___ ___
// SCK : ___| |___| |______
{
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;
}
/**********************************************
模块名称:s_connectionreset(); 功能:连接复位函数
************************************************/
void s_connectionreset(void)
// communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart
// _____________________________________________________ ________
// DATA: |_______|
// _ _ _ _ _ _ _ _ _ ___ ___
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______
{
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
}
/**********************************************
模块名称:s_write_byte(); 功能:SHT10写函数
**********************************************/
char s_write_byte(unsigned char value)
// writes a byte on the Sensibus and checks the acknowledge
{
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. 3 us
SCK=0;
}
DATA=1; //release DATA-line
SCK=1; //clk #9 for ack
error=DATA; //DATA在第9个上升沿将被SHT10下拉为低电平。
_nop_();_nop_();_nop_();
SCK=0;
DATA=1; //release DATA-line
return error; //返回:0成功,1失败
}
/**********************************************
模块名称:s_read_byte(); 功能:SHT10读函数
***********************************************/
char s_read_byte(unsigned char ack)
// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
{
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
_nop_();_nop_();_nop_(); //pulswith approx. 3 us
SCK=0;
}
if(ack==1)DATA=0; //in case of "ack==1" pull down DATA-Line
else DATA=1; //如果是校验(ack==0),读取完后结束通讯
_nop_();_nop_();_nop_(); //pulswith approx. 3 us
SCK=1; //clk #9 for ack
_nop_();_nop_();_nop_(); //pulswith approx. 3 us
SCK=0;
_nop_();_nop_();_nop_(); //pulswith approx. 3 us
DATA=1; //release DATA-line
return val;
}
/************************************************
模块名称:s_measure(); 功能:测量温湿度函数
******************************************
没有合适的资源?快使用搜索试试~ 我知道了~
tem.rar_湿度控制
共126个文件
bak:16个
lst:15个
c:14个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 163 浏览量
2022-09-23
01:07:25
上传
评论
收藏 341KB RAR 举报
温馨提示
C语言单片机控制实现温度、湿度控制系统。
资源推荐
资源详情
资源评论
收起资源包目录
tem.rar_湿度控制 (126个子文件)
STARTUP.A51 6KB
总程序_uvopt.bak 57KB
sht10_uvopt.bak 56KB
液晶显示_uvopt.bak 55KB
温度_uvopt.bak 55KB
按键_uvopt.bak 54KB
ceshi_uvopt.bak 54KB
总程序_uvproj.bak 13KB
ceshi_uvproj.bak 13KB
wangshang_uvproj.bak 0B
wendu_uvproj.bak 0B
液晶显示_uvproj.bak 0B
温度_uvproj.bak 0B
按键_uvproj.bak 0B
sht10_uvproj.bak 0B
wendu1_uvproj.bak 0B
wendu2_uvproj.bak 0B
wendu1.c 13KB
wendu2.c 12KB
wangshang.c 10KB
总程序_温度.c 9KB
wendu.c 8KB
温度.c 8KB
sht10.c 6KB
按键.c 6KB
CH451C54.C 5KB
总程序.c 4KB
液晶显示.c 4KB
ceshi.c 3KB
main.c 3KB
ds1602.c 2KB
ceshi 10KB
Last Loaded 温度仿真.DBK 74KB
温度仿真.DSN 73KB
tou.h 1KB
touwenjian.h 86B
wendu1.hex 8KB
sht10.hex 7KB
wendu2.hex 7KB
ceshi.hex 4KB
ExtDll.iex 19B
sht10.lnp 86B
总程序.lnp 80B
液晶显示.lnp 64B
wendu2.lnp 60B
wendu1.lnp 60B
wendu.lnp 58B
ceshi.lnp 58B
温度.lnp 56B
按键.lnp 56B
wendu1.LST 19KB
wangshang.LST 19KB
wendu2.LST 19KB
STARTUP.LST 14KB
总程序_温度.LST 14KB
温度.LST 12KB
wendu.LST 12KB
sht10.LST 11KB
按键.LST 10KB
总程序.LST 9KB
CH451C54.LST 8KB
液晶显示.LST 8KB
ceshi.LST 7KB
main.LST 6KB
ds1602.LST 4KB
总程序.M51 28KB
sht10.M51 25KB
wendu1.M51 22KB
wendu2.M51 21KB
wendu.M51 17KB
液晶显示.M51 15KB
ceshi.M51 14KB
温度.M51 14KB
按键.M51 10KB
wendu1.OBJ 22KB
wendu2.OBJ 20KB
wendu.OBJ 14KB
总程序_温度.OBJ 13KB
sht10.OBJ 13KB
总程序.OBJ 13KB
液晶显示.OBJ 12KB
ceshi.OBJ 10KB
温度.OBJ 9KB
按键.OBJ 8KB
main.OBJ 7KB
ds1602.OBJ 7KB
STARTUP.OBJ 749B
按键.plg 6KB
wangshang.plg 1KB
wendu1.plg 1KB
wendu2.plg 906B
wendu.plg 704B
液晶显示.plg 242B
总程序.plg 240B
ceshi.plg 239B
sht10.plg 161B
温度.plg 160B
温度仿真.PWI 768B
sht10 25KB
总程序.uvopt 57KB
共 126 条
- 1
- 2
资源评论
局外狗
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功