Home     Projects     Micro     Tools     Delphi     Developer     Blog     Site map
HOME  
 
     

MCS-51 | PIC


Connecting DS1820 with AT89S52

DS1820 is a temperture sensor which is small sensor.The output of sensor converted to digital that easy connecting with microcontroller.



SOME FEATURES OF DS1820
  • Unique 1-Wire® interface requires only one port pin for communication
  • Multidrop capability simplifies distributed temperature sensing applications
  • Requires no external components
  • Measures temperatures from –55°C to +125°C (–67°F to +257°F)
  • ±0.5C accuracy from –10°C to +85°C
  • 9-bit thermometer resolution
 


Software

Software for this example program with KEIL C51 V7.5.Becuase DS1820 is the time cirtical devices so for accurately control the special timing requirements of the 1-WireTM interface.This means we must create the exact delay function which use for all read and write control.In KEIL C51 we can create delay function
like this.
//-----------------------------------------------
// DELAY at 11.059MHz crystal.
// Calling the routine takes about 21us, and then
// each count takes another 16us.
// Test with KEIL C51 V7.5
//-----------------------------------------------
void DelayUs(int us)
{
	int i;
	for (i=0; i < us; i++);
}

For full source code download at the buttom of this page.The example will read data from DS1820 then send to Hyper terminal for display temperature.

Here is the main program of this example.The temperature result will displayed on hyper terminal program which is come with Windows.
//---------------------------------------
// Example read and write DS1820
// for AT89S52
// KEIL C51 v7.5
// www.sixca.com
//---------------------------------------
#include<reg8252.h>
#include<stdio.h>
#include<ds1820.h>
#include<serial.h>

unsigned char MyTemp[9];

//---------------------------------------
// Main program
//---------------------------------------
void main(void)
{
     unsigned char tp,tpd,i;
     InitSerial();  		// Initialize serial port
     while(1)
     {
        ReadTemp(&MyTemp[0]);        
        tp  = MyTemp[0] >> 1;
        tpd = ((MyTemp[0] >> 1)&1) ? 5:0;		
        putchar(0x0C);  // clear Hyper terminal
        printf("%bu Temperature : %2bu.%bu\r\n",i++,tp,tpd);	    
        DelayMs(200);
     }
}





Download KEIL C51 example



Copyright(c) 2005-2008 sixca.com, All right reserved.
Best view @ 800X600, IE 6.0 up   
Terms of Use  Privacy Policy