Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Created August 26, 2016 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepijndevos/76fbf714e11569f688c19bf070f51435 to your computer and use it in GitHub Desktop.
Save pepijndevos/76fbf714e11569f688c19bf070f51435 to your computer and use it in GitHub Desktop.
Attiny25 binary counter
#include <avr/io.h>
int main(void) {
PORTB = 0;
DDRB = 0b1111;
uint8_t counter = 0;
uint8_t input=0;
uint8_t previous_input=0;
while(1) {
input = PINB & (1<<PINB4);
if ((input == 0) && (previous_input != input)) {
PORTB = (counter>>1) & 0b1111;
counter++;
}
previous_input = input;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment