Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

Project Request

Return
Jabir J
JAbir

posted on 2014/02/06 08:50:09 PM CET

Measurement

code for reading negative temp

I am using PIC18F4550 and temp sensor LM35 to read both '-' and '+' temperature. I am using Mikrobasic pro for writing the code.can anyone help me to correct the code that i have written...please..?


dim LCD_RS as sbit at LATB4_bit
LCD_EN as sbit at LATB5_bit
LCD_D4 as sbit at LATB0_bit
LCD_D5 as sbit at LATB1_bit
LCD_D6 as sbit at LATB2_bit
LCD_D7 as sbit at LATB3_bit
dim LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit

dim R_S as word
dim T as word
dim V as byte
dim temp as string[15]

main:
ADCON0 = 0x00
ADCON1 = 0x00
ADCON2 = 0x00
ADRESL = 1
ADRESH = 0

PORTA=$01 'Initialize port A to 0
PORTB=0 'Initialize port B to $01
TRISA3_bit = 1 ' Configure RA3 pin as input
TRISB=0 ' port B is output


ADC_Init() ' Initialize ADC

Lcd_Init() ' Initialize LCD
Lcd_Cmd(_LCD_CLEAR) ' Clear display
Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off

Lcd_Out(1, 1, "Temperature :")
Lcd_Chr(2,8,223) 'char code for degree

Lcd_Chr(2,9,"C") ' Display "C" for Celsius
R_S = 0

While TRUE
R_S= ADC_Get_Sample(3) 'Get 10-bit results of AD conversion
V=R_S*(5/1024) 'convert digital reading to voltage,verf=5 V
T=V*100 'converting this voltage to Celsius, Since sensor's sensitivity is 10mV/C
wordToStr(T,temp)
temp[4] = 0
Lcd_out(2,3, temp) ' Write string in second row
delay_ms(500)
wend

end.