Showing posts with label thermometer. Show all posts
Showing posts with label thermometer. Show all posts

Thursday, September 11, 2008

Make MCU Board - Thermometer (DS1821) module


The reason of choosing DS1821 thermo sensor is that the circuit is very simple, it only need on  IO pin.

Originally, I wrote the test program by SDCC compiler, the test has some problem, the LCD display is work, but the temperature is still display zero?
Then, I did compiling by HI-TECH's PICC, the temperature value is correct.
If you are using PICC, please comment out lines as following:

typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;

Replace pic/pic16f877a.h by htc.h

Circuit schematics is as following:












Main process:
/*******************************************************************************

 Copyright (c) 2008 Wizign Ltd.
 All Rights Reserved.

 main.c: Main program for demo thermometer

 Version: 1.0.0

 Date: Sep 05, 2008

 Author: YenHung Chen

 E-mail: yhchen@wizign.com

 Revision:
 ---------- -----------------------------------------------------------------
 2008/09/05 Created by YenHung Chen, demo thermometer for both 8051 and PIC

******************************************************************************/
/*******************************************************************************

The IO control

<>For AT89S52

LCD display:
There are 8 data pins, which are connected P2.
The control pins are connected to P1_0, P1_1, and P1_2.

DS1821:
P1_7

<>For PIC16F877A

LCD display:
There are 8 data pins, which are connected PORTD
The control pins are connected to RA0, RA1, and RA2.

DS1821:
RA5


******************************************************************************/

#include "global.h"
#include "delay.h"
#include "lcd.h"
#include "thermo.h"

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define IO and global variables

#ifdef MCU_PIC

// Configurations
typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;

#endif


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define functions

/* Initilize parameters before run the main loop */
void InitParams(void)
{

LCDInit();
ThermoInit();
}

/* Display message on LCD panel */
void DisplayTemperature(void)
{
char tmMsg[16];
int theT;
unsigned char myT;
int hundred;
int tenth;
int ones;

LCDGoto(0); // goto 1st line
LCDPuts("  WIZIGN LTD.  ");

// Convert value to string
myT = ThermoReadTemperature();
if(myT > 127){
   theT = (int)(myT - 0xFF);
}else{
   theT = (int)myT;
}
// start
// it can not display correct format in this block
BLOCK
// end
   hundred = (int)(theT/100);
   tenth = (int)((theT%100)/10);
   ones = theT%10;
   tmMsg[1] = 0x30 + hundred;
   tmMsg[2] = 0x30 + tenth;
   tmMsg[3] = 0x30 + ones;
   tmMsg[4] = 0x20;
   tmMsg[5] = 'C';
   tmMsg[6] = 0x20;
   tmMsg[7] = '\0';

   LCDGoto(0x40); // goto 2nd line
   LCDPuts(tmMsg);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// main program

void main(void)
{
   // Initilize parameters
 InitParams();

   /* do loop */
   while(1){
    DisplayTemperature();
       // The LCD display and the calculation of time
       // will consume times, so, the delay time is less than 1000 ms.
       DelayMs(900);
   }
}