资源描述:
《温度传感器18b20toe2rom_3读系列号C程序,在52单片机上测试通过.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/18B20序列号存于24c02E2ROM中,再从E2ROM中读取出序列号在数码管上显示。#include#include#include#defineucharunsignedchar#defineuintunsignedint;/*****************************************************************************/sbitseg1=P2^0;sbitseg2=P2^1;sbitseg3=P2^2;sbitDQ=P1^7;//ds18b20端口sfrdataled=0
2、x80;//显示数据端口/**********************************************************************/uchartemp;ucharflag_get,count,num,minute,second;ucharcodetab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x80};//7段数码管段码表共阳0....9,a,b,C,d,E,F,。ucharstr[3];/*********************
3、**************************************************/voiddelay(ucharMS);unsignedcharReadTemperature(void);voidInit_DS18B20(void);unsignedcharReadOneChar(void);voidWriteOneChar(unsignedchardat);voiddelay(unsignedinti);voidReadRom2EERom(unsignedcharaddr);externvoidWrToROM_B(unsignedcharData[],unsignedch
4、arAddress,unsignedcharNum);externvoidWrToROM_P(unsignedcharData[],unsignedcharAddress,unsignedcharNum);externvoiddisplay(unsignedcharAdrE2rom,unsignedchardelytime);//externbitWP;//之前24C02.C中WP定义为sbit,这里外部引用要定义为bitexternvoidmDelay(unsignedcharj);/******************************************************
5、******************/main(){///unsignedcharNumber2[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};//WrToROM_P(Number2,0,8);//测试用从E2OM显示数据OKReadRom2EERom(0);display(0,0xf0);//mDelay(200);display(4,0xf0);//mDelay(200);}/************************************************************************/voidtim(void)
6、interrupt1using1//中断,用于数码管扫描和温度检测间隔{TH0=0xef;//定时器重装值TL0=0xf0;num++;if(num==50){num=0;flag_get=1;//标志位有效second++;if(second>=60){second=0;minute++;}}count++;if(count==1){P2=0;dataled=str[0];}//数码管扫描if(count==2){P2=1;dataled=str[1];}if(count==3){P2=2;dataled=str[2];count=0;}}/*************************
7、************************************************************/voiddelay(unsignedinti)//延时函数{while(i--);//char?}/***************************************************************************************//