2011-10-15 11:32:43 +02:00
|
|
|
/*
|
2011-10-19 00:04:59 +02:00
|
|
|
* Based on the code of the Mini-LED-Cube 1.0
|
2011-10-15 11:32:43 +02:00
|
|
|
*
|
2011-10-19 00:04:59 +02:00
|
|
|
* Copyright (C) 2009 Paul Wilhelm <paul@mosfetkiller.de>
|
|
|
|
* http: *mosfetkiller.de/?s=miniledcube
|
2011-10-15 11:32:43 +02:00
|
|
|
*
|
|
|
|
* Changed by Kai Lauterbach (klaute at web dot de)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
// Main
|
2011-08-20 15:22:47 +02:00
|
|
|
int main(void)
|
|
|
|
{
|
2011-10-19 00:04:59 +02:00
|
|
|
// Initialisierung
|
2011-10-15 11:32:43 +02:00
|
|
|
init();
|
|
|
|
init_usb();
|
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
// Hauptschleife
|
|
|
|
//while (1)
|
|
|
|
for (;;)
|
2011-10-15 11:32:43 +02:00
|
|
|
{
|
|
|
|
//wdt_reset(); // we are alive, so don't reset the µC
|
|
|
|
usbPoll(); // keep connected
|
|
|
|
|
|
|
|
}
|
2011-08-20 15:22:47 +02:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
// Initialisierung
|
2011-08-20 15:22:47 +02:00
|
|
|
void init()
|
|
|
|
{
|
2011-10-19 00:04:59 +02:00
|
|
|
// Ports vorbereiten
|
|
|
|
DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathoden)
|
|
|
|
PORTB = 0b11111111; // HIGH
|
2011-08-20 15:22:47 +02:00
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
DDRD = 0b1111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden)
|
2011-10-15 11:32:43 +02:00
|
|
|
PORTD = 0b1000000;
|
2011-08-20 15:22:47 +02:00
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
// Timer-Interrupt "TIMER1" vorbereiten
|
|
|
|
//cli(); //
|
2011-08-20 15:22:47 +02:00
|
|
|
|
2011-10-15 11:32:43 +02:00
|
|
|
set_bit(TIMSK, OCIE1A);
|
|
|
|
set_bit(TCCR1B, WGM12);
|
2011-08-20 15:22:47 +02:00
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
// Animations-Geschwindigkeit
|
2011-10-15 11:32:43 +02:00
|
|
|
OCR1AH = 0x01;
|
|
|
|
OCR1AL = 0x00;
|
2011-08-20 15:22:47 +02:00
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
clear_bit(TCCR1B, CS12); // Prescaler 64
|
2011-10-15 11:32:43 +02:00
|
|
|
set_bit(TCCR1B, CS11);
|
|
|
|
set_bit(TCCR1B, CS10);
|
2011-08-20 15:22:47 +02:00
|
|
|
|
2011-10-15 11:32:43 +02:00
|
|
|
sei();
|
2011-08-20 15:22:47 +02:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
// Interruptvektor von TIMER1
|
2011-08-20 15:22:47 +02:00
|
|
|
SIGNAL(SIG_OUTPUT_COMPARE1A)
|
|
|
|
{
|
2011-10-19 00:04:59 +02:00
|
|
|
|
|
|
|
// Pixel multiplexen
|
|
|
|
for (uint8_t z = 0; z < 3; z++)
|
2011-10-15 11:32:43 +02:00
|
|
|
{
|
2011-10-19 00:04:59 +02:00
|
|
|
for (uint8_t y = 0; y < 3; y++)
|
2011-10-15 11:32:43 +02:00
|
|
|
{
|
2011-10-19 00:04:59 +02:00
|
|
|
for (uint8_t x = 0; x < 3; x++)
|
2011-10-15 11:32:43 +02:00
|
|
|
{
|
2011-10-19 00:04:59 +02:00
|
|
|
uint8_t n = z * 3 + x;
|
2011-10-15 11:32:43 +02:00
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
// LED an
|
2011-10-15 11:32:43 +02:00
|
|
|
if (cube[x][y][z] == 1)
|
|
|
|
{
|
|
|
|
if (n < 8) clear_bit(PORTB, n); else clear_bit(PORTD, 6);
|
|
|
|
set_bit(PORTD, y + 3);
|
|
|
|
}
|
2011-10-19 00:04:59 +02:00
|
|
|
// ON-Time
|
|
|
|
sleep_nop(PIXEL_TON);
|
2011-10-15 11:32:43 +02:00
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
// LED aus
|
2011-10-15 11:32:43 +02:00
|
|
|
if (cube[x][y][z] == 1)
|
|
|
|
{
|
|
|
|
clear_bit(PORTD, y + 3);
|
|
|
|
if (n < 8) set_bit(PORTB, n); else set_bit(PORTD, 6);
|
|
|
|
}
|
2011-10-19 00:04:59 +02:00
|
|
|
// OFF-Time
|
|
|
|
sleep_nop(PIXEL_TOFF)
|
2011-10-15 11:32:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-19 00:04:59 +02:00
|
|
|
|
2011-08-20 15:22:47 +02:00
|
|
|
}
|
2011-10-19 00:04:59 +02:00
|
|
|
|