Simple single-color 8x8x8 LED Cube with AVRs
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

main.c 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * main.c
  3. *
  4. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  5. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  6. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  7. *
  8. * This file is part of LED-Cube.
  9. *
  10. * LED-Cube is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * LED-Cube is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. #include <stdlib.h>
  24. #include <stdint.h>
  25. #include <avr/io.h>
  26. #include <avr/interrupt.h>
  27. #include <util/delay.h>
  28. #include "uart.h"
  29. #include "cube.h"
  30. #ifndef F_CPU
  31. #define F_CPU 16000000L
  32. #endif
  33. void init(void) {
  34. uint8_t ctr = 0;
  35. DDRD = 0xFF; // Mosfets as Output
  36. DDRB = 0xFF;
  37. DDRC = 0xFF; // Latch Enable
  38. DDRA = 0xFF; // Latch Data
  39. uart_init(UART_BAUD_SELECT(19200, 16000000L));
  40. TCCR1A |= (1 << WGM12); // CTC Mode
  41. TCCR1B |= (1 << CS10); // No prescaler
  42. OCR1A = 3968;
  43. TIMSK = (1 << OCIE1A); // Enable Overflow Interrupt
  44. imgBuffer = malloc(8 * sizeof(uint8_t*));
  45. if (imgBuffer == NULL) {
  46. // TO-DO:
  47. // error!
  48. }
  49. for(ctr = 0; ctr < 8; ctr++) {
  50. imgBuffer[ctr] = malloc(8 * sizeof(uint8_t));
  51. if (imgBuffer[ctr] == NULL) {
  52. // TO-DO:
  53. // error!
  54. }
  55. }
  56. sei(); // Enable Interrupts
  57. }
  58. int main(void) {
  59. init();
  60. while (1) {
  61. PORTB |= (1 << PB0);
  62. _delay_ms(1000);
  63. PORTB &= ~(1 << PB0);
  64. _delay_ms(1000);
  65. }
  66. return 0;
  67. }