how to add the calculation of temperature in my source code


Results 1 to 14 of 14

Threaded View

  1. #7
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Try that on your breadboard.

    (Click to enlarge the picture)

    The original tutorial + code can be found here:
    http://www.rentron.com/PicBasic/LM34.htm

    LM35 datasheet:
    http://www.national.com/ds/LM/LM35.pdf

    The code below will work with the above connections.
    Note that you will have to add the DEFINE + code for the LCD.

    Best regards,

    Luciano


    Code:
    DEFINE osc 4            ' We're using a 4 MHz oscillator
    DEFINE ADC_BITS 8       ' Set A/D for 8-bit operation
    DEFINE ADC_CLOCK 1      ' Set A/D clock Fosc/8
    DEFINE ADC_SAMPLEUS 50  ' Set A/D sampling time @ 50 uS
    ' Add the LCD DEFINEs here <<<<<<<<<<<<<<<<<<<<<<<<<
    samples VAR WORD        ' Multiple A/D sample accumulator
    sample  VAR BYTE        ' Holds number of samples to take
    temp    VAR BYTE        ' Temperature storage
    samples = 0             ' Clear samples accumulator on power-up
    
        TRISA = %11111111   ' Set PORTA to all input
        ADCON1 = %00000011  ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
        PAUSE 500           ' Wait .5 second
    
    loop:
    
        FOR sample = 1 TO 20    ' Take 20 samples
            ADCIN 0, temp       ' Read channel 0 into temp variable
            samples = samples + temp ' Accumulate 20 samples
            PAUSE 250           ' Wait approximately 1/4 seconds per loop
        NEXT sample
    
        temp = samples/20
        
        LCDOUT $FE, 1 ' Clear LCD
        LCDOUT "Temp: ",DEC temp,"'C" 
    
        samples = 0             ' Clear old sample accumulator
        GOTO loop               ' Do it forever
    
        END
    Attached Images Attached Images  

Similar Threads

  1. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. My Code get crazy after i add interrupt
    By jetpr in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th May 2005, 04:43
  4. code source
    By meyou in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th August 2004, 21:01
  5. accessing source code
    By mle in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st July 2003, 14:25

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts