Maker Pro
Maker Pro

PIC, 4digit 7seg display

Dear all,

I need your help with my problem in displaying floating numbers on the 4 digit 7 seg display. What method do you use for displaying floating numbers on such displays?The problem I cannot over come is I have a variable voltage divider and I want to measure a voltage across it by using A/D converter. The final reading I get is a floating number and I need the number to display on the display. I have tried different approaches such try to convert the number to a string then the string to convert back to the numbers but this time to store each digit separately in an array. I have some problem using standard function in MPLAB. What approach do you take to over come this problem?
I have solutions for this: floating number to be displayed> (missing part) converting floating to a string> (missing part) storing each character in integer array as digit> mapping each digit with its hex number> applying to a port (mux)
 
To what resolution do you need to display the number?
Assign it to an int after multiplying it with (10 to the power of however many decimal places) you want.
I found using sprintf on PICs to be very space consuming.
 

KrisBlueNZ

Sadly passed away in 2015
Convert your floating point number to a string, then convert that string to characters for your display working from left to right. When you hit the decimal point in the string, set the decimal point flag in the seven segment display data for the digit you just calculated. When you have calculated the digit value for the last character in the display, stop.

Check that the floating point number always has a leading zero, i.e. it can't start with a decimal point. This should be described in the documentation for sprintf() or whatever function you're using.

If you want some code, let me know.

Yes, sprintf() uses a lot of space on a PIC. Also, floating point on a PIC is very inefficient and quite slow.
 
If you look in general chat forum, there is a thread @LiPo discharge protection that has a function printing out voltages to 2 decimal places.
 
thank you fKrisBlueNZ and shumifan50. I have decided to keep things simple and to use 3dp resolution (at least to get something on the display!). It turned out that was simpler than I thought ( well it took awhile). All I had to do is to multiply the reading by 10^3 and typecast to integer (for discarding the remaining rational part). Then the digits of the integer number I stored into integer array. And the decimal point always stayed in the same place.
 
Top