1 | // globale Variable zur Speicherung des Inhalts im 74HC595
|
2 | uint8_t com74hc595;
|
3 |
|
4 | // Konstante enthält verwendete Pins am 74HC595 durch das LCD
|
5 | const uint8_t LCD_PIN_MASK = 0b11111000;
|
6 |
|
7 | void com74hc595_out(uint8_t output) // Nibble ausgeben
|
8 | {
|
9 | output &= LCD_PIN_MASK; // ungültige Bits auf 0 setzen
|
10 | com74hc595 &= ~LCD_PIN_MASK; // alte Bits auf 0 setzen
|
11 |
|
12 | com74hc595 &= output; // neuen Inhalt generieren
|
13 |
|
14 | for(int8_t i=7;i>=0;i--) // ...und ausgeben, MSB first
|
15 | {
|
16 | if(com74hc595 & (1<<i))
|
17 | PORT_COM74HC595 &= ~(1<<PORT_SIN); // LOW an serial in
|
18 | else
|
19 | PORT_COM74HC595 |= (1<<PORT_SIN); // HIGH an serial in
|
20 |
|
21 | PORT_COM74HC595 |= (1<<PORT_SCK); // HIGH ... kurzer Puls auf SCK
|
22 | PORT_COM74HC595 &= ~(1<<PORT_SCK); // LOW ... übernimmt Wert an SIN
|
23 | }
|
24 |
|
25 | /* Strobe an RCK bringt die Daten von den Schieberegistern in die Latches */
|
26 | PORT_COM74HC595 |= (1<<PORT_RCK); // HIGH
|
27 | PORT_COM74HC595 &= ~(1<<PORT_RCK); // LOW
|
28 |
|
29 | for(uint8_t i=0;i<=2;i++) // paar Takte warten
|
30 | asm volatile ("nop" ::);
|
31 |
|
32 | PORT_LCD_EN |= (1<<PORT_EN); // HIGH ... kurzer Puls an EN übernimmt Nibble
|
33 | for(uint8_t i=0;i<=2;i++) // paar Takte warten
|
34 | asm volatile ("nop" ::);
|
35 | PORT_LCD_EN &= ~(1<<PORT_EN); // LOW
|
36 | }
|
37 |
|
38 |
|
39 | void lcd_init(void)
|
40 | {
|
41 | /* Verwendete Ports auf OUT */
|
42 | DDR_COM74HC595 |= (1<<DDR_SIN)|(1<<DDR_SCK)|(1<<DDR_RCK);
|
43 | DDR_LCD_EN |= (1<<DDR_EN);
|
44 |
|
45 | _delay_ms(250); // 250ms bis zum Start warten
|
46 |
|
47 | uint8_t tmp = (0b00110011)|(1<<LCD_RS);
|
48 |
|
49 | com74hc595_out(tmp); //4 Bit-Interface initialisieren
|
50 | _delay_ms(5);
|
51 | }
|