基于51单片机的DHT11温湿度传感器
基于51单片机SHT11温湿度传感器检测程序

基于51单片机SHT11温湿度传感器检测程序(含电路图)下面是原理图:下面是SHT11与MCU连接的典型电路:下面是源代码:#include <reg52.h>#include <intrins.h>/******************************************************** 宏定义********************************************************/ #define uint unsigned int#define uchar unsigned char#define noACK 0#define ACK 1#define STATUS_REG_W 0x06#define STATUS_REG_R 0x07#define MEASURE_TEMP 0x03#define MEASURE_HUMI 0x05#define RESET 0x1eenum {TEMP,HUMI};typedef union //定义共用同类型{unsigned int i;float f;} value;/******************************************************** 位定义********************************************************/ sbit lcdrs=P2^0;sbit lcdrw=P2^1;sbit lcden=P2^2;sbit SCK = P1^0;sbit DATA = P1^1;/******************************************************** 变量定义********************************************************/ uchar table2[]="SHT11 温湿度检测";uchar table3[]="温度为:℃";uchar table4[]="湿度为:";uchar table5[]=".";uchar wendu[6];uchar shidu[6];/******************************************************** 1ms延时函数********************************************************/ void delay(int z){int x,y;for(x=z;x>0;x--)for(y=125;y>0;y--);}/******************************************************** 50us延时函数********************************************************/ void delay_50us(uint t){uint j;for(;t>0;t--)for(j=19;j>0;j--);}/******************************************************** 50ms延时函数********************************************************/ void delay_50ms(uint t){uint j;for(;t>0;t--)for(j=6245;j>0;j--);}/******************************************************** 12864液晶写指令********************************************************/ void write_12864com(uchar ){lcdrs=0;delay_50us(1);P0=;lcden=1;delay_50us(10);lcden=0;delay_50us(2);}/******************************************************** 12864液晶写数据********************************************************/ void write_dat(uchar dat){lcdrs=1;lcdrw=0;delay_50us(1);P0=dat;lcden=1;delay_50us(10);lcden=0;delay_50us(2);}/******************************************************** 12864液晶初始化********************************************************/ void init12864lcd(void){delay_50ms(2);write_12864com(0x30);delay_50us(4);write_12864com(0x30);delay_50us(4);write_12864com(0x0f);delay_50us(4);write_12864com(0x01);delay_50us(240);write_12864com(0x06);delay_50us(10);write_12864com(0x0c);delay_50us(10);}/********************************************************12864液晶显示函数********************************************************/ void display1(void){uchar i;write_12864com(0x80);for(i=0;i<18;i++){write_dat(table2[i]);delay_50us(1);}}/******************************************************** 12864液晶显示函数********************************************************/ void display2(void){uchar i;write_12864com(0x90);for(i=0;i<18;i++){write_dat(table3[i]);delay_50us(1);}}/******************************************************** 12864液晶显示函数********************************************************/ void display3(void){uchar i;write_12864com(0x88);for(i=0;i<8;i++){write_dat(table4[i]);delay_50us(1);}}/******************************************************** 12864液晶显示函数********************************************************/void displaywendu(void) {uchar i;write_12864com(0x94); for(i=0;i<3;i++){write_dat(wendu[i]); delay_50us(1);}for(i=0;i<1;i++){write_dat(table5[i]); delay_50us(1);}for(i=4;i<5;i++){write_dat(wendu[i]); delay_50us(1);}}/******************************************************** 12864液晶显示函数********************************************************/ void displayshidu(void){uchar i;write_12864com(0x8C);for(i=0;i<3;i++){write_dat(shidu[i]);delay_50us(1);}for(i=0;i<1;i++){write_dat(table5[i]);delay_50us(1);}for(i=4;i<5;i++){write_dat(shidu[i]);delay_50us(1);}}/******************************************************** SHT11写字节程序********************************************************/ char s_write_byte(unsigned char value){unsigned char i,error=0;for (i=0x80;i>0;i>>=1) //高位为1,循环右移{if (i&value) DATA=1; //和要发送的数相与,结果为发送的位else DATA=0;SCK=1;_nop_();_nop_();_nop_(); //延时3usSCK=0;}DATA=1; //释放数据线SCK=1;error=DATA; //检查应答信号,确认通讯正常_nop_();_nop_();_nop_();SCK=0;DATA=1;return error; //error=1 通讯错误}/******************************************************** SHT11读字节程序********************************************************/ char s_read_byte(unsigned char ack){unsigned char i,val=0;DATA=1; //释放数据线for(i=0x80;i>0;i>>=1) //高位为1,循环右移{SCK=1;if(DATA) val=(val|i); //读一位数据线的值SCK=0;}DATA=!ack; //如果是校验,读取完后结束通讯 ;SCK=1;_nop_();_nop_();_nop_(); //延时3usSCK=0;_nop_();_nop_();_nop_();DATA=1; //释放数据线return val;}/******************************************************** SHT11启动传输********************************************************/ void s_transstart(void){DATA=1; SCK=0; //准备_nop_();SCK=1;_nop_();DATA=0;_nop_();SCK=0;_nop_();_nop_();_nop_();SCK=1;_nop_();DATA=1;_nop_();SCK=0;}/********************************************************SHT11连接复位********************************************************/void s_connectionreset(void){unsigned char i;DATA=1; SCK=0; //准备for(i=0;i<9;i++) //DATA保持高,SCK时钟触发9次,发送启动传输,通迅即复位{SCK=1;SCK=0;}s_transstart(); //启动传输}/********************************************************SHT11温湿度检测********************************************************/char s_measure(unsigned char *p_value, unsigned char *p_checksum,unsigned charmode){unsigned error=0;unsigned int i;s_transstart(); //启动传输switch(mode) //选择发送命令{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; //等待测量结束if(DATA) error+=1; // 如果长时间数据线没有拉低,说明测量错误*(p_value) =s_read_byte(ACK); //读第一个字节,高字节(MSB)*(p_value+1)=s_read_byte(ACK); //读第二个字节,低字节(LSB)*p_checksum =s_read_byte(noACK); //read CRC校验码return error; // error=1 通讯错误}/********************************************************SHT11温湿度值标度变换及温度补偿********************************************************/void calc_sth10(float *p_humidity ,float *p_temperature){const float C1=-4.0; // 12位湿度精度修正公式const float C2=+0.0405; // 12位湿度精度修正公式const float C3=-0.0000028; // 12位湿度精度修正公式const float T1=+0.01; // 14位温度精度5V条件修正公式const float T2=+0.00008; // 14位温度精度5V条件修正公式float rh=*p_humidity; // rh: 12位湿度float t=*p_temperature; // t: 14位温度float rh_lin; // rh_lin: 湿度linear值float rh_true; // rh_true: 湿度ture值float t_C; // t_C : 温度℃t_C=t*0.01 - 40; //补偿温度rh_lin=C3*rh*rh + C2*rh + C1; //相对湿度非线性补偿rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //相对湿度对于温度依赖性补偿if(rh_true>100)rh_true=100; //湿度最大修正if(rh_true<0.1)rh_true=0.1; //湿度最小修正*p_temperature=t_C; //返回温度结果*p_humidity=rh_true; //返回湿度结果}/********************************************************主函数********************************************************/void main(void){unsigned int temp,humi;value humi_val,temp_val; //定义两个共同体,一个用于湿度,一个用于温度unsigned char error; //用于检验是否出现错误unsigned char checksum; //CRCinit12864lcd();display1();display2();display3();s_connectionreset(); //启动连接复位while(1){error=0; //初始化error=0,即没有错误error+=s_measure((unsigned char*)&temp_val.i,&checksum,TEMP); //温度测量error+=s_measure((unsigned char*)&humi_val.i,&checksum,HUMI); //湿度测量if(error!=0) s_connectionreset(); ////如果发生错误,系统复位else{humi_val.f=(float)humi_val.i; //转换为浮点数temp_val.f=(float)temp_val.i; //转换为浮点数calc_sth10(&humi_val.f,&temp_val.f); //修正相对湿度及温度temp=temp_val.f*10;humi=humi_val.f*10;wendu[0]=temp/1000+'0'; //温度百位wendu[1]=temp%1000/100+'0'; //温度十位wendu[2]=temp%100/10+'0'; //温度个位wendu[3]=0x2E; //小数点wendu[4]=temp%10+'0'; //温度小数点后第一位displaywendu();shidu[0]=humi/1000+'0'; //湿度百位shidu[1]=humi%1000/100+'0'; //湿度十位shidu[2]=humi%100/10+'0'; //湿度个位shidu[3]=0x2E; //小数点shidu[4]=humi%10+'0'; //湿度小数点后第一位displayshidu();}delay(800); //等待足够长的时间,以现行下一次转换}}相关手册资料及源码下载地址:基于51单片机SHT11温湿度传感器检测程序相关资料。
基于DHT11的温湿度控制系统设计解读

本科毕业设计(论文) 题目:基于DHT11的温湿度检测系统设计基于DHT11的温湿度检测系统设计摘要DHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器,传感器包括一个电阻式感湿元件和一个NTC测温元件,具有品质卓越、超快响应、抗干扰能力强、性价比极高等特点。
温湿度是我们日常生活中最基本的环境参数,温湿度的检测具有重要意义。
本文主要介绍该传感器的特点,并采用STC89C52单片机,LCD1602液晶显示器,及一些元器件进行组合,从而完成对温湿度的检测。
选用温湿度传感器DHT11检测环境温度和湿度,将其输出的数字信号输入单片机STC89C52,单片机采集数字信号并进行数据处理,然后由LCD1602进行显示,外加复位电路、时钟电路、键盘电路和报警电路。
本系统整体设计具有界面友好、控制灵活、硬件系统集成度高、电路简单、功能强、性能可靠、成本低等特点。
对我们的生活特别有帮助。
关键词: DHT11;单片机;温湿度;检测。
Design a System of Temperature and Humidity DetectionBased on the DHT11AbstractDHT11 temperature and humidity digital sensor is a composite temperature and humidity sensor , it outputs the already calibrated digital signal ,the sensor includes a resistance type moisture element and a NTC temperature measuring element, with excellent quality, super fast response, strong anti-interference ability, extremely high performance-price ratio.Temperature and humidity is the most basic parameters of environment,temperature and humidity detection is of great significance.This paper mainly introduces the characteristics of the sensors, and uses the STC89C52 singlechip, LCD1602 display, and some of the components are combined, so as to complete the detection of temperature and humidity. Choose DHT11 temperature and humidity sensors to detect temperature and humidity, the output of digital signal input microcontroller STC89C52 single-chip digital signal and data processing, and then by the LCD1602 display, plus the reset circuit, clock circuit, keyboard circuit and alarm circuit.The system design with friendly interface, flexible control, high hardware system integration, simple circuit, functional, reliable performance, low cost, etc. Particularly helpful to our life.Key words:DHT11; microcontroller; temperature and humidity ; detection.目录中文摘要 (1)Abstract (2)1 绪论 (1)1.1 研究的意义 (1)1.2 国内外发展现状 (1)1.3 设计的市场现状分析 (2)1.4 温湿度检测技术和存在的问题 (2)1.5 设计内容和预期结果 (3)1.5.1 主要完成内容 (3)1.5.2 本文的设计思路 (3)1.5.3 预期结果 (4)2 温湿度测量系统方案设计 (5)2.1系统总体设计 (5)2.2 系统设计原则 (5)2.3 系统方案的论证与选择 (6)2.3.1 单片机的选择 (6)2.3.2 显示器的选择 (7)2.3.3 报警系统的选择 (8)3 系统硬件设计 (9)3.1主控模块 (9)3.1.1 STC89C52的简介 (9)3.1.2 STC89C52的主要特点 (9)3.1.3 STC89C52的引脚功能 (9)3.1.4 STC89C52的控制接口 (11)3.3 时钟电路 (12)3.4 显示模块 (13)3.4.1 LCD1602简介 (13)3.4.2 LCD1602特性 (13)3.4.3 LCD1602 管脚功能 (13)3.4.4 LCD1602字符集 (14)3.4.5 LCD1602与单片机的接口 (14)3.5温湿度采集模块 (15)3.5.1 温湿度传感器简介 (15)3.5.2 串行接口(单线双向) (16)3.5.3 引脚与接口 (18)3.6 键盘模块 (18)3.7 报警模块 (19)3.7.1 蜂鸣器报警原理 (19)3.7.2 报警电路接口 (20)3.8 串口通信模块 (20)3.8.1 RS-232C简介 (20)3.8.2 MAX232简介 (21)3.9小结 (22)4 系统软件设计 (24)4.1 主程序模块程序设计 (24)4.2 1602液晶显示模块程序设计 (25)4.3 传感器模块程序设计 (26)4.4 键盘模块设计 (27)5 设计中遇到的问题及解决方法 (29)5.1 硬件问题及解决方法 (29)5.2 软件所遇问题及解决方法 (29)6 结论 (30)参考文献 (31)致谢.................................. 错误!未定义书签。
基于51单片机的温湿度检测控制系统

摘要本次设计是采用MSC-51系列单片机中的AT89S51和DHT11构成的低成本的温湿度的检测控制系统。
单片机AT89S51是一款低消耗、高性能的CMOS8位单片机,由于它强大的功能和低价位,因此在很多领域都是用它。
DHT11温湿度传感器是一款含有已校准数字输出的温湿度复合传感器,传感器包括一个电阻式感湿原件和一个NTC测温元件,该产品具有品质卓越、超快响应、抗干扰能力强、性价比极高等优点。
设计主要包括硬件电路的设计和系统软件的设计。
硬件电路主要包括单片机、温湿度传感器、显示模块、报警器以及控制设备等5部分。
其中由DHT11温湿度传感器及1602字符型液晶模块构成系统显示模块;测温湿度控制电路由温湿度传感器和预设温度值比较报警电路组成;用户根据需要预先输入预设值,当实际测量的温湿度不符合预设的温湿度标准时,发出报警信号(蜂鸣器蜂鸣),启动相应控制。
软件部分包括了主程序、显示子程序、测温湿度子程序。
关键词:AT89S51;DHT11;温湿度传感器AbstractMicrocontroller AT89S51 is a low consumption, high performance CMOS8 bit microcontroller.Because of its powerful features and low price, so it is used in many areas.DHT11 temperature and humidity sensor is a temperature and humidity combined sensor contains a calibrated digital output, the sensor consists of a resistor in the original sense of wet and a NTC temperature measurement devices.The product has many advantage,such as excellent quality, fast response, strong anti-jamming capability . This design is fromed by the AT89S51 in MSC-51 Series and DHT11 constitute which is a low-cost temperature and humidity measurement and control system. The design includes the design of hardware circuit design and system software.The hardware has Five modules.They are a microcontroller, temperature and humidity sensors, display module, alarm and control equipment. The 1602-character LCD module constitute the system display module.The temperature and humidity control circuit by the temperature and humidity sensors and preset temperature alarm circuit.According to the need of pre-enter the default value, when the actual measurement of the temperature humidity does not conform the preset temperature and humidity standards, send the alarm signal (buzzer will beep), and start the corresponding control.The software part includes the main program, the display routines, temperature and humidity subroutine.Key words:Temperature and humidity measurement;Temperature and humidity control;AT89S51 ;DHT11目录前言 (1)1.1本文研究的背景及意义 (1)1.2研究现状 (1)1.3本文研究的主要内容 (1)第2章设计任务分析及方案论证 (4)2.1设计过程及其工艺要求设计 (4)2.2设计总体方案及其论证 (4)2.3器件选定 (5)2.4AT89S51单片机 (11)2.5中断系统 (15)2.6复位电路 (16)2.7时钟电路 (17)2.8显示部分 (18)2.9本章小结 (26)第3章硬件设计 (27)3.1主控制电路和测温时控制电路 (27)3.2主要模块的电路 (28)3.3硬件实施控制 (33)3.4设备运行 (35)3.5控制设备: (36)3.6本章小结 (38)第4章软件设计 (39)4.1系统流程图 (39)4.2按键流程图 (41)4.3P ROTUES运行结果 (42)4.4本章小结 (43)结论 (44)参考文献 (45)附录 (47)前言1.1本文研究的背景及意义粮库已经被广泛的运用,是存储粮食的一个重要方式。
课程设计基于单片机的温湿度传感器

由于温度与湿度不管是从物理量本身还是在实际人们的生活中都有着密切的关系,所以温湿度一体的传感器就会相应产生。
DHT11与单片机之间能采用简单的单总线进行通信,仅仅需要一个I/O口。
操作简单,使用基亚5110二手屏幕显示DHT11传感器读出来的温度和湿度值。
关键字:AT89S52;5110液晶;DHT11传感器;单总线AbstractBecause of the temperature and the humidity from both the physical quantity itself or in the actual life of people are closely related, so the temperature and humidity sensor integrated will arise accordingly. Between DHT11 and SCM can adopt the simple single bus, only need a I\/O port. Simple operation, using the base of 5110 secondhand screen display DHT11 sensor Read out the temperature and humidity.Keywords: AT89S52; DHT11 5110 LCD; sensor; single bus引言 ------------------------------------------11.1 DHT11描述---------------------------------------------------21.2 管脚排列----------------------------------------------21.3 应用电路连接说明--------------------------------------21.4 DHT11数据结构-----------------------------------------31.5 DHT11的传输时序---------------------------------------31.5.1 DHT11开始发送数据流程--------------------------31.5.2 主机复位信号和DHT11响应信号 --------------------31.5.3 数字‘0’信号表示方法-----------------------------31.5.4 数字‘1’信号表示方法-----------------------------42、诺基亚5110液晶简介(PCD8544驱动)--------------------42.1 引脚---------------------------------------------------4 2.2 功能描述:---------------------------------------------52.2.1 地址计数器 (AC)--------------------------------52.2.2 初始化-------------------------------------------52.2.3复位的作用----------------------------------------62.2.4显示控制------------------------------------------62.2.5 串行接口时序--------------------------------------62.2.6 指令集 ------------------------------------------63、总结-------------------------------------------------74、谢辞-------------------------------------------------85、参考文献---------------------------------------------96、附录-------------------------------------------------105.1 实验总框架图---------------------------------------------10 5.2 硬件部分-------------------------------------------------105.2.1硬件原理图-------------------------------------------10 5.2.2 硬件PCB图-------------------------------------------11 5.2.3 所需元器件-------------------------------------------115.3 实验效果-------------------------------------------------11 5.4 实验软件程序---------------------------------------------12引言可靠性与卓越的长期稳定性。
DHT11温湿度传感器驱动程序 C51单片机

/**************DHT11 简单应用显示在数码管上(我的数码管是两个74HC595 不懂的可以问我)*********************************建议显示在液晶上******************/#include<reg52.h>#include<intrins.h>char T_H1,T_L1,RH_H1,RH_L1,checkdata1;char T_H2,T_L2,RH_H2,RH_L2,checkdata2;char F16T,F16RH,tshi,tge,rhshi,rhge;sbit DHT11 = P2^1;uchar bdata output;uchar location,j,i,ge,shi;uint num=0,num1,num2;uchar code segment[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77, /*共阴7段LED段码表*/0x7c,0x39,0x5e,0x79,0x71,0x76,0x73,0x3e,0x00};sbit srclk=P4^2;sbit rclk = P4^1;sbit ser = P4^4;sbit out_put= output^7;/*传感器接受数据的响应命令*/void delay(uint x);void Delay32us();void Delay22ms();void Delay500ms();void shumaguan(uchar wei,uchar duan){output = wei;for(j=0;j<8;j++) //位码{ser = out_put;srclk=0;srclk=1;srclk=0;output = _crol_(output,1);}output = duan; //段码for(j=0;j<8;j++){ser=out_put;srclk=0;srclk=1;srclk=0;output = output<<1;}rclk=0;rclk=1;rclk=0;}void shuru(){num=0;while(num<1000){shumaguan(0x01,~segment[tshi]);shumaguan(0x02,~segment[tge]);shumaguan(0x10,~segment[rhshi]);shumaguan(0x20,~segment[rhge]);shumaguan(0,~segment[19]);}}char COM(void){char i,temp,comdata;/**判断信号时0还是1**/for(i=0;i<8;i++){while(!DHT11);Delay32us();temp=0;if(DHT11){temp=1;}//当DHT11变为低电平时,开始下bit 的传送comdata = comdata<<1;comdata = comdata|temp;while(DHT11);}return comdata;}/***主机的开始信号和从机的响应信号***//***********DHT11的主函数*********************/void getDHT11(){DHT11=0;Delay22ms(); //主机拉低22msDHT11=1;Delay32us(); //总线由上拉电阻拉高主机延时20-40us //判断从机是否有低电平响应信号如不响应则跳出,响应则向下运行if(!DHT11) //T !{//判断从机是否发出80us 的低电平响应信号是否结束while(!DHT11);//判断从机是否发出80us 的高电平,如发出则进入数据接收状态while(DHT11);/*****接收数据的命令每次传送八位******/RH_H1 = COM();RH_L1 = COM();T_H1 = COM();T_L1 = COM();checkdata1 = COM();if(T_H1+T_L1+RH_H1+RH_L1==checkdata1){RH_H2 = RH_H1;RH_L2 = RH_L1;T_H2 = T_H1;T_L2 = T_L1;F16RH = RH_H2+RH_L2/1000;F16T = T_H2+T_L2/1000;tshi = F16T/10;tge = F16T%10;rhshi = F16RH/10;rhge = F16RH%10;}}}/************主函数*************/void main(){EA = 1 ;ET0= 1;TR0 = 1;TMOD = 0X01;TH0 = (65536-1000)/256;TL0 = (65536-1000)%256;while(1){DHT11=0;getDHT11();shuru();}}/**********延时子程序************************/void time1() interrupt 1 //延时20微秒{TH0 = (65536-1000)/256;TL0 = (65536-1000)%256;num=num+1;num1=num1+1;num2=num2+1;}void Delay32us() //@12.000MHz{unsigned char i;_nop_();_nop_();i = 93;while (--i);}void Delay22ms() //@12.000MHz{unsigned char i, j, k;_nop_();_nop_();i = 2;j = 1;k = 201;do{do{while (--k);} while (--j);} while (--i);}/*******************************/。
DHT11温湿度传感器要点

温湿度DHT11 51程序

while((!P2_0)&&U8FLAG++);
Delay_10us();
Delay_10us();
Delay_10us();
U8temp=0;
if(P2_0)U8temp=1;
U8FLAG=2;
//----------------------------------------------//
sbit P2_0 = P2^0 ;
//----------------------------------------------//
//----------------定义区--------------------//
//----校验 8位 == U8checkdata-----
//----调用相关子程序如下----------
//---- Delay();, Delay_10us();,COM();
//--------------------------------
void RH(void)
i--;
i--;
i--;
}
void COM(void)
{
U8 i;
for(i=0;i<8;i++)
{
U8 U8comdata;
U8 outdata[5]; //定义发送的字节数
U8 indata[5];
U8 count, count_r=0;
U8 str[5]={"RS232"};
U16 U16temp1,U16temp2;
SendData(U8 *a)
基于51单片机的粮仓温湿度检测

工 程 技 术DOI:10.16661/ki.1672-3791.2018.26.041基于51单片机的粮仓温湿度检测曾鹏 陈其军 段浩楠 高雁凤 许素安 陈锡爱(中国计量大学机电工程学院 浙江杭州 310018)摘 要:随着社会科学技术发展,越来越多的产业开始实现自动化。
近年来,互联网实时监控日渐普及,得到了广泛应用,本文设计了一套基于51单片机的粮仓温湿度检测系统。
该粮仓管理系统根据用户所期待的温湿度对环境(粮仓)进行检测,将数据通过2.4G无线网络上传并记录在数据库,并在超出阈值时报警。
关键词:粮仓管理 51单片机 温湿度检测 无线通讯 串口技术中图分类号:TP27 文献标识码:A 文章编号:1672-3791(2018)09(b)-0041-03Abstract: For the large range of temperature f luctuations and pushing tube speed and temperature control matching problems, the heating system and hydraulic in the intermediate frequency bender are analyzed, transfer function of heating system and hydraulic system are established. A double closed loop controller is developed and variable integral PID method is adopted in hydraulic system control strategy. The results show that base on a double closed loop and variable integral PID control method ensures accurately control to the temperature and high-level quality to the elbows.Key Words: Double closed loop; Variable integral PID control; Medium-frequency heating; Pipe bender粮库是粮食仓库的简称,是存储粮食的重要方式,由粮食部门统一管理,担负着国家粮食储备、地方粮食储备、粮食流通的主渠道作用,其主要任务是完成粮食的接受、保管和调运输送等粮食流通诸环节。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
w8l=w8l_temp;
check8=check8_temp;
}
}
sd=s8h+(float)s8l/256;
wd=w8h+(float)w8l/256;
}
void main()
{
while(1)
{
getdth();
display(s8h,w8h);
}
}
s8l_temp=com();
w8h_temp=com();
w8l_temp=com();
check8_temp=com();
dth=1;
if((s8h_temp+s8l_temp+w8h_temp+w8l_temp)==check8_temp) //校验
{
s8h=s8h_temp;
s8l=s8l_temp;
//if(flag==1)break;
cdata<<=1;
cdata=cdata|temp;
}
return cdata;
}
void getdth()
{
uchar i;
dth=0;
delayms(18);//18ms
dth=1;
//Delay_10us();
//Delay_10us();
//Delay_10us();
dula=1;
dula=0;
delayms(2);
P0=0xfb;
wela=1;
wela=0;
P0=table[kh+10];
dula=1;
dula=0;
delayms(2);
P0=0xf7;
wela=1;
wela=0;
P0=table[il];
dula=1;
dula=0;
delayms(2);
P0=0xef;
float sd,wd;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void delayms(uint z)
{
flag=2;
while((!dth)&&(flag++)); //等待拉高
//Delay_10us();
//Delay_10us();
//Delay_10us();
j=3;while(j--);//延时30us
temp=0;
if(dth==1)temp=1;
flag=2;
while(dth&&(flag++));//等待拉低
ih=th/100;
jh=th%100/10;
kh=th%10;
il=tl/100;
jl=tl%100/10;
kl=tl%10;
P0=0xfe;
wela=1;
wela=0;
P0=table[ih];
dula=1;
dula=0;
delayms(2);
P0=0xfd;
wela=1;
wela=0;
P0=table[jh];
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void Delay_10us()//进入函数3us
{
uchar i;//每条语句1us
i--;
i--;
i--;
i--;
i--;
i--;
}
void display(uchar th,uchar tl)
{
uchar ih=0,il=0,jh=0,jl=0,kh=0,kl=0;
wela=1;
wela=0;
P0=table[jl];
dula=1;
dula=0;
delayms(2);
P0=0xБайду номын сангаасf;
wela=1;
wela=0;
P0=table[kl];
dula=1;
dula=0;
delayms(2);
}
char com()
{
uchar i,j,temp,cdata=0;
for(i=0;i<8;i++)
//Delay_10us();
i=4;while(i--);//延时40us
dth=1;
if(dth!=1)//dth11响应
{
flag=2;while((!dth)&&(flag++)); //等待拉高
flag=2;while(dth&&(flag++));//等待读入数据
s8h_temp=com();
基于
#include<reg52.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
sbit dth=P1^0;
sbit dula=P2^6;
sbit wela=P2^7;
uchar s8h,s8h_temp,s8l,s8l_temp,w8h,w8h_temp,w8l,w8l_temp,check8,check8_temp,flag=0;