Bitwise Operations

Nov 13, 2009 4 Replies

Hello All,



I have a question about a function I have made. LATA is 8-bits long and all bits are set ok as in the code below, but what I want the code to do is leave the previous bit set as well and not turn it off so that at the end of the loop all bits are set.


[code] void LED_test (void) {

{ int i; LATA = 0b00000001; for (i = 0; i < 7; i++) { Delay_Us( Delay_750mS_Cnt ); LATA = LATA


or perhaps: LATA = (LATA

void LED_test( void ) { for (unsigned int LATA = 1; LATA += LATA + 1; LATA < 0x100) { /* presumably use LATA for something here... */ Delay_Us( Delay_750mS_Cnt ); /* ... or here? */ } }

Note that you could also run the algorithm backwards (assuming that the other "something" you want to do is tolerant of this change):

for (unsigned int LATA = 0xFF; LATA = LATA >> 1; LATA > 0) {

all

end

That works too. Now I have LEDs going back and forth, like a scanner. Thanks guys.

--------------------------------------- This message was sent using the comp.arch.embedded web interface on

formatting link

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required