81 lines
2.8 KiB
C
81 lines
2.8 KiB
C
/***************************************************************************
|
|
* 16ch RGB 8bit PWM controller *
|
|
* *
|
|
* Copyright (C) 2011 - 2012 by Olaf Rempel *
|
|
* razzor AT kopf MINUS tisch DOT de *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; version 2 of the License, *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
#include <avr/io.h>
|
|
#include <avr/interrupt.h>
|
|
#include <stdio.h>
|
|
|
|
#include "rgb16mpm.h"
|
|
|
|
/*
|
|
* using ATmega32 @8MHz:
|
|
* Fuse H: 0xD9 (no bootloader, jtag disabled)
|
|
* Fuse L: 0xD4 (int. 8MHz Osz, fast rising power, no BOD)
|
|
*
|
|
* PA0..7 -> COL1..8
|
|
* PC0..7 -> COL9..16
|
|
* PB0 / PD7(OC2) -> ROW2/GREEN (OC2 not used)
|
|
* PB1 / PD5(OC1A) -> ROW1/RED (OC1A not used)
|
|
* PB2 / PD4(OC1B) -> ROW4 (OC1B not used)
|
|
* PB3(OC0) / PD6 -> ROW3/BLUE (OC0 not used)
|
|
* PD0 -> RXD
|
|
* PD1 -> TXD
|
|
* PD2 -> /RX_TX
|
|
* PD3 -> /LED
|
|
*/
|
|
|
|
int main(void) __attribute__ ((noreturn));
|
|
int main(void)
|
|
{
|
|
DDRD = (1<<LED);
|
|
PORTD = (1<<LED);
|
|
|
|
/* timer1: FCPU/1024 */
|
|
TCCR1B = (1<<CS12) | (1<<CS10);
|
|
TCNT1 = 0x0000;
|
|
|
|
eeprom_read(1);
|
|
rgb_init();
|
|
mpm_init();
|
|
|
|
demomode_init(nvram_data.demomode);
|
|
|
|
sei();
|
|
|
|
uint16_t wait = 0;
|
|
while (1) {
|
|
mpm_check_transfer();
|
|
|
|
/* no delay or timeout reached */
|
|
if (wait == 0 || (TIFR & (1<<TOV1))) {
|
|
TIFR = (1<<TOV1);
|
|
|
|
/* execute periodic democode */
|
|
wait = demomode_run();
|
|
rgb_update(COLOR_MASK, UPDATE_BLOCKING);
|
|
|
|
if (wait > 0) {
|
|
/* x * 8 / (8MHz/1024) */
|
|
TCNT1 = 0xFFFF - (wait << 3);
|
|
}
|
|
}
|
|
}
|
|
}
|