Created
October 15, 2012 16:02
-
-
Save l3kn/3893299 to your computer and use it in GitHub Desktop.
Addition to l3cube
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
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <util/delay.h> | |
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) | |
#define FPS 1; | |
volatile int frame = 0; | |
uint8_t cube[4][4]; | |
int mode = 0; | |
int lvl_arr[4] = {0b1000,0b0100,0b0010,0b0001}; | |
int frame_arr[5][4] = {{0b1001,0b1001,0b1111,0b1001}, {0b1111,0b1000,0b1110,0b1111}, {0b1111,0b1000,0b1000,0b1000}, {0b1111,0b1000,0b1000,0b1000},{0b1111,0b1001,0b1001,0b1111}}; | |
int main(void) | |
{ | |
int lvl; | |
// set for 16 MHz clock, and make sure the LED is off | |
CPU_PRESCALE(0); | |
// set b & d ports as output | |
DDRD = 255; | |
DDRC = 255; | |
DDRB = 255; | |
//setup the interrupt-timer | |
TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode | |
TIMSK1 |= (1 << OCIE1A); // Enable CTC interrupt | |
sei(); // Enable global interrupts | |
OCR1A = 15624/FPS; // Set CTC compare value to 1Hz at 1MHz AVR clock, with a prescaler of 64 | |
TCCR1B |= ((1 << CS10) | (1 << CS12)); // Start timer at Fcpu/64 | |
while (1) | |
{ | |
for(lvl=0;lvl<=3;lvl++) | |
{ | |
PORTB = lvl_arr[lvl]; | |
switch(mode) | |
{ | |
case 0: | |
PORTD = frame_arr[frame][lvl] + 16*frame_arr[frame][lvl]; | |
PORTC = frame_arr[frame][lvl] + 16*frame_arr[frame][lvl]; | |
_delay_ms(2); | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
} | |
ISR(TIMER1_COMPA_vect) | |
{ | |
frame++; | |
if (frame > 4) | |
{ | |
frame=0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment