Temperature sensor with PIC18 and MCP9700

 This can be a complete project on its own - a simple DIY digital thermometer with LCD display and only a handful of parts - the PIC18F45K20, LM35 and a small number of resistors and capacitors running off a regulated 5v supply.

Display type - LCD (can be 16x1, 16x2 or anything larger)
Controller: PIC18F45K20
Programming Language: BASIC
Compiler: mikroBASIC PRO for PIC v3.20

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Programmer: Syed Tahmid Mahbub
'Compiler: mikroBASIC PRO for PIC v3.20
'Target PIC: 18F45K20
'Configuration: Check the project in the download link for the configuration bits


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.

 

Hex file + Schematic + Code freely available for download:
http://www.4shared.com/file/b8bT5a9e/MC9700_temperature_sensor.html

The code can be freely used and there is no copyright restrictions or anything as such. Only credit the author (me) where necessary.

Comments

Popular posts from this blog

N-Channel MOSFET High-Side Drive: When, Why and How?

Using the SG3525 PWM Controller - Explanation and Example: Circuit Diagram / Schematic of Push-Pull Converter

Using the high-low side driver IR2110 - explanation and plenty of example circuits