1 | /******************************************
|
2 | * Routine für Dog-M Displays *
|
3 | * mit ST7036 Controller im SPI-Mode *
|
4 | ******************************************
|
5 | * *
|
6 | * Nur 1-Zeilige Version vorerst... *
|
7 | * Beschaltung laut Datenblatt EA-DOG-M *
|
8 | * *
|
9 | * (C)2007 Christopher Müller *
|
10 | * shorty@shortysfastlane.de *
|
11 | * *
|
12 | * www.shortysfastlane.de *
|
13 | * *
|
14 | * Stand: 17.Okt.2007 *
|
15 | ******************************************/
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | // Veränderliche Variablen
|
21 | //*******************************************
|
22 | //#define F_CPU 1600000UL //Clockspeed in Hz
|
23 | #define DDR_SPI DDRB // DD-Register des SPI-Ports
|
24 | #define DD_MOSI DDB3 // Port/Pin des MOSI
|
25 | #define DD_SCK DDB5 // Port/Pin des SCK
|
26 | #define DD_RS DDRB // DDR von RS
|
27 | #define PORT_RS PORTB // Port an dem RS ist
|
28 | #define PIN_RS PINB2 // Pin an dem RS ist
|
29 | #define DD_CSB DDRB // DDR von CSB
|
30 | #define PORT_CSB PORTB // Port an dem CSB ist
|
31 | #define PIN_CSB PINB1 // Pin an dem CSB ist
|
32 | #define VOLTAGE 5 // Voltage auf 5 oder 3 Volt
|
33 | #define CONTRAST 0x70 // Von 0x70 bis 0x7F Hexadezimal
|
34 | //*******************************************
|
35 | #include <util/delay.h>
|
36 |
|
37 |
|
38 |
|
39 | void InitSPI (void)
|
40 | {
|
41 |
|
42 | /* Set MOSI and SCK output, andere input */
|
43 | DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK);
|
44 | /* aktiviere SPI, Master, setze clock rate fck/16 */
|
45 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
|
46 |
|
47 | // Setze CSB als Ausgang und low
|
48 | DD_CSB |= (1<<PIN_CSB);
|
49 | PORT_CSB &= ~(1 << PIN_CSB);
|
50 |
|
51 | // Setze RS-Pin als Ausgang und low
|
52 | DD_RS |= (1<<PIN_RS);
|
53 | PORT_RS &= ~(1 << PIN_RS);
|
54 |
|
55 | }
|
56 |
|
57 |
|
58 |
|
59 | void Disp_Command(int Data)
|
60 | {
|
61 |
|
62 | // Command Mode vorbeireiten; setze RS low
|
63 | PORT_RS &= ~(1 << PIN_RS);
|
64 |
|
65 | /* Starte übertragung */
|
66 | SPDR = Data;
|
67 | /* Warte auf ende der Übertragung */
|
68 | while(!(SPSR & (1<<SPIF)));
|
69 |
|
70 | //Übertragung abschließen durch RS toggle
|
71 | PORT_RS = (1 << PIN_RS); // high
|
72 | PORT_RS &= ~(1 << PIN_RS); //low
|
73 |
|
74 | _delay_us(50); // warte auf Display
|
75 | }
|
76 |
|
77 |
|
78 |
|
79 | void Disp_Byte(int Data)
|
80 | {
|
81 | // Data Mode vorbeireiten; setze RS high
|
82 | PORT_RS = (1 << PIN_RS);
|
83 |
|
84 | /* Starte übertragung */
|
85 | SPDR = Data;
|
86 | /* Warte auf ende der Übertragung */
|
87 | while(!(SPSR & (1<<SPIF)));
|
88 |
|
89 | //Übertragung abschließen durch RS toggle
|
90 | PORT_RS &= ~(1 << PIN_RS); //low
|
91 | PORT_RS = (1 << PIN_RS); // high
|
92 |
|
93 | _delay_us(50); // warte auf Display
|
94 | }
|
95 |
|
96 |
|
97 |
|
98 | void Disp_Char(char cData)
|
99 | {
|
100 | // Data Mode vorbeireiten; setze RS high
|
101 | PORT_RS = (1 << PIN_RS);
|
102 |
|
103 | /* Starte übertragung */
|
104 | SPDR = cData;
|
105 | /* Warte auf ende der Übertragung */
|
106 | while(!(SPSR & (1<<SPIF)));
|
107 |
|
108 | //Übertragung abschließen durch RS toggle
|
109 | PORT_RS &= ~(1 << PIN_RS); //low
|
110 | PORT_RS = (1 << PIN_RS); // high
|
111 |
|
112 | _delay_us(50); // warte auf Display
|
113 | }
|
114 |
|
115 |
|
116 |
|
117 | void Disp_String(char *cData)
|
118 | {
|
119 | // Data Mode vorbeireiten; setze RS high
|
120 | PORT_RS = (1 << PIN_RS);
|
121 |
|
122 | while (*cData)
|
123 | {
|
124 | /* Starte übertragung */
|
125 | SPDR = *cData;
|
126 |
|
127 | /* Warte auf ende der Übertragung */
|
128 | while(!(SPSR & (1<<SPIF)));
|
129 |
|
130 | //Übertragung abschließen durch RS toggle
|
131 | PORT_RS &= ~(1 << PIN_RS); //low
|
132 | PORT_RS = (1 << PIN_RS); // high
|
133 |
|
134 | _delay_us(50); // warte auf Display
|
135 | ++cData;
|
136 | }
|
137 | }
|
138 |
|
139 |
|
140 |
|
141 | void Disp_Clear(void)
|
142 | {
|
143 |
|
144 | Disp_Command(0x01); // Disoplay löschen
|
145 | _delay_ms(25); // Auf Display warten
|
146 | Disp_Command(0x06); // Entry Mode set - Display wartet auf Eingabe
|
147 | _delay_ms(15); // Auf Display warten
|
148 |
|
149 | }
|
150 |
|
151 | // zeile =1 oder 2, Position bei 0 beginnend
|
152 | void Disp_Pos(int zeile, int xPos)
|
153 | {
|
154 | if (zeile == 2)
|
155 | xPos += 0x40;
|
156 |
|
157 | Disp_Command(0x80|xPos); // Display Position Set DDRAM Address
|
158 | _delay_ms(25); // Auf Display warten
|
159 |
|
160 | }
|
161 |
|
162 |
|
163 |
|
164 | void InitDisp(void)
|
165 | {
|
166 | _delay_ms(80); // Warte auf Display
|
167 |
|
168 | int BIAS,PWR,FOLLOW;
|
169 |
|
170 | if (VOLTAGE == 5)
|
171 | {
|
172 | BIAS = 0x1c;
|
173 | PWR = 0x52;
|
174 | FOLLOW = 0x69;
|
175 | }
|
176 | else
|
177 | {
|
178 | BIAS = 0x14;
|
179 | PWR = 0x55;
|
180 | FOLLOW = 0x6d;
|
181 | }
|
182 |
|
183 | Disp_Command(0x39); // Function Set ; 8 Bit; 1Zeile, Istr.Tab 1
|
184 | Disp_Command(BIAS); // Bias Set
|
185 | Disp_Command(PWR); // Power Controll
|
186 | Disp_Command(0x69); // Follower Controll
|
187 | Disp_Command(CONTRAST); // Kontrast setzten
|
188 | Disp_Command(0x0c); // Display ein, kein Cursor, kein Blinken
|
189 | Disp_Command(0x01); // Disoplay löschen
|
190 | _delay_ms(50); // Auf Display warten
|
191 | Disp_Command(0x06); // Entry Mode set - Display wartet auf Eingabe
|
192 | _delay_ms(50); // Auf Display warten
|
193 |
|
194 | }
|