bit shift - 74hc595 Cascading -


i have problem spi protocol. have 2 74hc595 cascade register , connected 7 segment.

i have following pattern displaying numbers:

static const uint8_t pattern[] = {     0b01000000, // 0     0b11101001, // 1     0b00100010, // 2     0b10100000, // 3     0b10001001, // 4     0b10000100, // 5     0b00000100, // 6     0b11100001, // 7     0b00000000, // 8     0b10000000, // 9     0b11101111}; // blank 

but can't execute program; there shift in bits when want display number 1 or 4 or 7.

i noticed these 3 figure ends bit 1 (the problem is):

0b1110100**1**, // 1 0b1000100**1**, // 4 0b1110000**1**, // 7 

with other numbers (0,2,3,5,6,8,9) program works well.

here program:

#define f_cpu 1000000ul #include <avr/io.h> #include <util/delay.h>  //#define chek_bit(var,pos) ((var) & (1 << (pos))) #define hc595_port   portc #define hc595_ddr    ddrc #define hc595_ds_pos pc7      //data pin (ds) pin location 42 #define hc595_sh_cp_pos pc5      //shift clock (sh_cp) pin location 40 #define hc595_st_cp_pos pc6      //store clock (st_cp) pin location 41  static const uint8_t pattern[] = {     0b01000000, // 0     0b11101001, // 1     0b00100010, // 2     0b10100000, // 3     0b10001001, // 4     0b10000100, // 5     0b00000100, // 6     0b11100001, // 7     0b00000000, // 8     0b10000000, // 9     0b11101111}; // blank  void shiftinit() {    //make data(ds), shift clock (sh_cp), store clock (st_cp) lines output    hc595_ddr|=((1<<hc595_sh_cp_pos)|(1<<hc595_st_cp_pos)|(1<<hc595_ds_pos)); }   #define hc595datahigh() (hc595_port|=(1<<hc595_ds_pos)) #define hc595datalow() (hc595_port&=(~(1<<hc595_ds_pos)))    void sendspidata(char data) {      for(int8_t i=0;i<8;i++)     {         hc595_port|=(1<<hc595_sh_cp_pos); //high          if(data & 0b10000000)          { //msb 1 output high             hc595datahigh();         }         else         {             //msb 0 output high             hc595datalow();         }          hc595_port&=(~(1<<hc595_sh_cp_pos));//low         data=data<<1;        }  }   int main(void) {       shiftinit();      hc595_port&=(~(1<<hc595_sh_cp_pos));//low   hc595_port&=(~(1<<hc595_st_cp_pos));//low      while(1)    {       hc595_port|=(1<<hc595_st_cp_pos);//high      sendspidatav2(pattern[7]);   //write data shift register    sendspidata(pattern[0]);   //write data shift register     hc595_port&=(~(1<<hc595_st_cp_pos));//low      } } 

when send 7 , 0 (11100001 01000000) receive in 2 registers 74hc595 (11100000 01000001) data not same. nb: bit in position 4 "11100001" ignored it's bp in 7 segment.

where problem? think problem in test if(data & 0b10000000).


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -