Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

ds1820-examples for c51 needed !

Status
Not open for further replies.

onde

Junior Member level 1
Joined
Nov 29, 2002
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
88
ds1820 c51

Hello,

does anybody know a link or have same examples of programming the ds1820 in c51 ???
thanks in advance,
onde
 

dainis

Advanced Member level 4
Joined
May 15, 2001
Messages
1,126
Helped
53
Reputation
106
Reaction score
9
Trophy points
1,318
Activity points
9,271
f*p://f*p.wickenhaeuser.de/source/ds1820uc.zip
 

zk543g

Member level 2
Joined
Dec 10, 2002
Messages
49
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
korea
Activity points
226
//DS1820 C51

//sbit DQ = p2^1;

typedef unsigned char byte;
typedef unsigned int word;

void delay(word useconds)
{
for(;useconds>0;useconds--);
}

byte ow_reset(void)
{
byte presence;
DQ = 0; //pull DQ line low
delay(29); // leave it low for 480us
DQ = 1; // allow line to return high
delay(3); // wait for presence
presence = DQ; // get presence signal
delay(25); // wait for end of timeslot
return(presence); // presence signal returned
} // 0=presence, 1 = no part

byte read_byte(void)
{
byte i;
byte value = 0;
for (i=8;i>0;i--)
{
value>>=1;
DQ = 0; // pull DQ low to start timeslot
DQ = 1; // then return high
delay(1); //for (i=0; i<3; i++);
if(DQ)value|=0x80;
delay(6); // wait for rest of timeslot
}
return(value);
}


void write_byte(char val)
{
byte i;
for (i=8; i>0; i--) // writes byte, one bit at a time
{
DQ = 0; // pull DQ low to start timeslot
DQ = val&0x01;
delay(5); // hold value for remainder of timeslot
DQ = 1;
val=val/2;
}
delay(5);
}


char Read_Temperature(void)
{
union{
byte c[2];
int x;
}temp;

ow_reset();
write_byte(0xCC); // Skip ROM
write_byte(0xBE); // Read Scratch Pad
temp.c[1]=read_byte();
temp.c[0]=read_byte();
ow_reset();
write_byte(0xCC); //Skip ROM
write_byte(0x44); // Start Conversion
return temp.x/2;
}
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top