Created
February 12, 2016 10:23
-
-
Save pilinux/62fe630a7256a1915a58 to your computer and use it in GitHub Desktop.
Twiddling bit with XOR operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------- Preamble ------- // | |
#include <avr/io.h> | |
#include <util/delay.h> /* Time delay function */ | |
#define DELAYTIME 250 /* milliseconds */ | |
#define LED_PORT PORTB | |
#define LED_DDR DDRB | |
int main(void) { | |
uint8_t i; | |
uint8_t z; | |
// ------- Inits ------- // | |
LED_DDR = 0xff; /* all LEDs are configured for output */ | |
// ------- Event loop ------- // | |
while(1) { | |
LED_PORT = 0; | |
z = 0x00000000; | |
_delay_ms(DELAYTIME); | |
for (i=0; i<6; i++) { | |
z |= _BV(i); // z |= (1 << i); | |
LED_PORT ^= z; | |
_delay_ms(DELAYTIME); | |
} | |
//LED_PORT = 0; | |
_delay_ms(DELAYTIME * 2); | |
} | |
return(0); /* this line is never reached */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment