为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

郭天祥温度传感器18B20仿真Protues

2019-02-25 9页 doc 24KB 38阅读

用户头像

is_279425

暂无简介

举报
郭天祥温度传感器18B20仿真Protues 教大家一个简便连线的方法:注意看下图中ABCDEFGHIJ的一一对应,其实不需要连线,一一对应就行 #include #include #define uchar unsigned char #define uint unsigned int sbit DQ=P2^7; uchar T; uchar code table[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f}; void delay1(uint z) { uint x,y; for(x=z;x...
郭天祥温度传感器18B20仿真Protues
教大家一个简便连线的方法:注意看下图中ABCDEFGHIJ的一一对应,其实不需要连线,一一对应就行 #include #include #define uchar unsigned char #define uint unsigned int sbit DQ=P2^7; uchar T; uchar code table[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f}; void delay1(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void delay(uint N)//廷迟时间为(24+N*16)us { int i; for(i=0;i>= 1;        //右移一位 } } uchar read() { uint i, value=0; DQ=1; _nop_();            //一个机器周期:(1/11.0952(即晶振频率))*12=1.085us for (i=0; i<8; i++) { value = value>>1; //15us 之内必须读完一位 DQ = 0;          //设i=0 :value=0101 0101  >>1  得到:0010 1010 _nop_();          // 读到的DQ=1,0010 1010|1000 0000=1010 1010 _nop_();              // i=1:  value=01010101 DQ = 1;                  //读到的DQ=0,  value=01010101 _nop_();              //i=2:  value=0010 1010 _nop_();  if (DQ)          //先读最低位 value|=0x80; delay(2);        // 56us DQ=1; } return(value); } void display(uchar num) { uchar a,b; a=num/10; b=num%10; P0=table[a]; P2=0xfe; delay1(5); P2=0xff; delay1(5); P0=table[b]; P2=0xfd; delay1(5); P2=0xff; delay1(5); } uchar  read_wen_du() {    uchar HB,LB,temp; init();                                //  复位 write(0xcc);                  //  跳过ROM  即不必读64位序列号的ROM write(0x44);                  //  启动温度转换 init(); write(0xcc);                    //  跳过ROM  即不必读64位序列号的ROM write(0xbe);                    //  读命令 LB=read();                    //  低八位 1011 1010 HB=read();                    //  高八位 1111 1010 HB=HB<<4;                            //        1011 000 HB+=(LB&0XF0)>>4;    //  (LB&0xF0)=1011 0000  >>4 :0000 1011  +HB :1010 1011 temp=HB; return temp;                  //  返回温度值 } void main() { while(1) {        T=read_wen_du(); display(T); } }
/
本文档为【郭天祥温度传感器18B20仿真Protues】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索