dogm2.c


1
#include <avr/io.h>          
2
#include <stdint.h>
3
#define F_CPU 8000000L
4
#include <util/delay.h>
5
 
6
//Werte für Initalisierung
7
#define DISPOFF      0xAE
8
#define DISPON       0xAF
9
#define DISPSTART    0x40
10
#define PAGEADR      0xB0
11
#define COLADRL      0x00
12
#define COLADRH      0x10
13
#define ADCNORMAL    0xA0
14
#define ADCREVERSE   0xA1
15
#define COMNORMAL    0xC0
16
#define COMREVERSE   0xC8
17
#define DISPNORMAL   0xA6
18
#define DISPREVERSE  0xA7
19
#define LCDBIAS9     0xA2
20
#define LCDBIAS7     0xA3
21
#define DisplayCLR   0xA4 //Alle Pixel aus
22
#define DisplayBLK   0xA5 //Alle Pixel an
23
#define RESET        0xE2
24
#define SETPOWERCTRL 0x28
25
#define REGRESISTOR  0x20
26
#define SETCONTRAST  0x81
27
#define STATINDMODE  0xAC
28
#define BOOSTERRATIO 0xF8
29
30
31
//------------------------------------------------------------------------------
32
// Portdefinitionen
33
//------------------------------------------------------------------------------
34
35
#define DOGPORT  PORTD
36
#define DOGCS    3  //Pin CS(Display) an PD3
37
#define DOGRES    4  //Pin RES(Display) an PD4
38
#define DOGA0    5  //Pin A0(Display) an PD5
39
#define DOGSCL    7  //Pin SCL(Display) an PD7
40
#define DOGSI    6  //Pin SI(Display) an PD6
41
42
43
//------------------------------------------------------------------------------
44
// Makrodefinitionen
45
//------------------------------------------------------------------------------
46
47
#define SetBit(adr, bnr)  ( (adr) |=  (1 << (bnr)) )
48
#define ClrBit(adr, bnr)  ( (adr) &= ~(1 << (bnr)) )
49
50
#define  DOGENABLE  ClrBit(DOGPORT, DOGCS)
51
#define  DOGDISABLE SetBit(DOGPORT, DOGCS)
52
53
#define  DOGCOMMAND ClrBit(DOGPORT, DOGA0)
54
#define  DOGDATA    SetBit(DOGPORT, DOGA0)
55
56
57
58
59
//-----------------------------------------------------------------------------------------
60
 
61
void dogSPIout(char out)//erzeugt takt und überträgt daten
62
{
63
  char msk;
64
65
  msk = 0x80;
66
  do
67
   { ClrBit(DOGPORT, DOGSCL);
68
     if(out & msk)
69
        SetBit(DOGPORT, DOGSI);
70
     else
71
        ClrBit(DOGPORT, DOGSI);
72
     SetBit(DOGPORT, DOGSCL);
73
     msk >>= 1;
74
   }
75
  while(msk > 0);
76
}
77
78
//-----------------------------------------------------------------------------------------
79
80
//------Initalisierung-----------------------------------------------------------------------------------
81
82
int main(void)
83
{
84
  //ResetDOG();
85
86
  DOGENABLE;
87
  DOGCOMMAND;
88
89
  dogSPIout(DISPSTART + 0);
90
91
  dogSPIout(ADCNORMAL);
92
  dogSPIout(COMREVERSE);
93
94
  dogSPIout(DISPNORMAL);
95
  dogSPIout(LCDBIAS9);
96
  dogSPIout(SETPOWERCTRL+7);
97
  dogSPIout(BOOSTERRATIO);     dogSPIout(0);
98
  dogSPIout(REGRESISTOR+7);
99
  dogSPIout(STATINDMODE);      dogSPIout(0);
100
  dogSPIout(DISPON);
101
  dogSPIout(DisplayBLK);//Alle Pixel ansteuern
102
  DOGDISABLE;
103
}
104
105
//-----------------------------------------------------------------------------------------
106
107
108
//-----------------------------------------------------------------------------------------
109
110
void ResetDOG(void)
111
{
112
  SetBit(DOGPORT,  DOGCS);
113
  SetBit(DOGPORT, DOGSCL);
114
  SetBit(DOGPORT,  DOGSI);
115
  SetBit(DOGPORT,  DOGA0);
116
117
  ClrBit(DOGPORT,  DOGRES);
118
  _delay_ms(50);
119
  SetBit(DOGPORT,  DOGRES);
120
  _delay_ms(1);
121
}
122
123
//-----------------------------------------------------------------------------------------