MPM controlled 16ch RGB LED dimmer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /***************************************************************************
  2. * 16ch RGB 8bit PWM controller *
  3. * *
  4. * Copyright (C) 2011 - 2012 by Olaf Rempel *
  5. * razzor AT kopf MINUS tisch DOT de *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; version 2 of the License, *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License *
  17. * along with this program; if not, write to the *
  18. * Free Software Foundation, Inc., *
  19. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  20. ***************************************************************************/
  21. #include <avr/io.h>
  22. #include <avr/interrupt.h>
  23. #include <stdio.h>
  24. #include "rgb16mpm.h"
  25. /*
  26. * using ATmega32 @8MHz:
  27. * Fuse H: 0xD9 (no bootloader, jtag disabled)
  28. * Fuse L: 0xD4 (int. 8MHz Osz, fast rising power, no BOD)
  29. *
  30. * PA0..7 -> COL1..8
  31. * PC0..7 -> COL9..16
  32. * PB0 / PD7(OC2) -> ROW2/GREEN (OC2 not used)
  33. * PB1 / PD5(OC1A) -> ROW1/RED (OC1A not used)
  34. * PB2 / PD4(OC1B) -> ROW4 (OC1B not used)
  35. * PB3(OC0) / PD6 -> ROW3/BLUE (OC0 not used)
  36. * PD0 -> RXD
  37. * PD1 -> TXD
  38. * PD2 -> /RX_TX
  39. * PD3 -> /LED
  40. */
  41. int main(void) __attribute__ ((noreturn));
  42. int main(void)
  43. {
  44. DDRD = (1<<LED);
  45. PORTD = (1<<LED);
  46. /* timer1: FCPU/1024 */
  47. TCCR1B = (1<<CS12) | (1<<CS10);
  48. TCNT1 = 0x0000;
  49. eeprom_read(1);
  50. rgb_init();
  51. mpm_init();
  52. demomode_init(nvram_data.demomode);
  53. sei();
  54. uint16_t wait = 0;
  55. while (1) {
  56. mpm_check_transfer();
  57. /* no delay or timeout reached */
  58. if (wait == 0 || (TIFR & (1<<TOV1))) {
  59. TIFR = (1<<TOV1);
  60. /* execute periodic democode */
  61. wait = demomode_run();
  62. rgb_update(COLOR_MASK, UPDATE_BLOCKING);
  63. if (wait > 0) {
  64. /* x * 8 / (8MHz/1024) */
  65. TCNT1 = 0xFFFF - (wait << 3);
  66. }
  67. }
  68. }
  69. }