MezData-Logo

Matrixanzeige 8*7 mit ATtiny2313

Demo

Prototyp

Tool zum Generieren der Muster

Quelle: https://github.com/stocka/LEDCube-Pattern-Tool


Quellcode [Matrix1c.c]
/* Matrixanzeige (c) Oliver Mezger 15.02.2011
   Firmware fuer Prototyp 8x7 LED-Matrix
   Distributed under Creative Commons 3.0 -- Attib & Share Alike
   Synopsis:
    http://www.tvbgone.com/mfaire/ledcubekit/ledcube.c
	http://www.cse.ohio-state.edu/~stocka/LEDCube/
*/
 
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
 
struct imElt {
  unsigned char z[7];
  unsigned long int imageDuration;
}
const imageTab[] PROGMEM = {
 { 0b10010010, 0b10010010, 0b10010010, 0b11110010, 0b10010010, 0b10010010, 0b10010010, 10000 }, 
 { 0b11100111, 0b01001000, 0b01001000, 0b01001011, 0b01001001, 0b01001001, 0b01000110, 10000 }, 
 { 0b00000000, 0b00000000, 0b00101000, 0b00010000, 0b00101000, 0b00000000, 0b00000000, 2240 }, 
 { 0b00000000, 0b01111100, 0b01000100, 0b01000100, 0b01000100, 0b01111100, 0b00000000, 2240 }, 
 { 0b11111110, 0b10000010, 0b10000010, 0b10000010, 0b10000010, 0b10000010, 0b11111110, 2240 }, 
 { 0b10000010, 0b01000100, 0b00101000, 0b00010000, 0b00101000, 0b01000100, 0b10000010, 2240 }, 
 { 0b01000000, 0b00100010, 0b00101100, 0b00010000, 0b01101000, 0b10001000, 0b00000100, 2240 }, 
 { 0b00010000, 0b00010000, 0b00010000, 0b11111110, 0b00010000, 0b00010000, 0b00010000, 2240 }, 
 { 0b00111000, 0b01010100, 0b10010010, 0b11111110, 0b10010010, 0b01010100, 0b00111000, 2240 }, 
 { 0b00111000, 0b01000100, 0b10000010, 0b10000010, 0b10000010, 0b01000100, 0b00111000, 2240 }, 
 { 0b00010000, 0b00101000, 0b01000100, 0b10000010, 0b01000100, 0b00101000, 0b00010000, 2240 }, 
 { 0b00000000, 0b00010000, 0b00101000, 0b01000100, 0b00101000, 0b00010000, 0b00000000, 2240 }, 
 { 0b00000000, 0b00000000, 0b00010000, 0b00101000, 0b00010000, 0b00000000, 0b00000000, 2240 }, 
 { 0b00000000, 0b00000000, 0b00000000, 0b00010000, 0b00000000, 0b00000000, 0b00000000, 5000 }, 
 { 0b00000000, 0b11100111, 0b00011000, 0b00011000, 0b00000000, 0b01000010, 0b00111100, 15000 }, 
 { 0b01000010, 0b11100111, 0b01011010, 0b00011000, 0b00000000, 0b01000010, 0b00111100, 15000 }, 
 { 0b00000000, 0b01000010, 0b01011010, 0b00000000, 0b00111100, 0b01000010, 0b00111100, 15000 }, 
 { 0b01000010, 0b10100101, 0b01000010, 0b00011000, 0b00000000, 0b00100100, 0b00011000, 10000 }, 
 { 0, 0, 0, 0, 0, 0, 0, 0 },
};
 
void displayImage(int index){
  unsigned long int duration = pgm_read_dword( &imageTab[index].imageDuration );
  unsigned char zeile=1,p=0;
  for (int i=0; i<(duration/(10)); i++) {
	PORTB = pgm_read_byte( &imageTab[index].z[p] );
	PORTD = zeile;
	_delay_ms(1);
    zeile = zeile <<1;
	p++;
    if (zeile == 128){
	  zeile =1;
	  p=0;
	}
  }
}
 
int main(){
  DDRB = 0xff; // PB als Ausgang Spalten
  PORTB = 0xff;
  DDRD = 0xff;  // PD als Ausgang Zeilen
  while (1){ // Endlosschleife
    int i = 0;
    do {
      displayImage(i);
      i++;
    } while (pgm_read_byte(&imageTab[i].imageDuration) != 0);
  }
}
 

Projekt mit 16*8 Matrix

Quellcode [Matrix16x8c.c]
/* Matrixanzeige (c) Oliver Mezger 13.04.2011
   Firmware fuer Prototyp 16x8 LED-Matrix
   Distributed under Creative Commons 3.0 -- Attib & Share Alike
   Synopsis:
    http://www.tvbgone.com/mfaire/ledcubekit/ledcube.c
    http://www.cse.ohio-state.edu/~stocka/LEDCube/
*/
 
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
 
struct imElt {
  unsigned int z[8];
  unsigned long int imageDuration;
}
const imageTab[] PROGMEM = {
 { 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000110000000, 0b0000000110000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 1000 }, 
 { 0b0000000000000000, 0b0000000000000000, 0b0000001111000000, 0b0000001001000000, 0b0000001001000000, 0b0000001111000000, 0b0000000000000000, 0b0000000000000000, 1000 }, 
 { 0b0000000000000000, 0b0000000000000000, 0b0000011111100000, 0b0000010000100000, 0b0000010000100000, 0b0000011111100000, 0b0000000000000000, 0b0000000000000000, 1000 }, 
 { 0b0000000000000000, 0b0000111111110000, 0b0000100000010000, 0b0000100000010000, 0b0000100000010000, 0b0000100000010000, 0b0000111111110000, 0b0000000000000000, 1000 }, 
 { 0b0000000000000000, 0b0001111111111000, 0b0001000000001000, 0b0001000000001000, 0b0001000000001000, 0b0001000000001000, 0b0001111111111000, 0b0000000000000000, 1000 }, 
 { 0b0011111111111100, 0b0010000000000100, 0b0010000000000100, 0b0010000000000100, 0b0010000000000100, 0b0010000000000100, 0b0010000000000100, 0b0011111111111100, 1000 }, 
 { 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 1000 }, 
 { 0b1010101010101010, 0b0101010101010101, 0b1010101010101010, 0b0101010101010101, 0b1010101010101010, 0b0101010101010101, 0b1010101010101010, 0b0101010101010101, 30000 },
 { 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000110000000, 0b0000000110000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 1000 }, 
 { 0b0000000000000000, 0b0000000000000000, 0b0000001111000000, 0b0000001001000000, 0b0000001001000000, 0b0000001111000000, 0b0000000000000000, 0b0000000000000000, 1000 }, 
 { 0b0000000000000000, 0b0000000000000000, 0b0000011111100000, 0b0000010000100000, 0b0000010000100000, 0b0000011111100000, 0b0000000000000000, 0b0000000000000000, 1000 }, 
 { 0b0000000000000000, 0b0000111111110000, 0b0000100000010000, 0b0000100000010000, 0b0000100000010000, 0b0000100000010000, 0b0000111111110000, 0b0000000000000000, 1000 }, 
 { 0b0000000000000000, 0b0001111111111000, 0b0001000000001000, 0b0001000000001000, 0b0001000000001000, 0b0001000000001000, 0b0001111111111000, 0b0000000000000000, 1000 }, 
 { 0b0011111111111100, 0b0010000000000100, 0b0010000000000100, 0b0010000000000100, 0b0010000000000100, 0b0010000000000100, 0b0010000000000100, 0b0011111111111100, 1000 }, 
 { 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 0b0100000000000010, 1000 },  
 { 0b0101010101010101, 0b1010101010101010, 0b0101010101010101, 0b1010101010101010, 0b0101010101010101, 0b1010101010101010, 0b0101010101010101, 0b1010101010101010, 30000 }, 
 { 0b0000000000000000, 0b1111101111010111, 0b0010001000010010, 0b0010001000010010, 0b0010001011010010, 0b0010001001010010, 0b0010001111010010, 0b0000000000000000, 35000 }, 
 { 0b0000000000000000, 0b1111010101000111, 0b1001010101000001, 0b1111010101000010, 0b1100010101000010, 0b1010010101000100, 0b1001011101110111, 0b0000000000000000, 40000 }, 
 { 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 0b0000000000000000, 5120 }, 
 { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
};
 
void displayImage(int index){
  unsigned long int duration = pgm_read_dword( &imageTab[index].imageDuration );
  unsigned char zeile=1,p=0;
  unsigned int a;
  for (int i=0; i<(duration/(20)); i++) {
    a = pgm_read_word( &imageTab[index].z[p] ); // lies Wort
    PORTC = a;    // oberer Teil hinten
    PORTD = a>>8; // unter Teil vorne
    PORTB = zeile;
    _delay_ms(1);
    zeile = zeile <<1;
    p++;
    if (zeile == 0){
      zeile =1;
      p=0;
    }
  }
}
 
int main(){
  DDRB = 0xff;  // PB als Ausgang Zeilen
  DDRC = 0xff;  // PC als Ausgang Spalten
  DDRD = 0xff;  // PD als Ausgang Spalten
  while (1){ // Endlosschleife   
    int i = 0;
    do {
      displayImage(i);
      i++;
    } while (pgm_read_dword(&imageTab[i].imageDuration) != 0);
  }
}