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 CODE NEEDED USING PIC18F46K20

Status
Not open for further replies.

jmie

Newbie level 4
Joined
Dec 9, 2009
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,349
i am required to setup the PIC18F46K20 and enable the ADC module to read a temperature sensor using PIC then display at LCD...I'm using MCP9700 and the temperature range from -40 to +125 deg C. i'm learn a BASIC for the code. can anyone help to provide the code? thx in advance...
 

tq tahmid for your reply..

can u give me the code if u use mikroBASIC compiler.

tq
 

Hi,
Code:
program MC9700_Temp

dim LCD_RS as sbit at RC4_bit
    LCD_EN as sbit at RC5_bit
    LCD_D4 as sbit at RC0_bit
    LCD_D5 as sbit at RC1_bit
    LCD_D6 as sbit at RC2_bit
    LCD_D7 as sbit at RC3_bit

    LCD_RS_Direction as sbit at TRISC4_bit
    LCD_EN_Direction as sbit at TRISC5_bit
    LCD_D4_Direction as sbit at TRISC0_bit
    LCD_D5_Direction as sbit at TRISC1_bit
    LCD_D6_Direction as sbit at TRISC2_bit
    LCD_D7_Direction as sbit at TRISC3_bit

dim ADRead as word
dim Temp as longword
dim vDisp as word[3]
dim Display as string[7]

main:
     TRISA = $FF
     TRISC = 0
     PORTC = 0
     LCD_Init()
     LCD_Cmd(_LCD_CURSOR_OFF)
     LCD_Cmd(_LCD_CLEAR)
     LCD_Out(1, 1, "Temp:")
     Display = "+125 'C"
     while true
           ADRead = ADC_Read(0)
           if (ADRead > 102) then 'If temperature is positive
              Temp = (100 * ( (10 * ADRead) - 1024 ) ) >> 11 'Get temperature
              Display[0] = "+"
           else 'If temperature is negative
              Temp = ( (1024 - (10 * ADRead) ) * 100 ) >> 11 'Get temperature
              Display[0] = "-"
           end if
           vDisp[0] = Temp div 100
           vDisp[1] = (Temp div 10) mod 10
           vDisp[2] = Temp mod 10
           Display[1] = vDisp[0] + 48
           Display[2] = vDisp[1] + 48
           Display[3] = vDisp[2] + 48
           LCD_Out(1, 8, Display) 'Show temperature
     wend
end.
100_1265441511.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top