1 | //*********************************************************************
|
2 | // Das LCD-Display ist EA DODS102W-6 mit 102x64 Pixel //
|
3 | // Der µC ist ein ATMEL ATtiny84 //
|
4 | // Spannungsregler LT1129-3.3V //
|
5 | //*********************************************************************
|
6 | #include <avr/io.h>
|
7 | //*********************************************************************
|
8 | #define LCD_SDA PB0
|
9 | #define LCD_SCK PA0
|
10 | #define LCD_CD PA1
|
11 | #define LCD_RST PA2
|
12 | #define LCD_CS0 PA3
|
13 |
|
14 | #define PORTA_Init DDRA = (1<<LCD_SCK)|(1<<LCD_CD)|(1<<LCD_RST)|(1<<LCD_CS0)
|
15 | #define PORTB_Init DDRB = (1<<LCD_SDA)|(1<<PB1)
|
16 | //*********************************************************************
|
17 | #define LCD_SDA_0 PORTB &= ~(1 << LCD_SDA)
|
18 | #define LCD_SDA_1 PORTB |= (1 << LCD_SDA)
|
19 | #define LCD_SCK_0 PORTA &= ~(1 << LCD_SCK)
|
20 | #define LCD_SCK_1 PORTA |= (1 << LCD_SCK)
|
21 | #define LCD_CD_0 PORTA &= ~(1 << LCD_CD)
|
22 | #define LCD_CD_1 PORTA |= (1 << LCD_CD)
|
23 | #define LCD_RST_0 PORTA &= ~(1 << LCD_RST)
|
24 | #define LCD_RST_1 PORTA |= (1 << LCD_RST)
|
25 | #define LCD_CS0_0 PORTA &= ~(1 << LCD_CS0)
|
26 | #define LCD_CS0_1 PORTA |= (1 << LCD_CS0)
|
27 | //*********************************************************************
|
28 | unsigned short int get_adc(unsigned char);
|
29 | void LCD_Init();
|
30 | void LCD_Command(unsigned char);
|
31 | void LCD_Data(unsigned char);
|
32 | void LCD_Byte(unsigned char);
|
33 | void Pause(unsigned long int);
|
34 | //*********************************************************************
|
35 | int main(void)
|
36 | {
|
37 | LCD_Init();
|
38 | while(1)
|
39 | {
|
40 | Pause(100000); // ca. 200ms Pause
|
41 | LCD_Data(0x55); // Bitmuster 01010101 ausgeben
|
42 | PINB = (1<<PB1); // die Led an PB1 toggelt
|
43 | }
|
44 | }
|
45 | //*********************************************************************
|
46 | void LCD_Init()
|
47 | {
|
48 | PORTA_Init;
|
49 | PORTB_Init;
|
50 | LCD_CS0_0;
|
51 | LCD_RST_0;
|
52 | Pause(20000);
|
53 | LCD_RST_1;
|
54 | Pause(20000);
|
55 | LCD_Command(0x40);
|
56 | LCD_Command(0xA1);
|
57 | LCD_Command(0xC0);
|
58 | LCD_Command(0xA4);
|
59 | LCD_Command(0xA6);
|
60 | LCD_Command(0xA2);
|
61 | LCD_Command(0x2F);
|
62 | LCD_Command(0x27);
|
63 | LCD_Command(0x81);
|
64 | LCD_Command(0x10);
|
65 | LCD_Command(0xFA);
|
66 | LCD_Command(0x90);
|
67 | LCD_Command(0xAF);
|
68 |
|
69 | LCD_Command(0x03); //Set the SRAM column address CA[3..0]
|
70 | LCD_Command(0x13); //Set the SRAM column address CA[7..4]
|
71 | LCD_Command(0xB0); //Set the SRAM page address PA=0..7
|
72 | }
|
73 | //*********************************************************************
|
74 | void LCD_Command(unsigned char Data)
|
75 | {
|
76 | LCD_CD_0;
|
77 | LCD_Byte(Data);
|
78 | }
|
79 | //*********************************************************************
|
80 | void LCD_Data(unsigned char Data)
|
81 | {
|
82 | LCD_CD_1;
|
83 | LCD_Byte(Data);
|
84 | }
|
85 | //*********************************************************************
|
86 | void LCD_Byte(unsigned char Data)
|
87 | {
|
88 | LCD_CS0_0;
|
89 | for(unsigned char n=8;n;n--)
|
90 | {
|
91 | if(Data & 0x80) LCD_SDA_1; else LCD_SDA_0;
|
92 | Data <<= 1;
|
93 | LCD_SCK_0;
|
94 | LCD_SCK_1;
|
95 | }
|
96 | LCD_CS0_1;
|
97 | }
|
98 | //*********************************************************************
|
99 | void Pause(volatile unsigned long int i)
|
100 | {
|
101 | for(;i;i--)
|
102 | {
|
103 | asm volatile("NOP"); //1
|
104 | asm volatile("NOP"); //2
|
105 | asm volatile("NOP"); //3
|
106 | asm volatile("NOP"); //4
|
107 | asm volatile("NOP"); //5
|
108 | asm volatile("NOP"); //6
|
109 | asm volatile("NOP"); //7
|
110 | asm volatile("NOP"); //8
|
111 | }
|
112 | }
|
113 | //*********************************************************************
|
114 | // F I N
|
115 | //*********************************************************************
|