---
+ Post New Thread
Results 1 to 15 of 15
  1. #1
    Junior Member level 1
    Points: 428, Level: 4

    Join Date
    Dec 2010
    Posts
    16
    Helped
    0 / 0
    Points
    428
    Level
    4

    HELP!! Digital Thermometer

    I have a huge project due in 2 days and i cant figure it out! I am using a PIC16F917 microcontroller and an LM34 sensor to display the thermometer readings on a seven segment display. I am using the MPLAB IDE program to program the pic, but i do not know how to write the code (I believe it is C Code) in order to get this simple temperature reading on the display. Does anyone have a C Code for my pic and sensor to make this work?

  2. #2
    Advanced Member level 4
    Points: 7,022, Level: 19
    klystron's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    1,013
    Helped
    189 / 189
    Points
    7,022
    Level
    19

    Re: HELP!! Digital Thermometer

    You need to write code for the the following functions :
    Read the analogue LM34 voltage (A2D)
    Convert the reading to temperature
    Convert the temperature value to BCD ( 2 digits)
    Convert the BCD to 7 segment code
    Refresh the 7 segment displays
    Re do the loop
    Your school require you to write the code to demonstrate that you have the necessary skills to past your course
    Which compiler does your school provide?



    •   Alt28th April 2011, 18:58

      advertising

        
       

  3. #3
    Junior Member level 1
    Points: 428, Level: 4

    Join Date
    Dec 2010
    Posts
    16
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: HELP!! Digital Thermometer

    yes i know that i have to do that for the code, i am good at wiring just awful at coding. We need to use the C Compiler so C Code would be the only code i would be able to use.



  4. #4
    Member level 5
    Points: 924, Level: 6

    Join Date
    Oct 2010
    Posts
    89
    Helped
    3 / 3
    Points
    924
    Level
    6

    Re: HELP!! Digital Thermometer

    You have CCS, hi tech and mikro compiler that use C language... and there are probably more...



    (each one is unique, as in one code working for mikro will not work from hi tech without an effort to change it)



  5. #5
    Junior Member level 1
    Points: 428, Level: 4

    Join Date
    Dec 2010
    Posts
    16
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: HELP!! Digital Thermometer

    I am using the MPLAB C compiler, which is associated with HI TECH C compiler



  6. #6
    Junior Member level 1
    Points: 428, Level: 4

    Join Date
    Dec 2010
    Posts
    16
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: HELP!! Digital Thermometer

    i know its a lot to ask i am really stuck and do not understand this and would love if anyone had sample MPLAB C code for a PIC16F917 even if its for a LM35 sensor.



  7. #7
    Member level 5
    Points: 924, Level: 6

    Join Date
    Oct 2010
    Posts
    89
    Helped
    3 / 3
    Points
    924
    Level
    6

    Re: HELP!! Digital Thermometer

    it is not alot really...

    do you know how to get a lcd to work properly?



    •   Alt28th April 2011, 23:02

      advertising

        
       

  8. #8
    Advanced Member level 4
    Points: 7,022, Level: 19
    klystron's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    1,013
    Helped
    189 / 189
    Points
    7,022
    Level
    19

    Re: HELP!! Digital Thermometer

    The first post refers to a seven segment display ; 2 digits I assume.



  9. #9
    Member level 5
    Points: 924, Level: 6

    Join Date
    Oct 2010
    Posts
    89
    Helped
    3 / 3
    Points
    924
    Level
    6

    Re: HELP!! Digital Thermometer

    oh right forgot about it ^^

    i have always been a fan of lcd over segment display ^^.

    i have something around here that gets that working.


    the conversion is pretty straightforward.

    i never used those kind of sensors they use the usual formula to converte? ( 5*(x)/1023 )



  10. #10
    Junior Member level 1
    Points: 428, Level: 4

    Join Date
    Dec 2010
    Posts
    16
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: HELP!! Digital Thermometer

    no i do not know how to have an LCD work, this is my first time and i was just given a seven segment display hooked up correctly and had to find the right code using the LM34 sensor, transistors to act as switches for the seven segment, 1k resistor bank hooked up to the pic and the pic16f917. Then i was told to find the correct code using MPLAB IDE program using C to make it display on the seven segment and i have no idea what to do.



  11. #11
    Administrator
    Points: 58,287, Level: 58
    Awards:
    3rd Helpful Member
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    8,288
    Helped
    2152 / 2152
    Points
    58,287
    Level
    58
    Blog Entries
    3

    Re: HELP!! Digital Thermometer

    Here's a tutorial on using PIC to drive a seven segment display:

    Driving Seven Segment Displays - PIC with C

    This PDF combined with the other three example projects in gave you in your other thread asking help for the same problem, cross posting, provides all the info you need to finish your project.



  12. #12
    Member level 5
    Points: 924, Level: 6

    Join Date
    Oct 2010
    Posts
    89
    Helped
    3 / 3
    Points
    924
    Level
    6

    Re: HELP!! Digital Thermometer

    Multiplexed Seven Segment Display using PIC16F877A and HI-TECH C | eXtreme Electronics

    follow that one for the segment display

    and for the conversion just go to

    C:\Program Files\HI-TECH Software\PICC\9.81\samples\A2Demo

    and check out those files.

    you need to know where you connect the sensor.

    if you check the 16f877 datasheet you can see that it only on the PORTA you can convert Analog to digital if i am not mistaken.

    in the

    Code:
    void
    adc_read(unsigned char channel)
    {
    
    	ADCON0 = (channel << 3) + 0xC1;		// enable ADC, RC osc.
    	ADGO = 1;
    	while(ADGO)
    		continue;	// wait for conversion complete
    }

    ADCON0 = (channel << 3) + 0xC1; <--- this is where you tell the pic where to convert the signal.

    as i said before check the datasheet and in there there will be 1 or 2 pages about ADCON0 and ADCON1 read them, understand them, get the correct config on your code.

    and i believe... it is pretty much at the end your project ;)


    have fun.



  13. #13
    Junior Member level 1
    Points: 428, Level: 4

    Join Date
    Dec 2010
    Posts
    16
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: HELP!! Digital Thermometer

    thanks zwilorg!!

    ---------- Post added at 18:30 ---------- Previous post was at 18:27 ----------

    One quick questions. In the code it has #include <htc.h>. Would i have to download that library because in the MPLAB IDE for the PIC16F917 it doesn't have that library it says.



  14. #14
    Member level 5
    Points: 924, Level: 6

    Join Date
    Oct 2010
    Posts
    89
    Helped
    3 / 3
    Points
    924
    Level
    6

    Re: HELP!! Digital Thermometer

    Quote Originally Posted by jhunt315 View Post
    thanks zwilorg!!

    ---------- Post added at 18:30 ---------- Previous post was at 18:27 ----------

    One quick questions. In the code it has #include <htc.h>. Would i have to download that library because in the MPLAB IDE for the PIC16F917 it doesn't have that library it says.


    No problem m8.

    You maybe doing something wrong then :S

    htc.h aswell as some others are the "default" libraries of hitech compiler :S you don´t need to add them to your project. just include them...

    i can´t help you with that error :S sorry



  15. #15
    Junior Member level 1
    Points: 428, Level: 4

    Join Date
    Dec 2010
    Posts
    16
    Helped
    0 / 0
    Points
    428
    Level
    4

    Re: HELP!! Digital Thermometer

    Ok I got that problem fixed. One quick question though, looking at the code it looks like the seven segment display is connected to port D. Is that correct?



+ Post New Thread
Please login