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
| ||
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#include #include #include 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
No comments:
Post a Comment