bit shift proteus led

Hi forum i have small problem with bit shift I tried simulate snake from led diods in proteus
I want to led diod move from right and move from left together but when i used this code: led diod from right is active only one and from left is active only 2.Please help ty

1
2
3
4
5
6
7
8
9
10
11
12
13
   DDRD = 0xff;
   DDRD=0b10000001;
   
    while(1) {
    delay_ms(1000);
    DDRD>>=1;
     delay_ms(1000);
     DDRD<<=1; 
    
      
        }
    }
You probably want to have separate numbers for the left & right LEDs - bitshift each one independently, then OR them together when you assign a value to DDRD:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
   LEFT  = 0b10000000;
   RIGHT = 0b00000001;
   
   while(1)
   {
      delay_ms(1000);
      DDRD = LEFT | RIGHT;
      LEFT>>=1;
      RIGHT<<=1;
      // If LEFT & RIGHT have reached the end, reset LEFT & RIGHT 
      //   so that the sequence continues on forever 
      if( (LEFT | RIGHT) == 0b10000001 )
      {
         LEFT  = 0b10000000;
         RIGHT = 0b00000001;
      }
   }


How's that?
Last edited on
Topic archived. No new replies allowed.