Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Temperature Sensor project with LM35DZ & PIC16F877A

Status
Not open for further replies.

reinneguhn

Newbie level 3
Joined
Apr 11, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,307
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?
 

Microchip changed the register name to 'ADGO'

Change your GODONE's to ADGO.
 

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??
 

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?
 

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
 

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

can u give me a schematic diagram of this temperature sensor that you made now?....plz..tnx..
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top