Hallo,
ich bin grade dabei, einen "elektrischen Würfel" zu programmieren. Dafür
habe ich neun LEDs als Matrix und folgenden Code.
Allerdings wird die Anweisung "PORTB = get_wuerfel(0, x);" ignoriert -
wenn ich nun aber x im Code durch 0, 1 oder 2 ersetze, funktioniert
soweit alles.
Ich suche nun schon seid etwa einer Stunde, finde aber partout keinen
Fehler.
Kann mir jemand weiterhelfen?
1 | #define F_CPU 4000000
|
2 | #include <avr/io.h>
|
3 | #include <avr/interrupt.h>
|
4 | #include <util/delay.h>
|
5 |
|
6 | const int zeilen[3] = {
|
7 | 1 << PB0,
|
8 | 1 << PB1,
|
9 | 1 << PB2
|
10 | };
|
11 |
|
12 | const int spalten[3] = {
|
13 | 1 << PB3,
|
14 | 1 << PB4,
|
15 | 1 << PB5
|
16 | };
|
17 |
|
18 | int wuerfel[7][3][3] = {
|
19 | {
|
20 | { 1, 1, 1 },
|
21 | { 1, 0, 1 },
|
22 | { 1, 1, 1 }
|
23 | }
|
24 | };
|
25 |
|
26 | void delay_ms(int ms) {
|
27 | for(; ms > 0; ms--) {
|
28 | _delay_ms(1);
|
29 | }
|
30 | }
|
31 |
|
32 | void delay_us(int us) {
|
33 | for(; us > 0; us--) {
|
34 | _delay_us(1);
|
35 | }
|
36 | }
|
37 |
|
38 | int get_wuerfel(int ziffer, int linie) {
|
39 | int r = zeilen[linie];
|
40 | int i;
|
41 |
|
42 | for(i = 0; i < 3; i++) {
|
43 | if(wuerfel[ziffer][linie][i]) {
|
44 | r = r | spalten[i];
|
45 | }
|
46 | }
|
47 |
|
48 | r ^= 0b000111;
|
49 | return r;
|
50 | }
|
51 |
|
52 | int main (void) {
|
53 | DDRB = 0xFF;
|
54 | PORTB = 0xFF;
|
55 |
|
56 | while(1) {
|
57 | int x = 0;
|
58 | for(; x < 3; x++) {
|
59 | PORTB = get_wuerfel(0, x);
|
60 | delay_ms(1000);
|
61 | }
|
62 | }
|
63 |
|
64 | return 0;
|
65 | }
|