1 | #define F_CPU 8000000 // clock frequency in Hz
|
2 | #define ENTPRELL_ZEIT 78
|
3 |
|
4 | #include <stdio.h>
|
5 | #include <stdlib.h>
|
6 | #include <string.h>
|
7 | #include <avr/io.h>
|
8 | #include <avr/pgmspace.h>
|
9 | #include <avr/interrupt.h>
|
10 | #include <avr/eeprom.h>
|
11 | #include <inttypes.h>
|
12 | #include <util/delay.h>
|
13 |
|
14 |
|
15 |
|
16 | // DATA PORTB.5
|
17 | // CLK PORTB.7
|
18 | // LOAD PORTD.2
|
19 |
|
20 | // LOAD_PORT |= (1<<Pin) --> 1
|
21 | // LOAD_PORT &= ~(1<<Pin) --> 0
|
22 |
|
23 | void write_spi (unsigned char data_out){ //msb first
|
24 | unsigned char loop, mask;
|
25 | mask=0x80;
|
26 | PORTD |= (1<<2); // Load 1
|
27 | for (loop=0;loop<8;loop++) {
|
28 | mask=mask>>1;
|
29 | PORTB &= ~(1<<7); // CLK 0
|
30 | if (data_out & mask) PORTB |= (1<<5); // Data 1
|
31 | else PORTB &= ~(1<<5); // DATA 0
|
32 | PORTB |= (1<<7); // CLK 1
|
33 | }
|
34 | PORTB &= ~(1<<7); // CLK 0
|
35 | PORTD &= ~(1<<2); // LOAD 0
|
36 | }
|
37 |
|
38 | //*****************************************************************
|
39 |
|
40 | void write_max7219 (unsigned char adress, unsigned char data){
|
41 | write_spi (adress);
|
42 | write_spi (data);
|
43 | }
|
44 |
|
45 | //*****************************************************************
|
46 |
|
47 | int main(void) {
|
48 | DDRB |= (1<<5);
|
49 | DDRB |= (1<<7);
|
50 |
|
51 | DDRD |= (1<<2);
|
52 |
|
53 | DDRD &= ~(1<<3); // PORTB als Eingang - Taster
|
54 | PORTD |= (1<<3); // PORTB0 auf High
|
55 |
|
56 |
|
57 | write_max7219 (0x09, 0x00); // Dekodieren ausschalten
|
58 | write_max7219 (0x0b, 0x07); // 8 Digits
|
59 | write_max7219 (0x0c, 0x01); // Display an
|
60 |
|
61 | write_max7219 (0x0f, 0x00); // Testmode aus
|
62 | write_max7219 (0x0a, 0x0a); // Helligkeit
|
63 |
|
64 | write_max7219 (0x01, 0x0f); // Daten in Spalte 1
|
65 |
|
66 | while (1) {
|
67 |
|
68 | };
|
69 | return 0;
|
70 | }
|