Skip to content

Instantly share code, notes, and snippets.

@Michcioperz
Created October 29, 2014 14:26
Show Gist options
  • Save Michcioperz/a514531d6f897e19ba94 to your computer and use it in GitHub Desktop.
Save Michcioperz/a514531d6f897e19ba94 to your computer and use it in GitHub Desktop.
1D pong on atmega8 (WIP)
#include <avr/io.h>
#include <avr/interrupt.h>
int dir = 0;
int main() {
TIMSK |= (1<<TOIE0);
DDRD = (1<<PD3);
PORTD |= (1<<PD3) | (1<<PD2);
MCUCR |= (1<<ISC11);
GICR |= (1<<INT1);
TCCR0 |= (1<<CS02) | (0<<CS01) | (0<<CS00);
DDRB = 0xFF;
PORTB = 1;
sei();
while(1);
}
ISR(SIG_OVERFLOW0) {
if (dir == 0) {
if (PORTB<<1 > 0b10000000) PORTB = 1; else PORTB <<= 1;
} else {
if (PORTB>>1 < 1) PORTB = 0b10000000; else PORTB >>= 1;
}
}
ISR(SIG_INTERRUPT0) {
if (dir == 1) {
dir = 0;
}
}
ISR(SIG_INTERRUPT1) {
if (dir == 0) {
dir = 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment