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-11-05 16:52:02 +01:00
|
|
|
// hier pause einfügen
|
|
|
|
_delay_ms(50); // beispielsweise 50 ms => muss angepasst werden an usb kommunikation
|
|
|
|
|
2011-10-15 11:32:43 +02:00
|
|
|
}
|
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-11-05 16:52:02 +01:00
|
|
|
// (vergleichswert bei dem der Interrupt ausgelöst wird)
|
2011-10-15 11:32:43 +02:00
|
|
|
OCR1AH = 0x01;
|
|
|
|
OCR1AL = 0x00;
|
2011-08-20 15:22:47 +02:00
|
|
|
|
2011-11-05 16:52:02 +01:00
|
|
|
// anpassen auf reihenweise ausgabe
|
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-11-05 16:52:02 +01:00
|
|
|
ISR (TIMER1_COMPA_vect)
|
2011-08-20 15:22:47 +02:00
|
|
|
{
|
2011-10-19 00:04:59 +02:00
|
|
|
|
2011-11-29 19:39:57 +01:00
|
|
|
PORTD &= 0xC7; // 0b11000111
|
|
|
|
PORTD |= (1 << (cube_layer + 3)); // shift "1" to bit 3,4,5 in PortD
|
|
|
|
PORTB = ~(cube & (0xFF << (cube_layer * 9))); // set the lines 1 to 8 negated to the port b
|
|
|
|
PORTD = (~(cube & (1 << cube_layer * 9 + 8)) << 6)
|
|
|
|
| (PORTD & 0x7F); // 0b01111111 keep the ower 7 bits and set the 9. bit from the LEDCube data.
|
|
|
|
|
|
|
|
cube_layer++;
|
|
|
|
|
|
|
|
if (cube_layer > 2)
|
|
|
|
cube_layer = 0;
|
|
|
|
|
2011-08-20 15:22:47 +02:00
|
|
|
}
|
2011-10-19 00:04:59 +02:00
|
|
|
|