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
  SetBit(DOGPORT,  DOGRES);
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
  DDRD = 0x00;
86
87
  DOGENABLE;
88
  DOGCOMMAND;
89
90
  dogSPIout(DISPSTART + 0);
91
92
  dogSPIout(ADCNORMAL);
93
  dogSPIout(COMREVERSE);
94
95
  dogSPIout(DISPNORMAL);
96
  dogSPIout(LCDBIAS9);
97
  dogSPIout(SETPOWERCTRL+7);
98
  dogSPIout(BOOSTERRATIO);     dogSPIout(0);
99
  dogSPIout(REGRESISTOR+7);
100
  dogSPIout(STATINDMODE);      dogSPIout(0);
101
  dogSPIout(DISPON);
102
  DOGDISABLE;
103
  
104
  while(1){
105
  DOGENABLE;
106
  dogSPIout(DisplayBLK);//Alle Pixel ansteuern
107
  DOGDISABLE;
108
   _delay_ms(200);
109
  DOGENABLE;
110
  dogSPIout(DisplayCLR);//Alle Pixel ansteuern
111
  DOGDISABLE;
112
  }
113
  return 0;
114
}
115
116
//-----------------------------------------------------------------------------------------
117
118
119
//-----------------------------------------------------------------------------------------
120
121
void ResetDOG(void)
122
{
123
  SetBit(DOGPORT,  DOGCS);
124
  SetBit(DOGPORT, DOGSCL);
125
  SetBit(DOGPORT,  DOGSI);
126
  SetBit(DOGPORT,  DOGA0);
127
128
  ClrBit(DOGPORT,  DOGRES);
129
  _delay_ms(50);
130
  SetBit(DOGPORT,  DOGRES);
131
  _delay_ms(1);
132
}
133
134
//-----------------------------------------------------------------------------------------