The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Dallas temp sensors


  • To: ukha_d@xxxxxxx
  • Subject: RE: Dallas temp sensors
  • From: "K. C. Li" <li@xxxxxxx>
  • Date: Fri, 19 Jul 2002 12:27:57 +0100 (BST)
  • Mailing-list: list ukha_d@xxxxxxx; contact ukha_d-owner@xxxxxxx
  • Reply-to: ukha_d@xxxxxxx

On Fri, 19 Jul 2002, Jon Whiten wrote:

> The DS1820 does not have the error checking.  I have somewhere a report from
> Dallas regarding the problems with the DS1820 I can let you have if you
> like.

The DS18S20 (or DS1820) outputs can be checked by calculating the CRC
using the scratchpad values return. If the resultant CRC value is zero,
the readings are assumed to be reliable. The algorithm is given in the
Dallas technical reference for the temperature chip.

I have attached a small PIC C program that reads the DS1820 and displays
the various temperature readings on a LCD display. The PIC C compiler was
developed by us for internal use. If anyone is interested, I can post the
CRC routine in PIC16F84 assembler. We are also happy to provide a copy of
our PIC C compiler to UKHA FOC but unfortunately it is not packaged for
distribution at the moment.

Regards,

Kwong Li
li@xxxxxxx Laser Business Systems Ltd.
http://www.laser.com

Yahoo! Groups Sponsor
ADVERTISEMENT

For more information: http://www.automatedhome.co.uk
Post message: ukha_d@xxxxxxx
Subscribe:  ukha_d-subscribe@xxxxxxx
Unsubscribe:  ukha_d-unsubscribe@xxxxxxx
List owner:  ukha_d-owner@xxxxxxx

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
/*
DS1820 thermometer program  (v1.4)

Copyright (c) 2000 Laser Business Systems Ltd.
All rights reserved.

This program reads the DS1820 continuously and
displays the following:

1. ROM code of DS1820
2. Current temperature
3. Trigger high and low values
4. Count remain & Count per degree C
5. Highest and lowest temperatures (+ve int only)

CRC is calculated and compared with the returned CRC
to ensure the integrity of read data.

A flashing symbol is displayed to give visual feedback.
For each flash, two temperature readings have been taken.
Note: The symbol is user programmable.
*/

#config(_CP_OFF & _PWRTE_OFF & _WDT_ON & _XT_OSC)
#include <stdio.h>

#define SAMSUNGlcd

void prelude(void);
void setupdisplay(void);
void displayROM(void);
void displayinfo(void);

char crc, count, half, tempH, tempL;
char ROM[8];                        /* ROM code */
char scratchpad[9];                 /* Scratchpad data */

void main(void)
{
char idx;

prelude();
while (1) {
@clrwdt();              /* Reset watchdog */
dsmatchrom(ROM);
convert1820();
dsconvwait();
while (1) {
dsmatchrom(ROM);
read1820sp(scratchpad);
crc = 0;
for (idx=0; idx <= 8; idx++)
crc = dscalcrc(scratchpad[idx], crc);
if (!crc)         /* Should be zero */
break;
}
half = scratchpad[0] & 1;       /* Note half degree */
scratchpad[0] >>= 1;            /* Now remove it */
if ((scratchpad[0]) > tempH)    /* Highest? */
tempH = scratchpad[0];
if ((scratchpad[0]) < tempL)    /* Lowest? */
tempL = scratchpad[0];
displayinfo();                  /* Show info */
}
}

void prelude(void)
{
char idx, *symbol;

symbol = "\b00100\b01110\b11011\b11111\b01110\b01110\b11111\x80";
lcd4init(0b00001000, 0b00000100, 0b00000010, 0b00000000);
lcd4clear();
displayROM();
dsmatchrom(ROM);
recall1820ee();
setupdisplay();
count = tempH = 0;
tempL = 255;
lcd4setcg7(0, symbol);   /* Program own lcd symbol */
}

void setupdisplay(void)
{
lcd4gotoxy(2, 1);
lcd4print("Temp:");
lcd4gotoxy(3, 1);
lcd4print("TH:   TL:   H:");
lcd4gotoxy(4, 1);
lcd4print("CR:   CP:   L:");
}

void displayROM(void)
{
char idx;

while (1) {
crc = 0;
dsreadrom(ROM);
for (idx=7; idx > 0; idx--)     /* Do checksum calculation */
crc = dscalcrc(ROM[idx], crc);
if (ROM[0] == crc)              /* All data read OK? */
break;                      /* Yes, get out */
}
for (idx=0; idx < 8; idx++)         /* Display ROM code */
lcd4hex(ROM[idx]);
}

void displayinfo(void)
{
lcd4gotoxy(2, 6);
if (scratchpad[1])          /* Temp below zero? */
lcd4putchar('-');
lcd4dec(scratchpad[0]);     /* Show actual temp */
if (half)                   /* Any half degree? */
lcd4print(".5");
#ifndef SAMSUNGlcd
lcd4print("\xdfC  ");       /* Show degree symbol */
#else
lcd4print("\xd6C  ");       /* Samsung has a diff symbol */
#endif
lcd4gotoxy(2, 16);
//    (++count & 1) ? lcd4putchar('*') : lcd4putchar(' ');
(++count & 1) ? lcd4putchar(0) : lcd4putchar(' ');
lcd4gotoxy(3, 4);
lcd4hex(scratchpad[2]);
lcd4gotoxy(3, 10);
lcd4hex(scratchpad[3]);
lcd4gotoxy(3, 15);
lcd4dec(tempH);
lcd4gotoxy(4, 4);
lcd4hex(scratchpad[6]);
lcd4gotoxy(4, 10);
lcd4hex(scratchpad[7]);
lcd4gotoxy(4, 15);
lcd4dec(tempL);
}

Home | Main Index | Thread Index

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.