Statistics
| Branch: | Revision:

root / main.c @ db70b626

History | View | Annotate | Download (2.3 KB)

1
#define F_CPU 16000000L
2

    
3
#include <inttypes.h>
4
#include <avr/io.h>
5
#include <util/delay.h>
6
#include <avr/interrupt.h>
7
#include <avr/pgmspace.h>
8
#include "buffer.h"
9
//let's make our lives easier :)
10
#define PORT_(port) PORT ## port
11
#define DDR_(port)  DDR  ## port
12
#define PIN_(port)  PIN  ## port
13
#define PORT(port) PORT_(port)
14
#define DDR(port)  DDR_(port)
15
#define PIN(port)  PIN_(port)
16

    
17
// wallboard pins:
18
#define WALLBOARD_PORT         B
19
#define CLOCK_PIN         PB0
20
#define DATA_GREEN_PIN         PB3
21
#define DATA_RED_PIN         PB1
22
#define OUTPUT_ENABLE_PIN PB2
23
// address lines - please note that the address lines have to be
24
// on the same port and in the current implementation are on 0-3
25
#define ADDRESS_PORT         C
26
#define A0                 PC0
27
#define A1                 PC1
28
#define A2                 PC2
29
#define A3                 PC3
30

    
31

    
32
int main(void);
33
inline void customColor(uint8_t colorPins);
34
inline void OE(void);
35
inline void ODE(void);
36
static inline void drawEverything(void);
37
inline void printLineBasic(int16_t line, uint8_t round, uint8_t color);
38

    
39
int main(){
40
        // hardware init
41
        // clock, data and output enable
42
        DDR(WALLBOARD_PORT) |= (1<<CLOCK_PIN) | (1<<DATA_RED_PIN) | (1<<DATA_GREEN_PIN) | (1<<OUTPUT_ENABLE_PIN);
43
        // address lines:
44
        DDR(ADDRESS_PORT) |= (1<<A3) | (1<<A2) | (1<<A1) | (1<<A0);
45

    
46
        while(1){
47
                drawEverything();
48
        }
49
}
50

    
51
static inline void drawEverything(){
52
        for(uint8_t intensity = 0; intensity < 16; intensity++){
53
                for(uint8_t round = 0; round < intensity; round++){
54
                        PORT(ADDRESS_PORT) = round;
55
                        for(int16_t line = 0; line < 90; line++){
56
                                printLineBasic(line, round, (1<<DATA_GREEN_PIN));
57
                        }
58
                        OE();
59
                        _delay_us(20);
60
                        ODE();
61
                        _delay_us(1); // avoid ghosting
62
                }
63
                for(uint8_t round = intensity; round < 16; round++){
64
                        PORT(ADDRESS_PORT) = round;
65
                        for(int16_t line = 0; line < 90; line++){
66
                                printLineBasic(line, round, (1<<DATA_RED_PIN));
67
                        }
68
                        OE();
69
                        _delay_us(20);
70
                        ODE();
71
                        _delay_us(1); // avoid ghosting
72
                }
73
        }
74
}
75

    
76
inline void printLineBasic(int16_t line, uint8_t round, uint8_t color){
77
        if((1<<round) & lines[line]){
78
                customColor(color);
79
        }
80
        else{
81
                customColor(0);
82
        }
83
}
84

    
85
inline void customColor(uint8_t colorPins){
86
        PORT(WALLBOARD_PORT) |= colorPins | (1<<CLOCK_PIN);
87
        PORT(WALLBOARD_PORT) &= ~(colorPins | (1<<CLOCK_PIN));
88
}
89

    
90
inline void OE(){
91
        PORT(WALLBOARD_PORT) |= (1<<OUTPUT_ENABLE_PIN);
92
}
93

    
94
inline void ODE(){
95
        PORT(WALLBOARD_PORT) &= ~(1<<OUTPUT_ENABLE_PIN);
96
}