/*************************************************************************** * C based avr910 / avr109 ISP Adapter * * * * Copyright (C) 2006 - 20011 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 #include #include /* * using ATmega16 @7.3728MHz: * Fuse H: 0xDA (512 words bootloader, jtag disabled) * Fuse L: 0xFF (ext. Crystal) */ #define F_CPU 7372800 #include #define BAUDRATE 9600 #define UART_CALC_BAUDRATE(baudRate) (((uint32_t)F_CPU) / (((uint32_t)baudRate)*16) -1) #if 0 static int uart_putchar(char c, FILE *stream) { if (c == '\n') uart_putchar('\r', stream); loop_until_bit_is_set(UCSRA, UDRE); UDR = c; return 0; } static FILE uart = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); #endif static uint8_t valueR[16] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, // 0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, }; static uint8_t valueG[16] = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0, 0xB0, // 0x48, 0x58, 0x68, 0x78, 0x88, 0x98, 0xA8, 0xB8, }; static uint8_t valueB[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF1, 0xF3, 0xF5, 0xF7, 0xF9, 0xFB, 0xFD, 0xFF, // 0xF0, 0xF2, 0xF4, 0xF6, 0xF8, 0xFA, 0xFC, 0xFE, }; static uint8_t *current_comp_reg; static uint8_t comp_regR[16]; static uint8_t comp_regG[16]; static uint8_t comp_regB[16]; static uint16_t *current_port_reg; static uint16_t port_regR[16 +1]; static uint16_t port_regG[16 +1]; static uint16_t port_regB[16 +1]; static uint8_t current_color; ISR(SIG_OVERFLOW0) { #if 0 /* switch color */ switch (current_color) { case 0: /* RED */ current_comp_reg = comp_regR; current_port_reg = port_regR; current_color = 1; break; case 1: /* GREEN */ current_comp_reg = comp_regG; current_port_reg = port_regG; current_color = 2; break; case 2: /* BLUE */ current_comp_reg = comp_regB; current_port_reg = port_regB; current_color = 0; break; } #else current_comp_reg = comp_regR; current_port_reg = port_regR; #endif uint16_t port_reg = *current_port_reg++; PORTA = (port_reg & 0xFF); PORTC = (port_reg >> 8) & 0xFF; /* enable compare interrupts if any pin is active */ if (port_reg != 0x0000) { TIMSK |= (1<> 8) & 0xFF; /* no further compare interrupts needed */ if (port_reg == 0x0000) { TIMSK &= ~(1<>8) & 0xFF; UBRRL = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF); /* enable usart with 8n1 */ UCSRB = (1<