0

i am using Basys mx3, and using the SSDDEMO which function as timer in Hex, I am trying to change the timer to decimal, with no success.. how do i do that :)? many thanks, this is the link to ssddemo:

https://github.com/Digilent/Basys-MX3-library/blob/master/Demos/SSDDemo.X/ssd.c

Dumbo
  • 13,555
  • 54
  • 184
  • 288
  • The function `SSD_WriteDigitsGrouped()` takes a 32 bit `val` where each byte represents 1 digit. Tee code does not call this function, so presumably your issue is elsewhere - to be a legitimate SO question to you need to post the relevant code, but the simple answer is that you must encode the `val` argument using _binary coded decimal_ (BCD) rather then binary. Fix the question by showing how you are calling `SSD_WriteDigitsGrouped()` and including the description of the function from the source comment, then it will be legitimised and answerable. – Clifford Dec 23 '17 at 19:55
  • Consider this: https://stackoverflow.com/questions/13247647/convert-integer-from-pure-binary-to-bcd – Clifford Dec 23 '17 at 20:00
  • Note that the code you have linked to is not "a timer", it is a library for displaying on a 4 digit 7-Segment display. The timer element is used only to multiplex the 4 digits - displaying each one for a short-time very fast in a cycle so it looks as if they are all lit. The timer aspect is irrelevant to your question and just makes your question confusing and hard to understand. – Clifford Dec 23 '17 at 20:04

1 Answers1

0

In the given library, SSD_WriteDigitsGrouped() displays the four hex digits of the val argument. By first converting your integer to binary-coded decimal (BCD) format where each hex nibble represents a decimal digit value 0 to 9, you can display decimal values.

This can easily be done with a wrapper for SSD_WriteDigitsGrouped() that does the conversion. Implement the following function, and call it in place of SSD_WriteDigitsGrouped():

void SSD_WriteDigitsGroupedBCD( unsigned int val, unsigned char dp )
{
    unsigned bcd = 0 ;
    int shift = 0 ;

    while( val > 0) 
    {
        bcd |= (val % 10) << (shift << 2) ;
        shift++ ;
        val /= 10;
    }

    SSD_WriteDigitsGrouped( bcd, dp ) ;
}
Clifford
  • 88,407
  • 13
  • 85
  • 165