---
+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Newbie level 3
    Points: 491, Level: 4

    Join Date
    Apr 2010
    Location
    Malaysia
    Posts
    4
    Helped
    0 / 0
    Points
    491
    Level
    4

    Temperature Sensor project with LM35DZ & PIC16F877A

    My project is about sensing the temperature with LM35DZ then perform ADC with PIC16F877A and display the output via 4 common anode 7-segment (eg: 24.5C). So far the circuit is done, and all that left is the coding part. I'm using 2V of voltage reference. I ran into some problem when building my program. my program is something like this:

    Code:
    // ***************************************************************************
    //  File Name    : pictemp.c
    //  Version      : 1.0
    //  Description  : PIC Thermometer
    //  Target       : Microchip PIC16F877a Microcontroller
    //  Last Updated : 28 March 2010
    // ***************************************************************************
    
    #include <pic.h>
    
    __CONFIG(XT & WDTDIS & PWRTDIS & UNPROTECT & BORDIS & \
      LVPDIS & DEBUGEN);
    
    #define FOSC 20000000L
    
    const char SSEG[] = {
      
      0b11000000,  // 0, LED Segment: A,B,C,D,E,F
      0b11111001,  // 1, LED Segment: B,C
      0b10100100,  // 2, LED Segment: A,B,D,E,G
      0b10110000,  // 3, LED Segment: A,B,C,D,G
      0b10011001,  // 4, LED Segment: B,C,F,G
      0b10010010,  // 5, LED Segment: A,C,D,F,G
      0b10000010,  // 6, LED Segment: A,C,D,E,F,G
      0b11111000,  // 7, LED Segment: A,B,C
      0b10000000,  // 8, LED Segment: A,B,C,D,E,F,G
      0b10010000,  // 9, LED Segment: A,B,C,D,F,G
      0b11000110,  // C, LED Segment: A,D,E,F
    
    };
    
    unsigned char DispDigit[4];
    unsigned char DigitCount;
    
    static void interrupt isr(void)
    {
      if(TMR0IF) {			       // TIMER0 Interrupt Flag
        /* Pull Low the Segment */
        PORTB = DispDigit[DigitCount];
        /* Activate the Digit and Advanced to next Digit */
        PORTD = ~(1 << DigitCount++);     
    
        /* Reset the Digit Count */
        if (DigitCount > 3)
          DigitCount=0;
    
        TMR0 = 156;            	   
        TMR0IF = 0;			     
      }
    }
    
    
    // Delay Function
    
    #define _delay_us(x) { unsigned char us; \
    	  	       us = (x)/(30000000/FOSC)|1; \
    		       while(--us != 0) continue; }
    
    
    void _delay_ms(unsigned int ms)
    {
      unsigned char i;
      do {
        i = 4;
        do {
          _delay_us(164);
        } while(--i);
      } while(--ms);
    }
    
    
    /* Seven Segment Put Number: Implementing floating value from 0 to 99.9 */
    
    void SSEG_putnum(float number)
    {
       unsigned char iDigit,iDigit1,iDecimal;
       if (number > 99.9) return;
       
       /* Global interrupt disable */
       GIE = 0;		                   
    
       iDigit=(int)number;  
       //float temp=number-iDigit;                       // Convert float to Integer
       //float temp2=temp*10;
       //iDecimal=(int)temp2;                            
       iDecimal=(int)(number - iDigit) * 10;       // Get The Decimal Digit
       DispDigit[1]=SSEG[iDecimal];                 // First Decimal Digit
       if (iDigit >= 10) {
         iDigit1=iDigit / 10;
         DispDigit[3]=SSEG[iDigit1];                  // Second Digit
         iDigit=iDigit - (iDigit1 * 10);
       } else { 
         DispDigit[3]=SSEG[0];                           // Zero Sign Second Digit
       }
       DispDigit[2]=SSEG[iDigit] & 0x7F;           // First Digit with Decimal Point
       
       /* Global interrupt enable */
       GIE = 1;
    }
    
    
    void main(void)
    {
      unsigned int iValue,iCTemp;
      float CentTemp;
    
    
      TRISA = 0xFF;        // Input for RA0 to RA7
      TRISB = 0x00;        // Output for RB0 to RB7
      TRISD = 0x00;        // Output for RC0 to RC7
     
      /* Initial Output Port */
      
      PORTB=0xFF;
      PORTD=0xFF;
      
    
      /* Init TIMER0: Period: 1/(Fosc/32) x Prescale x TMR0
         0.0016 ms x 64 * 100 = 10.24 ms */
      
      OPTION = 0b00000101;    // 1:64 Prescale
      TMR0=156;                          // Interupt every 10.24 ms
      TMR0IE = 1;	          // Enable interrupt on TMR0 overflow
      GIE = 1;	                           // Global interrupt enable
      
      
      /* Initial variables used */
      
      DigitCount=0;
      DispDigit[0]=SSEG[10];     // Centigrade Sign
      DispDigit[1]=SSEG[0];      // Zero Digit
      DispDigit[2]=SSEG[0];      // Zero Digit
      DispDigit[3]=SSEG[0];      // Zero Digit
      for(;;) {
      
      /* Get First Sample */
      
      ADCON0=0b10000001;       
      ADCON1=0b10001101;           // Right Justified,Vref: VCFG1 and VCFG0(1 VoltReference)
      GODONE=1;	                   // initiate conversion on the channel 0
      while(GODONE) continue;         // Wait conversion done
      iValue=ADRESL;                        // Get the 8 bit LSB result
      iValue += (ADRESH << 8);       // Get the 2 bit MSB result
      iCTemp = iValue;
      _delay_ms(50);
        
      /* Get Second Sample */
       
      GODONE=1;	                 // initiate conversion on the channel 0
      while(GODONE) continue;      // Wait conversion done
      iValue=ADRESL;                     // Get the 8 bit LSB result
      iValue += (ADRESH << 8);     // Get the 2 bit MSB result
      iCTemp += iValue;
      _delay_ms(50);
        
      /* Get Third Sample */
       
      GODONE=1;             	  // initiate conversion on the channel 0
      while(GODONE) continue;         // Wait conversion done
      iValue=ADRESL;                        // Get the 8 bit LSB result
      iValue += (ADRESH << 8);       // Get the 2 bit MSB result
      iCTemp += iValue;
    
      /* Calculate the Average Centigrade Value */
      /* (ADC Value/5.12) / Vref, LM35DZ Out=10mV/C, Vref = 2 Volt */
      
      CentTemp=(iCTemp/3.0)/ 5.12;
       
    
    
      /* Now Display The Result */
        SSEG_putnum(CentTemp);
        _delay_ms(200);
      }
    }
    /* EOF: pictemp.c */
    after i build the program, i got this error :
    "undefined identifier: GO_DONE"

    can anyone help me regarding this matter?

    •   Alt11th April 2010, 14:08

      advertising

        
       

  2. #2
    Advanced Member level 5
    Points: 18,155, Level: 32

    Join Date
    Jul 2001
    Location
    Oberon
    Posts
    1,889
    Helped
    422 / 422
    Points
    18,155
    Level
    32

    Re: Temperature Sensor project with LM35DZ & PIC16F877A

    Microchip changed the register name to 'ADGO'

    Change your GODONE's to ADGO.



  3. #3
    Newbie level 3
    Points: 491, Level: 4

    Join Date
    Apr 2010
    Location
    Malaysia
    Posts
    4
    Helped
    0 / 0
    Points
    491
    Level
    4

    Re: Temperature Sensor project with LM35DZ & PIC16F877A

    ok i changed the GODONE to ADGO and the compiler said there's no error in the program. But when when i load the program to the PIC16f877a all that is displayed are all 4 7-segment showing 8.8.8.8. what do you think is the problem now??



    •   Alt11th April 2010, 19:05

      advertising

        
       

  4. #4
    Newbie level 3
    Points: 491, Level: 4

    Join Date
    Apr 2010
    Location
    Malaysia
    Posts
    4
    Helped
    0 / 0
    Points
    491
    Level
    4

    Re: Temperature Sensor project with LM35DZ & PIC16F877A

    I think I need a header file for this project..can someone help with the header file please??

    Added after 2 hours 44 minutes:

    The display still doesn't change. It still displaying 8.8.8.8. Does anyone know what the problem is?



  5. #5
    Member level 2
    Points: 1,047, Level: 7

    Join Date
    Mar 2010
    Posts
    48
    Helped
    1 / 1
    Points
    1,047
    Level
    7

    Re: Temperature Sensor project with LM35DZ & PIC16F877A

    i 've the same project right now and i've the same problems
    could u post ur final code (if u don't mind)
    thanx alot



  6. #6
    Newbie level 3
    Points: 491, Level: 4

    Join Date
    Apr 2010
    Location
    Malaysia
    Posts
    4
    Helped
    0 / 0
    Points
    491
    Level
    4

    Re: Temperature Sensor project with LM35DZ & PIC16F877A

    Basically the above code is my final code..
    You just have to change GODONE to ADGO..



  7. #7
    Newbie level 5
    Points: 417, Level: 4

    Join Date
    Nov 2010
    Posts
    10
    Helped
    1 / 1
    Points
    417
    Level
    4

    Re: Temperature Sensor project with LM35DZ & PIC16F877A

    can u give me a schematic diagram of this temperature sensor that you made now?....plz..tnx..


    1 members found this post helpful.

+ Post New Thread
Please login