Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C51 DS18B20 read ROM CRC

Status
Not open for further replies.

sherryliu

Member level 1
Joined
Jan 17, 2011
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,535
#include <reg51.h>
#include "intrins.h"


unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

sbit DQ=P3^3;
unsigned char tempL=0;
unsigned char tempH=0;
unsigned char temp2=0;
unsigned char temp3=0;
unsigned char temp4=0;
unsigned char temp5=0;
unsigned char temp6=0;
unsigned char temp7=0;
unsigned char temp8=0;

float temperature;



void delay(unsigned int k)
{
unsigned int n=0;
while(n< k)
{
n++;
}
return;
}


void delay1(void)
{
int k;
for(k=0;k<400;k++);
}



void display(int k)
{
P2=0xfe;
P0=tab[k/1000];
delay1();

P2=0xfd;
P0=tab[k%1000/100];
delay1();

P2=0xfb;
P0=tab[k%100/10];
delay1();

P2=0xf7;
P0=tab[k%10];
delay1();

P2=0xff;
}



Init_DS18B20(void)
{
unsigned char x=0;
DQ=1;
delay(15);

DQ=0;
delay(70);


DQ=1;
delay(15);


}


ReadOneChar(void)
{
unsigned char i=0;
unsigned char dat=0;
for (i=8;i>0;i--)
{
DQ=1;
delay(1);
DQ=0;
dat>>=1;
DQ=1;
if(DQ)
dat|=0x80;
delay(4);
}
return(dat);
}



WriteOneChar(unsigned char dat)
{
unsigned char i=0;
for(i=8;i>0;i--)
{
DQ=0;
DQ=dat&0x01;
delay(5);
DQ=1;
dat>>=1;
}
delay(4);
}



ReadTemperature(void)
{

Init_DS18B20();
WriteOneChar(0xcc);
WriteOneChar(0x33);

// Init_DS18B20();
// WriteOneChar(0xcc);
// WriteOneChar(0x44);
// delay(125);
// Init_DS18B20();
// WriteOneChar(0xcc);
// WriteOneChar(0xbe);
tempL=ReadOneChar();
tempH=ReadOneChar();
temp2=ReadOneChar();
temp3=ReadOneChar();
temp4=ReadOneChar();
temp5=ReadOneChar(); )
temp6=ReadOneChar();
temp7=ReadOneChar();
temp8=ReadOneChar();
// temperature=((tempH*256)+tempL)*0.0625;
// delay(200);
// return(temperature);
}



void main()
{
float i;
while(1)
{
i=ReadTemperature();
display(i);
}
}



120130704094355.JPG120130704094516.JPG

Hi Everyone
Could you tell me how to set read ROM CRC&set Hi and Li limited? I simulated Read "temp8" value is "FF" in Keilc. Suppose I want add 8 and more DS18B20 in program,what will to change,
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top