Skip to main content

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

OP AMP INTEGRATOR CALCULATOR

Enter the Input Voltage,Vin: Volts Enter the Frequency, f: Hertz Enter the Input Resistance, Rin: Ohms Enter the Value of Capacitor, C: Farads Output Voltage, Vout: Volts OP AMP based Integrator Tutorial and Design

Block diagram of AM transmitter and receiver with explanation

Block diagram of AM transmitter and receiver with explanation AM Transmitter : Transmitters that transmit AM signals are known as AM transmitters. These transmitters are used in medium wave (MW) and short wave (SW) frequency bands for AM broadcast. The MW band has frequencies between 550 KHz and 1650 KHz, and the SW band has frequencies ranging from 3 MHz to 30 MHz. The two types of AM transmitters that are used based on their transmitting powers are: ·          High Level ·          Low Level High level transmitters use high level modulation, and low level transmitters use low level modulation. The choice between the two modulation schemes depends on the transmitting power of the AM transmitter. In broadcast transmitters, where the transmitting power may be of the order of kilowatts, high level modulation is employed. In low power transmitters, where only a few watts of transmitting power are required , low...

Using the TLP250 Isolated MOSFET Driver Explanation and Example Circuits

I’ve already shown how to drive an N-channel MOSFET (or even an IGBT) in both high-side and low-side configurations in a multitude of ways. I’ve also explained the principles of driving the MOSFETs in these configurations. The dedicated drivers I’ve shown so far are the TC427 and IR2110. Some people have requested me to write up on MOSFET drive using the very popular TLP250. And I’ll explain that here. The TLP250, like any driver, has an input stage, an output stage and a power supply connection. What’s special about the TLP250 is that the TLP250 is an optically isolated driver, meaning that the input and output are “optically isolated”. The isolation is optical – the input stage is an LED and the receiving output stage is light sensitive (think “photodetector”). Before delving any further, let’s look at the pin configuration and the truth table. Fig. 1 - TLP250 Pin Configuration Fig. 2 - TLP250 Truth Table Fig. 1 clearly shows the input LED side and the receiving photodetector as well...