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-12-02 14:47:59 +01:00
|
|
|
//uint8_t anim = 0;
|
2011-11-30 20:45:22 +01:00
|
|
|
|
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-12-02 14:47:59 +01:00
|
|
|
/*anim++;
|
2011-11-30 20:45:22 +01:00
|
|
|
|
2011-12-02 14:47:59 +01:00
|
|
|
if (anim >= 0)
|
2011-11-30 20:45:22 +01:00
|
|
|
{
|
|
|
|
if (cube == 0xffffffff)
|
|
|
|
cube = 0x07007007;
|
|
|
|
else if (cube == 0x07007007)
|
|
|
|
cube = 0x00000000;
|
|
|
|
else if (cube == 0x00000000)
|
|
|
|
cube = 0xffffffff;
|
2011-12-02 14:47:59 +01:00
|
|
|
|
|
|
|
anim = 0;
|
|
|
|
}*/
|
|
|
|
/*if (anim >= 40)
|
|
|
|
{
|
|
|
|
cube += 1;
|
|
|
|
|
|
|
|
if (cube > 0x07ffffff)
|
|
|
|
cube = 0;
|
|
|
|
|
|
|
|
anim = 0;
|
|
|
|
}*/
|
2011-11-30 20:45:22 +01:00
|
|
|
|
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-11-30 20:45:22 +01:00
|
|
|
DDRD = 0b01111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden)
|
|
|
|
PORTD = 0b01000000;
|
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-11-30 00:16:21 +01:00
|
|
|
set_bit(TIMSK, OCIE1A); // Interrupt für ISR COMPA
|
2011-12-02 14:47:59 +01:00
|
|
|
//set_bit(TCCR1B, WGM12); // Überlauf
|
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-11-30 00:16:21 +01:00
|
|
|
// 625d = 0x271 = 0b00000010, 0b01110001
|
|
|
|
OCR1AH = 0b00000010;
|
|
|
|
OCR1AL = 0b01110001;
|
2011-08-20 15:22:47 +02:00
|
|
|
|
2011-11-05 16:52:02 +01:00
|
|
|
// anpassen auf reihenweise ausgabe
|
2011-11-30 00:16:21 +01:00
|
|
|
// Vorteiler durch 64 (0x011) ----> CS12=0, CS11=1, CS10=1
|
2011-12-02 14:47:59 +01:00
|
|
|
//clear_bit(TCCR1B, CS12); // Prescaler 64
|
|
|
|
//set_bit(TCCR1B, CS11);
|
|
|
|
//set_bit(TCCR1B, CS10);
|
|
|
|
TCCR1B |= (1 << CS11) | (1 << CS10) | (1 << WGM12);
|
2011-11-30 00:16:21 +01:00
|
|
|
|
|
|
|
sei(); // Set enable interrupt bit (Muss gesetzt werden damit es überhaupt aufgerufen wird)
|
2011-08-20 15:22:47 +02:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:04:59 +02:00
|
|
|
// Interruptvektor von TIMER1
|
2011-11-30 00:16:21 +01:00
|
|
|
//SIGNAL(SIG_OUTPUT_COMPARE1A) // alte schreibweise
|
2011-11-05 16:52:02 +01:00
|
|
|
ISR (TIMER1_COMPA_vect)
|
2011-08-20 15:22:47 +02:00
|
|
|
{
|
2011-12-02 14:47:59 +01:00
|
|
|
|
|
|
|
// PORTD = __, 9, C, B, A,D+,D-,__
|
2011-11-30 20:45:22 +01:00
|
|
|
PORTD &= 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren
|
|
|
|
PORTD |= ((1 << cube_level) << 3); // cube_level setzen (Ebene A=0, B=1, C=2)
|
|
|
|
|
|
|
|
uint32_t tmp = cube_level * 9;
|
2011-11-30 00:16:21 +01:00
|
|
|
|
|
|
|
// PORTB = 1..8
|
|
|
|
// 0 = leuchtet, 1 = leuchtet nicht (invertiert!)
|
2011-11-30 20:45:22 +01:00
|
|
|
//PORTB = ~((uint32_t)(cube & (0b11111111 << tmp)) >> tmp);
|
|
|
|
//PORTB = ((uint32_t)(~cube & (uint32_t)(0xff << tmp)) >> tmp);
|
|
|
|
PORTB = ~((cube >> tmp) & 0xff);
|
|
|
|
|
|
|
|
// PORTD &= 0b10111111; // bereits oben erledigt
|
|
|
|
//PORTD |= ~(((uint32_t)(cube & (1 << (tmp+8))) >> (tmp+8)) << 6);
|
|
|
|
//PORTD |= (((~cube & (1 << tmp)) >> tmp) << 6);
|
|
|
|
if ( (((cube >> tmp) >> 8) & 0x01) == 1 )
|
|
|
|
PORTD &= ~(1 << 6);
|
|
|
|
else
|
|
|
|
PORTD |= (1 << 6);
|
2011-12-02 14:47:59 +01:00
|
|
|
|
2011-11-30 20:45:22 +01:00
|
|
|
//PORTD |= (1 << 6); // test to always off
|
|
|
|
|
|
|
|
cube_level++;
|
|
|
|
if (cube_level > 2) cube_level = 0;
|
2011-12-02 14:47:59 +01:00
|
|
|
|
2011-08-20 15:22:47 +02:00
|
|
|
}
|
2011-10-19 00:04:59 +02:00
|
|
|
|