/* Game of Life demo eHaJo Blinkenlights Bausatz www.eHaJo.de */ /* * Led_Matrix_mega8.c * * Created: 16.06.2012 10:54:30 * Authors: CalM -> calm@calm-solutuions.de * /joggl -> info@ehajo.de */ #define F_CPU 8000000UL #include #include #include #include #include //Es sind 16 defines noetig //Zeile 1 #define ZEILE1_PORT PORTB #define ZEILE1_PIN PB4 //Zeile 2 #define ZEILE2_PORT PORTB #define ZEILE2_PIN PB5 //Zeile 3 #define ZEILE3_PORT PORTB #define ZEILE3_PIN PB6 //Zeile 4 #define ZEILE4_PORT PORTB #define ZEILE4_PIN PB7 //Zeile 5 #define ZEILE5_PORT PORTC #define ZEILE5_PIN PC7 //Zeile 6 #define ZEILE6_PORT PORTC #define ZEILE6_PIN PC6 //Zeile 7 #define ZEILE7_PORT PORTC #define ZEILE7_PIN PC5 //Zeile 8 #define ZEILE8_PORT PORTC #define ZEILE8_PIN PC4 //Spalte 1 #define SPALTE8_PORT PORTD #define SPALTE8_PIN PD4 //Spalte 2 #define SPALTE7_PORT PORTD #define SPALTE7_PIN PD5 //Spalte 3 #define SPALTE6_PORT PORTD #define SPALTE6_PIN PD6 //Spalte 4 #define SPALTE5_PORT PORTD #define SPALTE5_PIN PD7 //Spalte 5 #define SPALTE4_PORT PORTB #define SPALTE4_PIN PB0 //Spalte 6 #define SPALTE3_PORT PORTB #define SPALTE3_PIN PB1 //Spalte 7 #define SPALTE2_PORT PORTB #define SPALTE2_PIN PB2 //Spalte 8 #define SPALTE1_PORT PORTB #define SPALTE1_PIN PB3 //Defines fuer Spalten/Zeilen an/aus #define SPALTE1_AN SPALTE1_PORT &= ~(1< 0 && j > 0) ++mask[i][j]; if(temp[i ][j-1] == 1 && j > 0) ++mask[i][j]; if(temp[i-1][j ] == 1 && i > 0 ) ++mask[i][j]; if(temp[i-1][j+1] == 1 && i > 0 && j + 1 < 8) ++mask[i][j]; if(temp[i ][j+1] == 1 && j + 1 < 8) ++mask[i][j]; if(temp[i+1][j ] == 1 && i + 1 < 8 ) ++mask[i][j]; if(temp[i+1][j-1] == 1 && i + 1 < 8 && j > 0) ++mask[i][j]; if(temp[i+1][j+1] == 1 && i + 1 < 8 && j + 1 < 8) ++mask[i][j]; if(mask[i][j] < 2 || mask[i][j] > 3) { Bildspeicher[i][j] = 0; //Sterben durch Vereinsamung/Überbevölkerung } else if(mask[i][j] == 3) { Bildspeicher[i][j] = 1; //Neues Leben schaffen } } } }*/ ISR(TIMER0_COMPA_vect) { // Timer-Compare interrupt, dieser zeigt die Matrix an cli(); ALLE_ZEILEN_AUS; SPALTE_AUS(akt_spalte); akt_spalte++; akt_spalte &= 0x07; // maximal 8 zeilen //Zeile 1 if(Bildspeicher[akt_spalte] & 0x01) ZEILE1_AN; //Zeile 2 if(Bildspeicher[akt_spalte] & 0x02) ZEILE2_AN; //Zeile 3 if(Bildspeicher[akt_spalte] & 0x04) ZEILE3_AN; //Zeile 4 if(Bildspeicher[akt_spalte] & 0x08) ZEILE4_AN; //Zeile 5 if(Bildspeicher[akt_spalte] & 0x10) ZEILE5_AN; //Zeile 6 if(Bildspeicher[akt_spalte] & 0x20) ZEILE6_AN; //Zeile 7 if(Bildspeicher[akt_spalte] & 0x40) ZEILE7_AN; //Zeile 8 if(Bildspeicher[akt_spalte] & 0x80) ZEILE8_AN; SPALTE_AN(akt_spalte); sei(); } unsigned short get_seed() { // Aus dem RAM zufallswert holen fuer random-seed unsigned short seed = 0; unsigned short *p = (unsigned short*) (RAMEND+1); extern unsigned short __heap_start; while (p >= &__heap_start + 1) seed ^= * (--p); return seed; } int main(void) { uint8_t lifetimer = 0; uint8_t i = 0; //Setup der IO PORTB=0; PORTC=0; PORTD=0; DDRB=0xFF; //Alles auf Ausgang, alles low DDRC=0xFF; //Alles auf Ausgang, alles low DDRD=0xFF; DDRD &= ~(1<4) { // wenn array 5 mal gleich dann neu berechnen //rand_array(); i = 0; lifetimer = 0; } if(lifetimer++ == 255) { // Wenn lifetimer abgelaufen dann neu berechnen -> oszillator kann mit // temp-array vergleich nicht erkannt werden... //rand_array(); } bild_copy(); // aktuelles array in das temp array kopieren } } void bild_copy() { // array in temp speicher kopieren for(uint8_t n = 0; n < 8; n++) { //Bildspeicher_temp[n] = Bildspeicher[n]; } } uint8_t bild_check() { // temp array mit bildspeicher vergleichen for(uint8_t n = 0; n < 8; n++) { for(uint8_t m = 0; m<8; m++) { //if(Bildspeicher_temp[n][m] != Bildspeicher[n][m]) return 1; } } return 0; } void zeile_an(uint8_t zeile) { switch(zeile) { case 0: ZEILE1_AN; break; case 1: ZEILE2_AN; break; case 2: ZEILE3_AN; break; case 3: ZEILE4_AN; break; case 4: ZEILE5_AN; break; case 5: ZEILE6_AN; break; case 6: ZEILE7_AN; break; case 7: ZEILE8_AN; break; default: break; } } void spalte_an(uint8_t spalte) { switch(spalte) { case 0: SPALTE1_AN; break; case 1: SPALTE2_AN; break; case 2: SPALTE3_AN; break; case 3: SPALTE4_AN; break; case 4: SPALTE5_AN; break; case 5: SPALTE6_AN; break; case 6: SPALTE7_AN; break; case 7: SPALTE8_AN; break; default: break; } }