简体   繁体   English

如何将Basys mx3计时器从十六进制更改为dec

[英]How to change Basys mx3 timer from hex to dec

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 :)? 我正在使用Basys mx3,并使用SSDDEMO作为十六进制中的计时器,我试图将计时器更改为十进制,但没有成功..我该怎么做:)? many thanks, this is the link to ssddemo: 非常感谢,这是ssddemo的链接:

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

In the given library, SSD_WriteDigitsGrouped() displays the four hex digits of the val argument. 在给定的库中, SSD_WriteDigitsGrouped()显示val参数的四个十六进制数字。 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. 通过首先将整数转换为二进制编码的十进制 (BCD)格式,其中每个十六进制半字节代表0到9的十进制数字值,您可以显示十进制值。

This can easily be done with a wrapper for SSD_WriteDigitsGrouped() that does the conversion. 这可以通过执行转换的SSD_WriteDigitsGrouped()包装器轻松完成。 Implement the following function, and call it in place of SSD_WriteDigitsGrouped() : 实现以下功能,并代替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 ) ;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM