74hc164 + 2x 4511 bcd decoder


hi everyone.
i'm trying use 2 bcd decoder 1 74hc164.
if use

code: [select]
shiftout(data, clock, lsbfirst,b10011001);

i'll number 9 in both displays.

i need make function convert dec number i.e 34  into b00110100  so can send 74hc164.

thanks everyone!

cheers

the value 34 consists of 2 digits. can separate 2 digits separate variables:

code: [select]
byte num = 34;
byte digit1 = num / 10; // digit1 3
byte digit2 = num % 10; // digit2 4


now, need convert each digit binary representation.

code: [select]
byte b[4];
if(digit >= 8)
{
   b[0] = 1;   // if digit 8 or 9, first position 1
   digit -= 8;
}
else
  b[0] = 0; // otherwise, it's 0

// digit 7 or less
if(digit >= 4)
{
   b[1] = 1; // if digit 4, 5, 6, or 7, 2nd position 1
   digit -= 4;
}
else
   b[1] = 0; // otherwise, it's 0

// digit 3 or less
if(digit >= 2)
{
   b[2] = 1; // if digit 2 or 3, 3rd position 1
   digit -= 2;
}
else
  b[2] = 0;  // otherwise, it's 0

// digit 0 or 1
b[3] = digit;


there shorter ways of doing this, works, , easy understand.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > 74hc164 + 2x 4511 bcd decoder


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums