View previous topic :: View next topic |
Author |
Message |
ILLIAS28
Joined: 11 Jan 2011 Posts: 42
|
Help convert a float into code for 7 segment |
Posted: Sat Dec 13, 2014 8:20 pm |
|
|
Hi,
can anyone help me please,
i am trying to make a thermometer with a pic16F876 and a lm335 with displaying the temperature on 3 seven segment display with common anode. The problem now is how to convert the result of the Analog to digital converter of the pic in a code for the 7segment, for example how to convert 26,7 (decimal) into a code for the 7segment.
many thanks _________________ i am newbe |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sun Dec 14, 2014 6:16 am |
|
|
The 'easy' way is to use the 'search' feature of this forum with the keywords 7 segment display multiplex. You will need to 'loop through' the 'display' function faster than 50 times a second to 'refresh' the display so our eyes see numbers and not the segments changing.You'll find lots of hits about this topic.There may be code in the 'code library' as well!
I'm assuming you've got 3 or 4 7Segment LEDs correctly wired to you PIC? If not, perhaps use Google to see how you can wire them up.These days it's actually cheaper to buy an LCD module though I'm assuming this is a school project.
hth
Jay |
|
|
ILLIAS28
Joined: 11 Jan 2011 Posts: 42
|
rehelp |
Posted: Sun Dec 14, 2014 6:59 am |
|
|
Hi,
thank you temtronic for your reponse,,i want to make a thermometer (-30 to +50°C) ,with 0,1°C precision.I have used schematic with opamps that giges 0V for -30°C and 5V for +50°C, that i apply to the ADC of the pic16F876.
but my probleme is not with multiplexing ,i have already made some projects using pic and 7segments to display integers,but this time i want to display numbers with coma(floats).
i have used the following formula to convert, the results of the 10bits ADC of the pic,in a decimal value coresponding to the mesured temperature:
t=(((read_adc())*0.00489)/0.0625)-30; where t is a float. for exemple when the value in the ADC is B'0001111000'=120(D) that means the temperature is t=-20,6°C. And when the value of the ADC is 600(D) then t=+16,9°C
my probleme now is how to separate 16,9 for exemple in 3 chiffers 1 and 6 and 9 so i can display each one on a 7segment _________________ i am newbe |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Re: rehelp |
Posted: Sun Dec 14, 2014 9:13 am |
|
|
ILLIAS28 wrote: | Hi,
thank you temtronic for your reponse,,i want to make a thermometer (-30 to +50°C) ,with 0,1°C precision.I have used schematic with opamps that giges 0V for -30°C and 5V for +50°C, that i apply to the ADC of the pic16F876.
but my probleme is not with multiplexing ,i have already made some projects using pic and 7segments to display integers,but this time i want to display numbers with coma(floats).
i have used the following formula to convert, the results of the 10bits ADC of the pic,in a decimal value coresponding to the mesured temperature:
t=(((read_adc())*0.00489)/0.0625)-30; where t is a float. for exemple when the value in the ADC is B'0001111000'=120(D) that means the temperature is t=-20,6°C. And when the value of the ADC is 600(D) then t=+16,9°C
my probleme now is how to separate 16,9 for exemple in 3 chiffers 1 and 6 and 9 so i can display each one on a 7segment |
Work on the KISS principal.
Convert your ADC reading to an int 16 in the range -300 to +500.
Display this integer directly, (with the DP between last and next to last digits lit).
Mike |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Sun Dec 14, 2014 10:45 am |
|
|
Look at the "w" format in the printf function - it allows you to insert a decimal point at a specified location in your display. Use the idea Mike Walne indicated (stay with ints - life is much simpler, faster and much smaller code) then use the "w" format to insert your decimal point.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
ILLIAS28
Joined: 11 Jan 2011 Posts: 42
|
|
Posted: Sun Dec 14, 2014 10:45 am |
|
|
Hi,
thank you very much Mike Walne;it works perfect _________________ i am newbe |
|
|
ILLIAS28
Joined: 11 Jan 2011 Posts: 42
|
|
Posted: Sun Dec 14, 2014 10:48 am |
|
|
thank you gpsmikey too _________________ i am newbe |
|
|
|