CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help convert a float into code for 7 segment

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ILLIAS28



Joined: 11 Jan 2011
Posts: 42

View user's profile Send private message

Help convert a float into code for 7 segment
PostPosted: Sat Dec 13, 2014 8:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Dec 14, 2014 6:16 am     Reply with quote

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

View user's profile Send private message

rehelp
PostPosted: Sun Dec 14, 2014 6:59 am     Reply with quote

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

View user's profile Send private message

Re: rehelp
PostPosted: Sun Dec 14, 2014 9:13 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Dec 14, 2014 10:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Dec 14, 2014 10:45 am     Reply with quote

Hi,
thank you very much Mike Walne;it works perfect
_________________
i am newbe
ILLIAS28



Joined: 11 Jan 2011
Posts: 42

View user's profile Send private message

PostPosted: Sun Dec 14, 2014 10:48 am     Reply with quote

thank you gpsmikey too
_________________
i am newbe
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group