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

what is the fastest way to convert signed int16 to 7-segment

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



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

what is the fastest way to convert signed int16 to 7-segment
PostPosted: Fri Feb 07, 2014 5:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 07, 2014 5:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 07, 2014 6:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 07, 2014 6:52 am     Reply with quote

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
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