ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:63.46KB ,
资源ID:5429556      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5429556.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(单片机多机多点温控系统从机模块.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

单片机多机多点温控系统从机模块.docx

1、单片机多机多点温控系统从机模块/DS从机程序#include #include #define uchar unsigned char#define uint unsigned int#define SLAVE 0x01#define BN 6sbit LCD_RS = P25; /*定义LCD控制端口*/ sbit LCD_RW = P26;sbit LCD_EN = P27;sbit DS1=P10;sbit DS2=P11;sbit key3=P35;sbit tem=P33;sbit win=P34;sbit key1=P36;sbit key2=P37;uint temp1,temp

2、2,tempH,tempL; / variable of temperatureuchar flag1,aa,we;uchar A1,A2,A3,A4,B1,B2,B3,B4; / sign of the result positive or negativeuchar dis116=76,45,84,0,0,.,0,32,32,72,45,84,0,0,.,0;uchar dis216=48,49,32,0,0,.,0,32,32,48,50,32,0,0,.,0;uchar code tab = 0,1,2,3,4,5,6,7,8,9;uchar trbuf6;bit tready;bit

3、 rready;void str(void);void sre(void); void delay(int ms) int i; while(ms-) for(i = 0; i0) i-; count-; */功能:串口初始化,波特率9600,方式1/void Init(void)TMOD=0x20; TL1=0xfd; TH1=0xfd; PCON=0x00; TR1=1; SCON=0xf0; ES=1; EA=1;void dsreset(uchar DS) /send reset and initialization command 18B20复位,初始化函数 uint i; if(D

4、S=1) DS1=0; i=103; while(i0)i-; DS1=1; i=4; while(i0)i-; if(DS=2) DS2=0; i=103; while(i0)i-; DS2=1; i=4; while(i0)i-; bit tmpreadbit(uchar DS) /read a bit 读DS2 1位数据函数 uint i; bit dat; if(DS=1) DS1=0;i+; /i+ for delay DS1=1;i+;i+; dat=DS1; i=8;while(i0)i-; if(DS=2) DS2=0;i+; /i+ for delay DS2=1;i+;i+

5、; dat=DS2; i=8;while(i0)i-; return (dat);uchar tmpread(uchar DS) /read a byte date 读1字节函数 uchar i,j,dat; dat=0; if(DS=1) for(i=1;i=8;i+) j=tmpreadbit(1); dat=(j1); /读出的数据最低位在最前面,这样刚好一个字节在DAT里 if(DS=2) for(i=1;i=8;i+) j=tmpreadbit(2); dat=(j1); /读出的数据最低位在最前面,这样刚好一个字节在DAT里 return(dat);void tmpwritebyt

6、e(uchar dat,uchar DS) /write a byte to ds18b20 向1820写一个字节数据函数 uint i; uchar j; bit testb; for(j=1;j1; if(DS=1) if(testb) /write 1 DS1=0; i+;i+; DS1=1; i=8;while(i0)i-; else DS1=0; /write 0 i=8;while(i0)i-; DS1=1; i+;i+; if(DS=2) if(testb) /write 1 DS2=0; i+;i+; DS2=1; i=8;while(i0)i-; else DS2=0; /w

7、rite 0 i=8;while(i0)i-; DS2=1; i+;i+; void tmpchange(uchar DS) /DS18B20 begin change 开始获取数据并转换 if(DS=1) dsreset(1); delay(1); tmpwritebyte(0xcc,1); / address all drivers on bus 写跳过读ROM指令 tmpwritebyte(0x44,1); / initiates a single temperature conversion 写温度转换指令 if(DS=2) dsreset(2); delay(1); tmpwrite

8、byte(0xcc,2); / address all drivers on bus 写跳过读ROM指令 tmpwritebyte(0x44,2); / initiates a single temperature conversion 写温度转换指令 uint tmp1(void) /get the temperature 读取寄存器中存储的温度数据 float tt; uchar a,b; dsreset(1); delay(1); tmpwritebyte(0xcc,1); tmpwritebyte(0xbe,1); a=tmpread(1); /读低8位 b=tmpread(1); /

9、读高8位 temp1=b; temp1=8; /two byte compose a int variable 两个字节组合为1个字 temp1=temp1|a; tt=temp1*0.0625; /温度在寄存器中是12位,分辨率是0.0625 temp1=tt*10+0.5; /乘10表示小数点后只取1位,加0.5是四折五入 temp1=temp1; /误差补偿 return temp1;uint tmp2( void) /get the temperature 读取寄存器中存储的温度数据 float tt; uchar a,b; dsreset(2); delay(1); tmpwrite

10、byte(0xcc,2); tmpwritebyte(0xbe,2); a=tmpread(2); /读低8位 b=tmpread(2); /读高8位 temp2=b; temp20;a-) for(b=60;b0;b-); uchar display(uint temp1,uint temp2) /显示程序 uchar i; A1=temp1/100; A2=temp1%100/10; A3=temp1%100%10; B1=temp2/100; B2=temp2%100/10; B3=temp2%100%10; trbuf0=A1; trbuf1=A2; trbuf2=A3; trbuf3

11、=B1; trbuf4=B2; trbuf5=B3; dis13=tabtempL*10/100; dis14=tabtempL*10%100/10; dis16=tabtempL*10%100%10; dis112=tabtempH*10/100; dis113=tabtempH*10%100/10; dis115=tabtempH*10%100%10; dis23=tabA1; dis24=tabA2; dis26=tabA3; dis212=tabB1; dis213=tabB2; dis215=tabB3; delay(1); lcd_pos(0); /设置显示位置为 delay(2)

12、;/ 第一行的第1个字符 for(i=0;i16;i+) lcd_wdat(dis1i); delay(2); lcd_pos(0x40); delay(2); for(i=0;i16;i+) lcd_wdat(dis2i); return (A1,A2,A3,B1,B2,B3); void TemC() if(temp1/10=tempL|temp2/10=tempH|temp2/10=tempH) win=0; else win=1; uchar chan() if(key1=0) tempL+; while(key1=0); if(tempL35) tempL=0; if(key2=0)

13、 tempH+; while(key2=0); if(tempH35) tempH=0; return (tempH,tempL); /*/void main() /uchar a; /uchar i; delay(10); lcd_init(); Init(); tempH=35; tempL=15; while(1) tmpchange(1); tmpchange(2); tmp1(); tmp2(); chan(); TemC(); display(temp1,temp2); tready=1; rready=1; void ssio(void)interrupt 4 uchar a;

14、RI=0; ES=0; if(SBUF!=SLAVE) ES=1; goto reti; SM2=0; SBUF=SLAVE; while(TI!=1); TI=0; while(RI!=1); RI=0; if(RB8=1) SM2=1; ES=1; goto reti; a=SBUF; if(a=0x02) if(tready=1) SBUF=0x02; else SBUF=0x00; while(TI!=1); TI=0; str(); goto reti; else SBUF=0x08; while(TI!=1); TI=0; SM2=1; ES=1; reti:RI=0; SM2=1; ES=1; void str(void) uchar i; tready=0; while(1) tmpchange(1); tmpchange(2); tmp1(); tmp2(); chan(); TemC(); display(temp1,temp2); for(i=0;iBN;i+) SBUF=trbufi; while(TI!=1); TI=0; while(RI!=1); RI=0; if(RB8=1)goto loop; loop:SM2=1; ES=1;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1