Forum: Mikrocontroller und Digitale Elektronik DS1820 auf AT89C2051


von Jankey (Gast)


Lesenswert?

Sodala ich hab einen AT89C2051 mit dem DS1820 verbunden, leider hängt 
das Programm bei der
while (ReadByte()==0xff); // wait for conversion complete
Zeile im ReadTemp UP.

Hat jemand einen Plan?



sbit DQ  =  P1^3;  // connect with DS1820 Data pin

//---------------------------------------
// Delay mS function
//---------------------------------------
void DelayMs(unsigned int count)
{  // mSec Delay 11.0592 Mhz
    unsigned int i;               // Keil v7.5a
    while(count) {
        i = 115;
    while(i>0) i--;
        count--;
    }
}


//----------------------------------------
// DELAY at 11.0592MHz crystal.
// Calling the routine takes about 22us, and then
// each count takes another 17us.
// test with KEIL C51 V7.5
//----------------------------------------
void DelayUs(int us)
{
  int i;
  for (i=0; i<us; i++);
}

//----------------------------------------
// Reset DS1820
//----------------------------------------
bit ResetDS1820(void)
{
  bit presence;
  DQ = 0;     //pull DQ line low
  DelayUs(29);   // leave it low for about 490us
  DQ = 1;     // allow line to return high
  DelayUs(3);   // wait for presence 55 uS
  presence = DQ;   // get presence signal
  DelayUs(25);   // wait for end of timeslot 316 uS
  return(presence); // presence signal returned
}   // 0=presence, 1 = no part

//-----------------------------------------
// Read one bit from DS1820
//-----------------------------------------
bit ReadBit(void)
{
  unsigned char i=0;
  DQ = 0;   // pull DQ low to start timeslot
  DQ=1;
  for (i=0; i<3; i++); // delay 17 us from start of timeslot
  return(DQ); // return value of DQ line
}

//-----------------------------------------
// Write one bit to DS1820
//-----------------------------------------
void WriteBit(bit Dbit)
{
  unsigned char i=0;
    DQ=0;
  DQ = Dbit ? 1:0;
  DelayUs(5);       // delay about 39 uS
  DQ = 1;
}

//-----------------------------------------
// Read 1 byte from DS1820
//-----------------------------------------
unsigned char ReadByte(void)
{
  unsigned char i;
  unsigned char Din = 0;
  for (i=0;i<8;i++)
  {
    Din|=ReadBit()? 0x01<<i:Din;
    DelayUs(6);
  }
  return(Din);
}

//-----------------------------------------
// Write 1 byte
//-----------------------------------------
void WriteByte(unsigned char Dout)
{
  unsigned char i;
  for (i=0; i<8; i++) // writes byte, one bit at a time
  {
    WriteBit((bit)(Dout & 0x1));     // write bit in temp into
    Dout = Dout >> 1;
  }
  DelayUs(5);
}

//-----------------------------------------
// Read temperature
//-----------------------------------------
void ReadTemp(unsigned char * buff)
{
  unsigned char n;

    EA=0;  // disable all interrupt
     ResetDS1820();
    WriteByte(0xcc);  // skip ROM
    WriteByte(0x44);  // perform temperature conversion
    while (ReadByte()==0xff); // wait for conversion complete
    ResetDS1820();
    WriteByte(0xcc);  // skip ROM
    WriteByte(0xbe);  // read the result

    for (n=0; n<9; n++)     // read 9 bytes but, use only one byte
    {
       buff[n]=ReadByte();  // read DS1820
    }
  EA=1;
}

von Jankey (Gast)


Lesenswert?

keiner eine Idee?

von Dubbster (Gast)


Lesenswert?

Hey Jankey,ich verwend momentan ebenfalls den ds1820,den quellcode den 
du da angefügt hast,der stimmt,hab ich auch und bei mir zeigt er keine 
fehler ein,wo möglich hast du falsche einstellung beim keil!

Ich hab das problem,dass er mir nichts auf den display anzeigt!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.