完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
本帖最后由 lamp波波 于 2016-8-7 13:08 编辑
#include #define uchar unsigned char #define uint unsigned int ***it DS=P2^4; ***it dot=P0^7; //小数点 uint temp; // variable of temperature uchar flag1; // sign of the result positive or negative code unsigned char tab[]={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; uint ad=0, ads;//数字信号变量 uchar StrTab[3]; void delay(uint count) //delay { uint i; while(count) { i=200; while(i>0) i--; count--; } } void dsreset(void) //send reset and initialization command { uint i; DS=0; i=103; while(i>0)i--; DS=1; i=4; while(i>0)i--; } bit tmpreadbit(void) //read a bit { uint i; bit dat; DS=0;i++; //i++ for delay DS=1;i++;i++; dat=DS; i=8;while(i>0)i--; return (dat); } uchar tmpread(void) //read a byte date { uchar i,j,dat; dat=0; for(i=1;i<=8;i++) { j=tmpreadbit(); dat=(j<<7)|(dat>>1); //????????????,?????????DAT? } return(dat); } void tmpwritebyte(uchar dat) //write a byte to ds18b20 { uint i; uchar j; bit testb; for(j=1;j<=8;j++) { testb=dat&0x01; dat=dat>>1; if(testb) //write 1 { DS=0; i++;i++; DS=1; i=8;while(i>0)i--; } else { DS=0; //write 0 i=8;while(i>0)i--; DS=1; i++;i++; } } } void tmpchange(void) //DS18B20 begin change { dsreset(); delay(1); tmpwritebyte(0xcc); // address all drivers on bus tmpwritebyte(0x44); // initiates a single temperature conversion } uint tmp() //get the temperature { float tt; uchar a,b; dsreset(); delay(1); tmpwritebyte(0xcc); tmpwritebyte(0xbe); a=tmpread(); b=tmpread(); temp=b; temp<<=8; //two byte compose a int variable temp=temp|a; tt=temp*0.0625; temp=tt*10+0.5; return temp; } void display(uint temp) { uint i; ad = temp; ads=ad/100; StrTab[2]=tab[ads]; ad=ad%100; ads=ad/10; StrTab[1]=tab[ads]; ad=ad%10; ads=ad; StrTab[0]=tab[ads]; for(i=0; i<100; i++) { P2=0x01; P0=StrTab[2]; dot=1; delay(5); P2=0x00; P2=0x02; P0=StrTab[1]; delay(5); P2=0x00; P2=0x04; P0=StrTab[0]; dot=1; delay(5); P2=0x00; } } void main() { uchar a; while(1) { tmpchange(); for(a=10;a>0;a--) { display(tmp()); } } }
|
|
相关推荐
5个回答
|
|
#include
#define uchar unsigned char #define uint unsigned int ***it DS=P2^4; ***it dot=P0^7; //小数点 uint temp; // variable of temperature uchar flag1; // sign of the result positive or negative code unsigned char tab[]={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; uint ad=0, ads;//数字信号变量 uchar StrTab[3]; void delay(uint count) //delay { uint i; while(count) { i=200; while(i>0) i--; count--; } } void dsreset(void) //send reset and initialization command { uint i; DS=0; i=103; while(i>0)i--; DS=1; i=4; while(i>0)i--; } bit tmpreadbit(void) //read a bit { uint i; bit dat; DS=0;i++; //i++ for delay DS=1;i++;i++; dat=DS; i=8;while(i>0)i--; return (dat); } uchar tmpread(void) //read a byte date { uchar i,j,dat; dat=0; for(i=1;i<=8;i++) { j=tmpreadbit(); dat=(j<<7)|(dat>>1); //????????????,?????????DAT? } return(dat); } void tmpwritebyte(uchar dat) //write a byte to ds18b20 { uint i; uchar j; bit testb; for(j=1;j<=8;j++) { testb=dat&0x01; dat=dat>>1; if(testb) //write 1 { DS=0; i++;i++; DS=1; i=8;while(i>0)i--; } else { DS=0; //write 0 i=8;while(i>0)i--; DS=1; i++;i++; } } } void tmpchange(void) //DS18B20 begin change { dsreset(); delay(1); tmpwritebyte(0xcc); // address all drivers on bus tmpwritebyte(0x44); // initiates a single temperature conversion } uint tmp() //get the temperature { float tt; uchar a,b; dsreset(); delay(1); tmpwritebyte(0xcc); tmpwritebyte(0xbe); a=tmpread(); b=tmpread(); temp=b; temp<<=8; //two byte compose a int variable temp=temp|a; tt=temp*0.0625; temp=tt*10+0.5; return temp; } void display(uint temp) { uint i; ad = temp; ads=ad/100; StrTab[2]=tab[ads]; ad=ad%100; ads=ad/10; StrTab[1]=tab[ads]; ad=ad%10; ads=ad; StrTab[0]=tab[ads]; for(i=0; i<100; i++) { P2=0x01; P0=StrTab[2]; dot=1; delay(5); P2=0x00; P2=0x02; P0=StrTab[1]; delay(5); P2=0x00; P2=0x04; P0=StrTab[0]; dot=1; delay(5); P2=0x00; } } void main() { uchar a; while(1) { tmpchange(); for(a=10;a>0;a--) { display(tmp()); } } } |
|
|
|
#include
#define uchar unsigned char #define uint unsigned int ***it DS=P2^4; ***it dot=P0^7; //小数点 uint temp; // variable of temperature uchar flag1; // sign of the result positive or negative code unsigned char tab[]={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; uint ad=0, ads;//数字信号变量 uchar StrTab[3]; void delay(uint count) //delay { uint i; while(count) { i=200; while(i>0) i--; count--; } } void dsreset(void) //send reset and initialization command { uint i; DS=0; i=103; while(i>0)i--; DS=1; i=4; while(i>0)i--; } bit tmpreadbit(void) //read a bit { uint i; bit dat; DS=0;i++; //i++ for delay DS=1;i++;i++; dat=DS; i=8;while(i>0)i--; return (dat); } uchar tmpread(void) //read a byte date { uchar i,j,dat; dat=0; for(i=1;i<=8;i++) { j=tmpreadbit(); dat=(j<<7)|(dat>>1); //????????????,?????????DAT? } return(dat); } void tmpwritebyte(uchar dat) //write a byte to ds18b20 { uint i; uchar j; bit testb; for(j=1;j<=8;j++) { testb=dat&0x01; dat=dat>>1; if(testb) //write 1 { DS=0; i++;i++; DS=1; i=8;while(i>0)i--; } else { DS=0; //write 0 i=8;while(i>0)i--; DS=1; i++;i++; } } } void tmpchange(void) //DS18B20 begin change { dsreset(); delay(1); tmpwritebyte(0xcc); // address all drivers on bus tmpwritebyte(0x44); // initiates a single temperature conversion } uint tmp() //get the temperature { float tt; uchar a,b; dsreset(); delay(1); tmpwritebyte(0xcc); tmpwritebyte(0xbe); a=tmpread(); b=tmpread(); temp=b; temp<<=8; //two byte compose a int variable temp=temp|a; tt=temp*0.0625; temp=tt*10+0.5; return temp; } void display(uint temp) { uint i; ad = temp; ads=ad/100; StrTab[2]=tab[ads]; ad=ad%100; ads=ad/10; StrTab[1]=tab[ads]; ad=ad%10; ads=ad; StrTab[0]=tab[ads]; for(i=0; i<100; i++) { P2=0x01; P0=StrTab[2]; dot=1; delay(5); P2=0x00; P2=0x02; P0=StrTab[1]; delay(5); P2=0x00; P2=0x04; P0=StrTab[0]; dot=1; delay(5); P2=0x00; } } void main() { uchar a; while(1) { tmpchange(); for(a=10;a>0;a--) { display(tmp()); } } } |
|
|
|
用的是AT89S51单片机
|
|
|
|
用的是51单片机,楼主有做好的程序吗,我毕设就是这个
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-使用AHT20进行环境监测之AHT20传感器介绍
828 浏览 0 评论
824 浏览 0 评论
861 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
836 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
1292 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11824 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 21:49 , Processed in 0.734701 second(s), Total 82, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号