Digital thermometer using 8051

Thermometer using 8051.

This article is about a simple 0-100°C digital thermometer with 1°C resolution using 8051. The circuit is based on LM35 analog temperature sensor, ADC0804 and AT89S51 microcontroller. LM35 is an analogue temperature sensor IC which can measure a temperature range of -55 to 150°C. Its output voltage varies 10mV per °C change in temperature.

For example, if the temperature is 32°C, the output voltage will be 32 x 10mV = 320mV. ADC 0804 is used to convert the analogue output voltage of the LM35  to a proportional 8 bit digital value suitable for the microcontroller. The microcontroller accepts the output of ADC, performs necessary manipulations on it and displays it numerically on a 2 digit seven segment LED display.

Out put of the LM35 is connected to the +Vin (pin 6) of the ADC0804. Resistor R13 and preset R14 is used to provide an external reference voltage of 1.28V to the Vref/2 pin  ( pin 9) of the ADC0804 and with this reference voltage, the step size of the ADC will be 10mV and span will be 0-1 V. This means that for a 10mV input the digital out of ADC will be 1 (1 in decimal also), for 20mV it will be 10 (2 in decimal), for 30mV it will be 11 (3 in decimal) and so on. The microcontroller accepts this data and puts it on the seven segment display. 

Circuit diagram.

8051 digital thermometer

Digital thermometer using 8051

Digital out of the ADC (D0 to D7) are connected to P1 (P1.0 to P1.7) of the microcontroller. This is the line through which the microcontroller accepts data from the ADC. The control pins CS, RD, WR and  INTR are connected to P3.7, P3.6, P3.5 and P3.4 of the microcontroller. This is the data path through which the microcontroller sends chip select (CS), read (RD) write (WR) signals to the ADC and receives INTR signal from the ADC. Data lines (a to h) of the multiplexed seven segment display are interfaced to P0 (P0.0 to P0.7) of the microcontroller. Activation signals for the segment driver transistors Q1 and Q2 are available from P3.2 and P3.1 pins of the microcontroller. 

Before attempting this circuit go through these articles Voltmeter using 8051  , Interfacing ADC to 8051 , Interfacing seven segment display to 8051

Program.

ORG 00H
MOV P1,#11111111B   // initializes P1 as input port
MOV P0,#00000000B   // initializes P0 as output port
MOV P3,#00000000B   // initializes P3 as output port
MOV DPTR,#LABEL     // loads the address of "LABEL" to DPTR
MAIN: MOV R4,#250D  // loads register R4 with 250D
      CLR P3.7      // makes Cs=0
      SETB P3.6     // makes RD high
      CLR P3.5      // makes WR low
      SETB P3.5     // low to high pulse to WR for starting conversion
WAIT: JB P3.4,WAIT  // polls until INTR=0
      CLR P3.7      // ensures CS=0
      CLR P3.6      // high to low pulse to RD for reading the data from ADC
      MOV A,P1      // moves the digital output of ADC to accumulator A
      MOV B,#10D    // load B with 10D
      DIV AB        // divides the content of A with that in B
      MOV R6,A      // moves the quotient to R6
      MOV R7,B      // moves the remainder to R7
DLOOP:SETB P3.2     // sets P3.2 which activates LED segment 1
      MOV A,R6      // moves the quotient to A
      ACALL DISPLAY // calls DISPLAY subroutine
      MOV P0,A      // moves the content of A to P0
      ACALL DELAY   // calls the DELAY subroutine
      CLR A         // clears A
      MOV A,R7      // moves the remainder to A
      CLR P3.2      // deactivates LED segment 1
      SETB P3.1     // activates LED segment 2
      ACALL DISPLAY
      MOV P0,A      
      ACALL DELAY
      CLR A 
      CLR P3.1      // deactivates LED segment 2
      DJNZ R4,DLOOP // repeats the loop "DLOOP" until R4=0
      SJMP MAIN     // jumps back to the main loop
DELAY: MOV R3,#255D // produces around 0.8mS delay
LABEL1: DJNZ R3,LABEL1          
        RET
DISPLAY: MOVC A,@A+DPTR // converts A's content to corresponding digit drive pattern 
         RET
LABEL: DB 3FH       // LUT (look up table) starts here
       DB 06H
       DB 5BH
       DB 4FH
       DB 66H
       DB 6DH
       DB 7DH
       DB 07H
       DB 7FH
       DB 6FH
END 
Show Comments

26 thoughts on “Digital thermometer using 8051

    • anonymous

      #include
      #define port P3
      #define adc_input P1
      #define dataport P0
      #define sec 100
      sbit rs = port^0;
      sbit rw = port^1;
      sbit e = port^2;

      sbit wr= port^3;
      sbit rd= port^4;
      sbit intr= port^5;

      int test_intermediate3=0, test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0};

      void delay(unsigned int msec )
      {
      int i ,j ;
      for(i=0;i<msec;i++)
      for(j=0; j<1275; j++);
      }

      void lcd_cmd(unsigned char item) //Function to send command to LCD
      {
      dataport = item;
      rs= 0;
      rw=0;
      e=1;
      delay(1);
      e=0;
      return;
      }

      void lcd_data(unsigned char item) //Function to send data to LCD
      {
      dataport = item;
      rs= 1;
      rw=0;
      e=1;
      delay(1);
      e=0;
      //delay(100);
      return;
      }

      void lcd_data_string(unsigned char *str) // Function to send string to LCD
      {
      int i=0;
      while(str[i]!='')
      {
      lcd_data(str[i]);
      i++;
      delay(10);
      }
      return;
      }

      void shape() // Function to create the shape of degree
      {
      lcd_cmd(64);
      lcd_data(2);
      lcd_data(5);
      lcd_data(2);
      lcd_data(0);
      lcd_data(0);
      lcd_data(0);
      lcd_data(0);
      lcd_data(0);
      }

      void convert() // Function to convert the values of ADC into numeric value to be sent to LCD
      {
      int s;
      test_final=test_intermediate3;
      lcd_cmd(0xc1);
      delay(2);
      lcd_data_string("TEMP:");
      s=test_final/100;
      test_final=test_final%100;
      lcd_cmd(0xc8);
      if(s!=0)
      lcd_data(s+48);
      else
      lcd_cmd(0x06);
      s=test_final/10;
      test_final=test_final%10;
      lcd_data(s+48);
      lcd_data(test_final+48);
      lcd_data(0);
      lcd_data('c');
      lcd_data(' ');
      delay(2);
      }

      void main()
      {
      int i,j;
      adc_input=0xff;
      lcd_cmd(0x38);
      lcd_cmd(0x0c); //Display On, Cursor Blinking
      delay(2);
      lcd_cmd(0x01); // Clear Screen
      delay(2);

      while(1)
      {
      for(j=0;j<3;j++)
      {
      for(i=0;i<10;i++)
      {
      delay(1);
      rd=1;
      wr=0;
      delay(1);
      wr=1;
      while(intr==1);
      rd=0;
      lcd_cmd(0x88);
      test_intermediate1[i]=adc_input/10;
      delay(1);
      intr=1;
      }
      for(i=0;i<10;i++)
      test_intermediate2[j]=test_intermediate1[i]+test_intermediate2[j];
      }

      test_intermediate2[0]=test_intermediate2[0]/3;
      test_intermediate2[1]=test_intermediate2[1]/3;
      test_intermediate2[2]=test_intermediate2[2]/3;
      test_intermediate3=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2];
      shape();
      convert();
      }
      }

      Reply
    • anonymous

      I’ve used both codes the one is assembly and the one in C but the circuit is not working!
      see if it works for you!

      Reply
  1. clemo

    hallo
    am new with coding i wanna learn good language to program pic etc,
    the one u wrote there what kind of language is it,?

    Reply
  2. Paul Fothergill

    I have built this circuit for my college project but i haven’t been able to program the PIC, can anyone program the 8051/8052 and post me a working one as I am running out of time to complete this project.

    Reply
  3. amirul

    hello sir..
    i wan to ask about the LUT..
    what does it mean?what table should i be looking at?
    how do u calculate the temperature rise and decrease in the code?

    Reply
  4. naresh

    in theory the ADC terminals rd,wr,cs,intr are different compare to above diagram all are complementry please tell the anthour program why becuse the ADC is not working

    Reply
  5. Rinal

    Hello, my name rinal and im a student.

    of course, I am very grateful for the knowledge that you give. This adds to my knowledge.

    I have a bit question, I hope you do not mind to answer it..
    bif you ever make this circuit? whether these circuits have been tested and work properly?
    I would be happy if you guide with answering my questions,
    thank you. :)

    Reply
  6. abdul rauf

    IS THIS CIRCUIT WORKING ?
    CAN I USE 89C51 INSTEAD OF 89S51.
    I WANT URGENT ANSWERS… PLZ. I HAVE TO SUBMITT MY PROJECT PROPOSAL AT 11, NOVEMBER 2013.

    Reply
  7. prutha

    can anyone please provide me the complete layout of this circuit and also the approximate cost? It would be of great help.

    Reply
    • admin Post author

      MOV R4,#250D initially loads R4 with 250D ,this instruction in conjunction with DJNZ R4,DLOOP repeats the display cycle 250 times (or for roughly 0.8mS). This means that the “MAIN” loop which fetches the data from the ADC is repeated only once in every 0.75mS.

      Reply
  8. EZE ROBERT

    thank u for helping students. Yes i would suggest that post ur work with proteus version of ur work, what i mean is design it with proteus and up-load it will actracts many users to vist tis site. This is want they are doing thus in this site,www.8051projects.net

    Reply
  9. EZE ROBERT

    yes that is a good work. Thanks but it will be more professional if u configure the cct using 3 7-segment display in showing the meter type and in the temperature form type as u up-loaded here inshort i personally will be glad likewise others…

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>