Embedded Systems and Power Electronics

Total Pageviews

About Me

My photo
I am currently a PhD student at UC Berkeley, following a 6-year journey working at Apple after my undergrad years at Cornell University. I grew up in Dhaka, Bangladesh where my interest in electronics was cultivated, resulting in the creation of this blog.

BTemplates.com

Powered by Blogger.

Dec 22, 2010

Digital thermometer with LM35 and PIC16F88


This can be a complete project on its own - a simple DIY digital thermometer with 7-segment displays and only a handful of parts - the PIC16F88, LM35 and a small number of resistors and capacitors running off a regulated 5v supply.
Temperature range - 0 to 150'C
Display type - 3 digit multiplexed 7 segment or 3 individual 7 segments
Controller: PIC16F88
Programming Language: BASIC
Compiler: mikroBASIC PRO for PIC v3.20

Complete code:

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

program DigThermo

'Programmer: Syed Tahmid Mahbub
'Compiler: mikroBASIC PRO for PIC v3.20
'Target PIC: 16F88 - 18pin DIP
'Configuration: XT OSC, PWRTE OFF, WDT OFF, RA5 - MCLR OFF, BOR OFF, LVP OFF, CP OFF, CPD OFF, DEBUG OFF, CKMNE OFF, INTEXTSW OFF

dim data7, num7 as byte
dim temperature as longword
dim digit as byte[3]

sub procedure send7 (dim value, seven as byte) 'Common Anode Displays (2 7segments)
    PORTA = 0
    select case value
           case 0 data7 = $C0
           case 1 data7 = $F9
           case 2 data7 = $A4
           case 3 data7 = $B0
           case 4 data7 = $99
           case 5 data7 = $92
           case 6 data7 = $82
           case 7 data7 = $F8
           case 8 data7 = $80
           case 9 data7 = $90
    end select
    PORTB = data7 'send temperature
    select case seven
           case 1 num7 = 2
           case 2 num7 = 4
           case 3 num7 = 8
    end select
    PORTA = num7 'choose which 7segment
end sub

sub procedure GlobInit
    TRISA = 1
    TRISB = 0
    PORTA = 0
    PORTB = 0
    ANSEL = 1 'AN0 analog
    CCP1CON = 0 'PWM off
    CMCON = 7 'Comparator off
end sub

sub procedure delay2ms
    delay_ms(2)
end sub

main:
     GlobInit
     while true
           temperature = (ADC_Read(0) * 500) >> 10
           digit[0] = temperature div 100
           digit[1] = (temperature div 10) mod 10
           digit[2] = temperature  mod 10
           send7(digit[0],1)
           delay2ms()
           send7(digit[1],2)
           delay2ms()
           send7(digit[2],3)
           delay2ms()
     wend
end.

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Schematic:




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

Hex file can be freely downloaded from:
http://www.4shared.com/file/o-OBjgGB/DigThermo.html

11 comments:

  1. Tahmid,i am shrinidhi.ilike ur blog.

    i am working on a control sys, that senses temperature & humidity.
    i plan to use 16f877 for this, is it okie??

    it's an academic project..wish to complete within 2 months.

    Will be of great help if you can guide on this.

    ReplyDelete
  2. Tahmid, i am using an LM34 instead of an LM35 for a project on my own. I was wondering how you would change the code in order to be able to use the LM34 instead of the LM35. Thanks alot.

    ReplyDelete
  3. Hey tahmid, can u help me in making a project report on this project.. I used your code and it worked perfectly... Thanx a lottt... Hopin for a quik reply

    ReplyDelete
  4. I am so sorry for the late reply. Had my exams and so was very busy.

    Anyways, if it isn't too late, Sabi, what kind of help do you want from me? I'll try to help if you can clarify your project.

    Shrinidhi, if it isn't too late, I might try to help.

    ReplyDelete
  5. Tahmid,

    Like Shrinidhi, I also plan to use pic 16f877 for the project ... will it work?

    thanks,

    ReplyDelete
  6. You can use 16F877, but it has a different pin-out, so you cannot use it as is (obviously). Plus the code needs to be recompiled with changes for 16F877.

    ReplyDelete
  7. hey guys, can you show me how the circuit looks like in reality because i'm having problems with my experimental part... or can someone tell me a site where i can find it.

    ReplyDelete
  8. Hallo!
    I've build the temp meter circuit but can't figure out the connections correctly from the resistors,
    I can see it starts to work but the 7 segments do not show up correctly.
    Any advice?Chris email hollybrand@telkomsa.net

    ReplyDelete
  9. Hi Tahmid!
    That's a great project. I'm newbie in PIC programming, but I would like to build this circuit with minor modifications such as using internal oscillator instead of XT and temperatur range -55 to 150 C. How can i modify the source code?
    Anyway, is it possible to build this project using 16F886 instead of 16F88 with 2 LM 35 sensor and 2 x 3 digit 7 segment display?
    Thanks for advising.

    Zsolt

    ReplyDelete
  10. Can we convert this temp indicator program in bad out put instead 7 segment . Please write
    Thanks

    ReplyDelete