基于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。基于ds18b20温度传感器的数字温度计设计
相关推荐
块 : 此模块是整个设计的核心部分。 设计流程如图 38所示。 在串行 通信中,无论发送或接收,都必须有时钟脉冲信号对所传送的数据进行定位和同步控制,设计中采用的时钟频率是波特率的两倍。 接收过程:初始状态是等待状态,当检测到 0 时进入检验状态,在检验状态下如果再检测到 0 则进入接收数据状态,当接收完 8 位比特数后判断是否有停止位,如果有则结束接收过程重新进入等待状态。 发送过程
UTF8 和 GB2312 两个中文编码表 ,表中数据项为 2 个字节长度的十六进制的数 ,代表一个中文编码。 两个表的长度分别为 14 890 字节( 27445)。 UTF8 编码表按数据项值从小到大排序 ,而在 GB2312 编码表中 ,与 UTF8 相同位置处为相同汉字的GB2312 码字 ,如 下图 所示。 UTF GB2312 编码表结构 ② 软件解码过程为:每次从 PDU模式
斲的斱法来改发温室内的光照强度。 调节斱法一般有以下四种:( 1)改善设斲的透光率;( 2)应用反光幕;( 3)人工补光;( 4)遮光。 二氧化碳含量的调节与控制 大气中二氧化碳平均浓度一般为 %,发幅较小。 在冬春设斲蔬菜生产中,为了保温,设斲经常处亍密闭状态,缺少内外气体交换,二氧化碳浓度发幅较大,中午设斲内由亍光合作用,二氧化碳浓度下降,接近甚至低亍补偿点
. Setting the DCEN bit enables Timer 2 to count up or down, as shown in Figure 3. In this mode, the T2EX pin controls the direction of the count. A logic 1 at T2EX makes Timer 2 count up. The timer
ode. Interrupt Registers The individual interrupt enable bits are in the IE register. Two priorities can be set for each of the six interrupt sources in the IP register. Data Memory The AT89C52
中断返回 N 外中断 1 入口 数码管显示为 0 置 R2 的值为 0 R2 的值为 0。 中断返回 东西、南北方向红灯亮 Y 7 中断处理流程 Y N Y 8 程序源代码 : ORG 0000H AJMP START ORG 0003H。 外中断 0入口 AJMP SERV0 ORG 000BH。 外中断 1入口 AJMP SERV1 ORG 0013H。 定时器中断入口 AJMP SERV2