Created
October 29, 2014 14:26
-
-
Save Michcioperz/a514531d6f897e19ba94 to your computer and use it in GitHub Desktop.
1D pong on atmega8 (WIP)
This file contains hidden or 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
#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