Temp project using LM34


Results 1 to 5 of 5

Threaded View

  1. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    try this
    Code:
    <code><font color="#000000">        <font color="#000080">DEFINE  </font>LCD_DREG	PORTD 	<font color="#008000">'data register
            </font><font color="#000080">DEFINE  </font>LCD_RSREG	PORTE	<font color="#008000">'register select
            </font><font color="#000080">DEFINE  </font>LCD_RSBIT	0	<font color="#008000">'pin number
            </font><font color="#000080">DEFINE  </font>LCD_EREG	PORTE	<font color="#008000">'enable register
            </font><font color="#000080">DEFINE  </font>LCD_EBIT 	1	<font color="#008000">'enable bit
            </font><font color="#000080">DEFINE  </font>LCD_RWREG	PORTE	<font color="#008000">'read/write register
            </font><font color="#000080">DEFINE  </font>LCD_RWBIT 	2	<font color="#008000">'read/write  bit
            </font><font color="#000080">DEFINE  </font>LCD_BITS 	8	<font color="#008000">'width of data 
            </font><font color="#000080">DEFINE  </font>LCD_LINES	2	<font color="#008000">'lines in display
            </font><font color="#000080">DEFINE  </font>LCD_COMMANDUS	2000	<font color="#008000">'delay in micro seconds
            </font><font color="#000080">DEFINE  </font>LCD_DATAUS 	20	<font color="#008000">'delay in micro seconds
            
                    'Set the port directions.  We are setting PORTA.0 to an input, all rest outputs
                    'all of PORTD is set to outputs to run the LCD
                    'and all of PORTE as outputs even though PORTE has only 3 lines.
            </font>TRISA = %11111111		<font color="#008000">'set PORTA lines
            </font>TRISD = %00000000		<font color="#008000">'set all PORTD lines to output
            </font>TRISE = %00000000		<font color="#008000">'set all PORTE lines to output 
    </font>        				<font color="#008000">'Set the Analog to Digital control register
            </font>ADCON1=%10000010		<font color="#008000">'see discussion above
    
                    '   added
                    '   -----
            </font>TRISB = %00001111           	<font color="#008000">'PORTB&lt;3:0&gt; = input
    </font>                                    	<font color="#008000">' others to output
            </font>OPTION_REG.7=0              	<font color="#008000">' ENABLE INTERNAL PULL-UPS
                    '   -----
                    
                    'Define the variables used
            </font>ADVAL	<font color="#000080">VAR</font>	<font color="#000080">BYTE</font>		<font color="#008000">'Create ADVAL to store result
            </font>TEMP    <font color="#000080">VAR</font> 	<font color="#000080">BYTE</font>		<font color="#008000">'temperature Farenheit variable
            </font>TEMPC	<font color="#000080">VAR</font> 	<font color="#000080">BYTE</font>		<font color="#008000">'temperature Celsius variable
            </font>DEG <font color="#000080">CON </font>223 			<font color="#008000">'write an degree mark on lcd
            
            </font>Mode    <font color="#000080">VAR BIT
            </font>C       <font color="#000080">CON </font>1
            F       <font color="#000080">CON </font>0
            
            
                    <font color="#008000">'define the adcin parameters
            </font><font color="#000080">DEFINE</font>	ADC_BITS	10	<font color="#008000">'Set number of bits in result
            </font><font color="#000080">DEFINE</font>	ADC_CLOCK	3	<font color="#008000">'Set clock source (3=rc)
            </font><font color="#000080">DEFINE</font>	ADC_SAMPLEUS	50	<font color="#008000">'Set sampling time in uS
    
            </font><font color="#000080">PAUSE </font>500   
            <font color="#000080">LCDOUT </font>$FE, 1			<font color="#008000">'clear screen 
            </font>PORTB.4=0                                   
            Mode = C
    
    LOOP:					<font color="#008000">'The main loop of the program
            </font><font color="#000080">ADCIN </font>4, ADVAL 			<font color="#008000">'Read channel 0 to adval
            </font>ADVAL =(ADVAL*/500)&gt;&gt;2
            TEMP=ADVAL
            TEMPC=((TEMP-32) *100) /180
    
            <font color="#000080">IF </font>PORTB.0=0 <font color="#000080">THEN
                </font>Mode = Mode ^ 1
                <font color="#000080">WHILE </font>PORTB.0 = 0 : <font color="#000080">WEND
                PAUSE </font>50
                <font color="#000080">ENDIF
                                        
            PAUSE </font>200
            <font color="#000080">LCDOUT </font>$FE, 1,&quot;Temp=&quot;
            <font color="#000080">IF </font>Mode=F <font color="#000080">THEN
                LCDOUT DEC3 </font>TEMP,DEG, &quot;F&quot; 	<font color="#008000">'print to line 1 of 2 line display
                </font><font color="#000080">ELSE
                    LCDOUT DEC3 </font>TEMPC,DEG, &quot;C&quot;
                <font color="#000080">ENDIF
                
            GOTO </font>LOOP
            <font color="#000080">END
    
    
    </font></code>
    sure a INT0 interrupt would have it's own advantages as well. Begin with it.
    Last edited by mister_e; - 25th April 2007 at 18:15.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Graphic LCD with PICbasic pro
    By amindzo in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th November 2012, 12:45
  2. Stuck with 85C temp on ds18b20
    By revelator in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd April 2009, 20:50
  3. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 09:47
  4. help with write command
    By cphillips82 in forum General
    Replies: 9
    Last Post: - 21st April 2008, 00:49
  5. Project with PIC16F818 & LM34
    By fesparza in forum mel PIC BASIC
    Replies: 2
    Last Post: - 18th November 2005, 21:05

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