|
|
View previous topic :: View next topic |
Author |
Message |
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
what is the fastest way to convert signed int16 to 7-segment |
Posted: Fri Feb 07, 2014 5:03 am |
|
|
What is the fastest way to convert signed int16 (from -99 to 999) into 3 digit 7-segment appearance (including Minus sign)? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Feb 07, 2014 5:28 am |
|
|
Probably nothing too much better than the standard functions.
However it should be fractionally faster, to test for -ve, display the sign, convert to +ve, and handle as unsigned. Then all the divisions can be done with unsigned arithmetic. Then the ldiv function is the most efficient way to handle the /10's, since this gives quotient and remainder directly.
I'd suspect using this approach you could probably beat the standard operation noticeably.
Best Wishes |
|
|
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
|
Posted: Fri Feb 07, 2014 6:04 am |
|
|
Something like this?
Code: |
int16 count;
ldiv_t SCREEN[3]={0,0,0}; // 3 digits array
int digits[11]={0b00111111,0b00000110,0b01011011,0b01001111,0b01100110,0b01101101,0b01111101,0b00000111,0b01111111,0b01101111,0b01000000} ; // led map including '-'
...
...
SCREEN[0]=digits[ldiv(count,100)];
SCREEN[1]=digits[ldiv(SCREEN[0].rem,10)];
SCREEN[2]=digits[SCREEN[1].rem]
...
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Feb 07, 2014 6:52 am |
|
|
Nearly.
Remember though you need to test for the value being -ve first, and if it is, display the -, and change the sign of the value.
Try timing it with the stopwatch in MPLAB, and see how it compares with the standard version.
Also, are you happy to have the leading zeros displayed?. If not, you'll need to test for these and blank them. and (of course) you'dd need to make sure the value can't go outside the range.
Best Wishes |
|
|
|
|
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
|