基于ds18b20温度传感器的数字温度计设计内容摘要:

( RXD)交叉连接,二者的地线( GND)直接相连,其它信号线如握手信号线均不用,而采用软件握手。 但由于 RS232C 的逻辑电对地是对称的,与 TTL、 MOS 逻辑电平完全不同,逻辑 0 电平规定为 +5~ +15V 之间,逻辑1 是电平为 5~ 15V 之间,因此利用 232 芯片进行电平转换,电路连接如图 11。 图 11 RS232C 通信连接电路 电源模块 本方案采用锂离子手机充电电池和配套的锂电池充电器作为电源,手机用的电池电压充电电压是 图 13 程序流程图 DS18B20 模块程序设计 程序流程 DS18B20 模块程序主要完成 DS18B20 的初始化和温度的读去操作,程序流程如图 14 所示。 程序源码 uchar DataH。 uchar DataL。 unsigned long Data。 void Delay uchar us while us。 bit init_18b20 //1820 初始化 uchar n 0。 bit flag 0。 DQ 1。 _nop_。 DQ 0。 Delay 255。 Delay 20。 //550us DQ 1。 Delay 55。 if DQ 0 flag 1。 //detect 1820 success! else flag 0。 //detect 1820 fail! Delay 100。 DQ 1。 return flag。 void write1820_byte uchar wr //单字节写入 uchar i。 for i 0。 i 8。 i++ DQ 0。 _nop_。 DQ wramp。 0x01。 Delay 20。 //45us DQ 1。 wr 1。 uchar read1820_byte void //读取单字节 uchar i,u 0。 for i 0。 i 8。 i++ DQ 0。 u 1。 DQ 1。 if DQ 1 u| 0x80。 Delay 18。 //40us return u。 //对从 DS18B20 读出的温度值( ddh, ddl)进行处理,送显示缓冲 区 void DataCoding unsigned char ddH , unsigned char ddL Data ddH * 256 + ddL。 Data Data * 625。 void Get_temperarue void if init_18b20 write1820_byte 0xcc。 //skip rom write1820_byte 0x44。 //temp convert Delay 35。 if init_18b20 write1820_byte 0xcc。 //skip rom write1820_byte 0xbe。 //read temp DataL read1820_byte。 DataH read1820_byte amp。 0x0f。 DataCoding DataH, DataL。 图 14 DS18B20 模块程序流程图 HS1602 驱动程序设计 程序流程 HS1602 液晶驱动主要完成 HS1602 的初始化以及字符和字符串的显示,程序流程如图 15 所示。 图 15 HS1602 液晶驱动程序流程图 程序源码 //液晶初始化 void lcd_init void delay_nms 15。 lcd_write_mand 0x38,0。 //显示模式设置三次 此时不管 lcd 空闲与否 delay_nms 5。 lcd_write_mand 0x38,0。 delay_nms 5。 lcd_write_mand 0x38,0。 delay_nms 5。 lcd_write_mand 0x38,1。 //显示模式设置 从此之后均需 lcd 空闲 lcd_write_mand 0x08,1。 //显示关闭 lcd_write_mand 0x01,1。 //显示清屏 lcd_write_mand 0x06,1。 //显示光标移动设置 lcd_write_mand 0x0c,1。 //显示开及光标设置 //写指令函数 : E 高脉冲 RS 0 RW 0 // mand 为指令, wait_en 指定是否要检测 LCD 忙信号 void lcd_write_mand unsigned char mand,unsigned char wait_en uchar xdata *dig。 if wait_en wait_enable。 //若 wait_en 为 1,则要检测 LCD 忙信号,等待其空闲 dig amp。 DIGPORT。 *dig mand。 //写数据函数 : E 高脉冲 RS 1 RW 0 void lcd_write_data unsigned char char_data uchar xdata *dig。 dig amp。 DIGPORT1。 wait_enable。 //等待 LCD 空闲 *dig char_data。 //正常读写操作之前必须检测 LCD 控制器状态 //E 1 RS 0 RW 1。 DB7: 0 LCD 控制器空闲, 1 LCD 控制器忙。 //检测忙信号 ,等待 LCD 空闲函数 void wait_enable void lcd_RS 0。 //RS 0 lcd_RW 1。 //RW 1 _nop_。 RD 0。 //E 1 lcd_E 1。 while busy。 //等待 LCD_DB7 为 0 RD 1。 //E 0 lcd_E 0。 //指定位置显示一个字符 :第一行位置 0~15,第二行 16~31 //显示一个字符函数 //参数 position 指定位置 0~31,char_data 为要显示的字符 void display_a_char unsigned char position,unsigned char char_data unsigned char position_tem。 if position 0x10 position_tem position+0xb0。 else position_tem position+0x80。 lcd_write_mand position_tem,1。 lcd_write_data char_data。 //指定一行显示连续字符串 :0 显示在第一行 ,1 显示在第二行 //字符串不能长于 16 个字符 //显示一行连续字符串函数 //参数 col 指定 行 ,*ptr 指字符串数组的首指针 void display_a_string unsigned char col,unsigned char *ptr unsigned char col_tem,i。 //若 col 为 1 即在 LCD 第二行显示字符串 ,先把 col 左移 4 位 //使显示字符的首位置改到第二行首位 ,即位置 16 col_tem col 4。 for i 0。 i 16。 i++ display_a_char col_tem++,* ptr+i。 AT24C08 存储模块程 序设计 程序流程 图 16 AT24C08。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。