×

PIC单片机对数字温度传感器的控制设计资料下载

消耗积分:2 | 格式:pdf | 大小:75.51KB | 2021-04-28

分享资料个

#include#define uchar unsigned char#define uint unsigned int#define DQ RC1#define DQ_HIGH() TRISC1=1#define DQ_LOW() TRISC1=0;DQ=0__CONFIG(0x3B31);const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};const uchar table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};uinttemper;uchar a1,a2,a3,a4;void delay(uint x);void delayus(uint,uchar);void init();void disp(uchar num1,uchar num2,uchar num3,uchar num4);void write_byte(uchar date);uchar read_byte();void get_tem();void main(){init();while(1){/*delayus(0,0);//20delayus(1,1);//30delayus(2,2);//45delayus(4,4);//70delayus(70,30);//750delayus(50,10);//500*///uchar num;get_tem();//for(num=20;num》0;num--)//disp(a1,a2,a3,a4);}}void reset(){uchar st=1;DQ_HIGH();NOP();NOP();while(st){DQ_LOW();delayus(70,30);DQ_HIGH();delayus(4,4);if(DQ==1)st=1;elsest=0;delayus(50,10);}}void write_byte(uchar date){uchar i,temp;DQ_HIGH();NOP();NOP();for(i=8;i》0;i--){temp=date&0x01;//01010101DQ_LOW();delayus(0,0);if(temp==1)DQ_HIGH();delayus(2,2);DQ_HIGH();date=date》》1;//00101010}}uchar read_byte(){uchar i,date;static bit j;for(i=8;i》0;i--){date=date》》1;DQ_HIGH();NOP();NOP();DQ_LOW();NOP();NOP();NOP();NOP();NOP();NOP();DQ_HIGH();NOP();NOP();NOP();NOP();j=DQ;if(j==1)date=date|0x80;//1000 0000delayus(1,1);}return (date);}void get_tem(){uchar tem1,tem2,num;float aaa;reset(); //复位write_byte(0xCC);//跳过ROMwrite_byte(0x44);//温度转换for(num=100;num》0;num--)

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !