Main.c
1 | //#define F_CPU 16000000UL
| 2 | #include <avr/io.h>
| 3 | #include <avr/interrupt.h>
| 4 | #include <util/delay.h>
| 5 | #include <math.h>
| 6 |
| 7 | #define a 20
| 8 | #define b 40
| 9 | #define c 60
| 10 | #define d 80
| 11 | #define e 99
| 12 |
| 13 | uint8_t framecountMax = 100;
| 14 |
| 15 | volatile uint8_t Leds[16][8] =
| 16 | {
| 17 | {a,a,a,a,a,a,a,a},
| 18 | {a,b,b,b,b,b,b,a},
| 19 | {a,b,c,c,c,c,b,a},
| 20 | {a,b,c,e,d,c,b,a},
| 21 | {a,b,c,d,e,c,b,a},
| 22 | {a,b,c,e,d,c,b,a},
| 23 | {a,b,c,d,e,c,b,a},
| 24 | {a,b,c,e,d,c,b,a},
| 25 | {a,b,c,d,e,c,b,a},
| 26 | {a,b,c,e,d,c,b,a},
| 27 | {a,b,c,d,e,c,b,a},
| 28 | {a,b,c,e,d,c,b,a},
| 29 | {a,b,c,d,e,c,b,a},
| 30 | {a,b,c,c,c,c,b,a},
| 31 | {a,b,b,b,b,b,b,a},
| 32 | {a,a,a,a,a,a,a,a}
| 33 | };
| 34 |
| 35 | uint8_t FrameCount;
| 36 |
| 37 | ISR( TIMER0_OVF_vect ) //Overflow
| 38 | {
| 39 |
| 40 | FrameCount++;
| 41 |
| 42 |
| 43 | // Komplette Matrix einmal ausgeben, wobei nur die LED eingeschaltet
| 44 | // werden, deren Helligkeitswert kleiner/gleich dem 'FrameCount' sind
| 45 | for( uint8_t y = 0; y < 16; y++ )
| 46 | {
| 47 | uint8_t value = 0;
| 48 | uint8_t mask = 0x01;
| 49 |
| 50 | for(uint8_t x = 0; x < 8; x++ )
| 51 | {
| 52 | if( (Leds[y][x]) < FrameCount )
| 53 | value |= mask;
| 54 | mask <<= 1;
| 55 | }
| 56 |
| 57 | while(!(SPSR & ( 1<<SPIF)));
| 58 | SPDR = value;
| 59 | }
| 60 |
| 61 | while(!(SPSR & ( 1<<SPIF)));
| 62 | PORTB |= ( 1 << PB2 );
| 63 | PORTB &= ~( 1 << PB2 );
| 64 |
| 65 | if(FrameCount == framecountMax)
| 66 | {
| 67 | FrameCount = 0;
| 68 | }
| 69 |
| 70 | }
| 71 |
| 72 | int main()
| 73 | {
| 74 |
| 75 | DDRB = 0xFF; // B-Pins als Ausgang definieren (Shift)
| 76 | SPCR = ( 1 << SPE ) | ( 1 << MSTR ); // Interrupt des SPI freigegeben (Shift)
| 77 | SPDR = 0;
| 78 | TIMSK = ( 1 << TOIE0 ); // Loese Interrupt aus (PWM)
| 79 | TCCR0 = ( 1 << CS00 ); // Vorteiler auf 1 setzten (PWM)
| 80 | sei(); // Schalte Interrupts ein (PWM)
| 81 |
| 82 | while(1)
| 83 | {
| 84 | };
| 85 | }
|
|