Search code examples
cbit-manipulationavrled

7 segment LED + 4094


I would like to display 2 number usig two shift registers 4094, some 7 segment LED and an ATmega 328p. My curent code is:

uint8_t LED[10]={0b11111100,0b01100000,0b011011010,0b011110010,0b01100110,0b10110110,0b10111110,0b111000000,0b11111110,0b11110110};


int j =Led; //input from the main
uint8_t num_1=Led/10;
uint8_t num_2=Led%10;       
Strobe=0;
uint8_t mask=0x80;
 for(uint8_t i=0; i<8; i++)
  {
      mask=mask>>1;     

    if( (LED[num_1]  & mask) ==1)
    {
        DATA= 1;
    }
    else
    {

        DATA= 0;
    }
    pulse();
}
mask=0x80;
for(uint8_t i=0; i<8; i++)
{
    mask=mask>>1;
     ;

    if( (LED[num_2]  & mask)==1)
    {
        DATA= 1;
    }
    else
    {

        DATA= 0;
    }
    pulse();
}

But of course it does not work properly. It generates only 0. Can you point me in the right direction? EDIT: I use Atmel studio 6. The purpose of the code is to generate number from 00 to 16.


Solution

  • First, you shoud put mask = mask>>1 in the end of loop.

    Second, you need to replace the
    if( (LED[num_2] & mask) == 1 ) with
    if( (LED[num_2] & mask) == mask) or just
    if( LED[num_2] & mask )

    Mask could be 0b10000000, 0b01000000,...,0b00000001.
    The result of & operation can only be the same as mask or zero.
    And the right side of == operator is 1, which is always 0b00000001.