Bitwise Operations

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

Reply to
drkidd22
Loading thread data ...

Reply to
Arlet

or perhaps: LATA = (LATA

Reply to
Mark Borgerson

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) {

Reply to
D Yuniskis

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

Reply to
drkidd22

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.