Tuesday, August 27, 2013

Digital Thermometer

Also called temperature indicator. This temperature measuring project has a veriety of range from  -55 to +125 degree centigrade indicating on four common anode seven segment display module.The project measures an accurate temperature value point to point.
                    The main sensing part of the project is the semiconductor DS1820.It is based on one wire protocol device manufactured by Dallas semiconductor comes in different resolution such as DS18S20(9-bit resolution), DS18B20(12-bit resolution) etc.A microcontroller(AT89C2051) controls whole circuit function like receiving the serial data from DS1820 and converting the value for displying the seven segment module. 


Here below some snapshots of bredboarding on "Digital Thermometer".




The firmware is written in C and compiled using "mikroC Pro for 8051".
/* DS18x20 Temperature indicator on 4x7-Segment display
   Writer : Sameer Gupta
   Date : July 2012
   MCU : AT89C2051, XL : 12MHz */

 sbit OW_Bit at P3_7_bit;     // OneWire pinout
 sbit dgt_4 at P3.B0; // Control pins for the seven segments
 sbit dgt_3 at P3.B1;
 sbit dgt_2 at P3.B2;
 sbit dgt_1 at P3.B3;
 unsigned char SG=0;
 int Digit1,Digit2,Digit3,Digit4;
 char number[]={0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09,0xFD};
 char Decimal[]={0x02,0x9E,0x24,0x0C,0x98,0x48,0x40,0x1E,0x00,0x08};

void MUX() org IVT_ADDR_ET0 // multiplexing using Timer0 overflow interrupt
{
    TL0=0x36; // load LSB & MSB values
    TH0=0xf6;
    P1=0xFF;
    dgt_1 = dgt_3 = dgt_2 = dgt_4 = 0;
    SG++;
    SG=SG%4;
    switch(SG){
        case 0: P1=number[Digit1];
                dgt_1 = 1;
                break;
        case 1: P1=Decimal[Digit2];
                dgt_2 = 1;
                break;
        case 2: P1=number[Digit3];
                dgt_3 = 1;
                break;
        case 3: P1=number[Digit4];
                dgt_4 = 1;
                break;
    }
}

const unsigned short TEMP_RESOLUTION = 12; //Replace ’12’ with ‘9’ if you are using DS18S20

unsigned temp;
void Display_Temperature(unsigned int temp2write) {
  const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
  char temp_whole;
  unsigned int temp_fraction;

  // check if temperature is negative
  if (temp2write & 0x8000) {
    Digit4 = 10;   //Show negative sign
    temp2write = ~temp2write + 1;
  }

  // extract temp_whole
  temp_whole = temp2write >> RES_SHIFT ;

  // convert temp_whole to characters
  if (temp_whole/100)
     Digit4 = temp_whole/100;
  else
     Digit4 = 0;

  Digit3 = (temp_whole/10)%10;             // Extract tens digit
  Digit2 =  temp_whole%10;                 // Extract ones digit

  // extract temp_fraction and convert it to unsigned int
  temp_fraction  = temp2write << (4-RES_SHIFT);
  temp_fraction &= 0x000F;
  temp_fraction *= 625;
  // convert temp_fraction to characters
  Digit1 =  temp_fraction/1000;         // Extract thousands digit
}

void main() {
  TMOD=0x01;        // Intialize Timer 0
  TL0=0x36;         // Load Timer 0 for 2.5mS delay for multiplexing
  TH0=0xF6;
  IE=0x82;          // Here EA=1 & ET0=1
  TR0_bit=1;        // Start timer0
  //--- main loop starts here
  do {
    //--- perform temperature reading
    Ow_Reset();                                  // Onewire reset signal
    Ow_Write(0xCC);                              // Issue command SKIP_ROM
    Ow_Write(0x44);                              // Issue command CONVERT_T
    Delay_us(120);
    Ow_Reset();
    Ow_Write(0xCC);                              // Issue command SKIP_ROM
    Ow_Write(0xBE);                              // READING_SCRATCHPAD
    temp =  Ow_Read();
    temp = (Ow_Read() << 8) + temp;
    Display_Temperature(temp);
    Delay_ms(500);
  } while (1);
}      //End
I provide you two hex code for DS18S20 & DS18B20.Download the hex code and burn it to the target MCU.


For complete source code contact ,  
search4electronics2013@gmail.com

No comments :

Post a Comment

feel free and ask...

IP Address Checker