1 | #include <XMC1100.h> //SFR declarations of the selected device
|
2 | #include "gpio_XMC1100_tssop38.h"
|
3 | #include "types.h"
|
4 |
|
5 |
|
6 | #define DISPLAY_EN P0_9_set(); //Display Enable
|
7 | #define DISPLAY_DATA_MOD P0_12_set(); //Display Datamode
|
8 |
|
9 | #define DISPLAY_SET_DATA0 P1_2_set(); //Display Data0 set
|
10 | #define DISPLAY_SET_DATA1 P1_3_set(); //Display Data1 set
|
11 | #define DISPLAY_SET_DATA2 P1_4_set(); //Display Data2 set
|
12 | #define DISPLAY_SET_DATA3 P0_0_set(); //Display Data3 set
|
13 | #define DISPLAY_SET_DATA4 P0_1_set(); //Display Data4 set
|
14 | #define DISPLAY_SET_DATA5 P0_2_set(); //Display Data5 set
|
15 | #define DISPLAY_SET_DATA6 P0_3_set(); //Display Data6 set
|
16 | #define DISPLAY_SET_DATA7 P0_4_set(); //Display Data7 set
|
17 |
|
18 | #define DISPLAY_DIS P0_9_reset(); //Display Disable
|
19 | //#define DISPLAY_WRITE P0_8_reset(); //Display Write
|
20 | #define DISPLAY_INS_MOD P0_12_reset(); //Display Instructionmode
|
21 | #define DISPLAY_RSET_DATA0 P1_2_reset(); //Display Data0 reset
|
22 | #define DISPLAY_RSET_DATA1 P1_3_reset(); //Display Data1 reset
|
23 | #define DISPLAY_RSET_DATA2 P1_4_reset(); //Display Data2 reset
|
24 | #define DISPLAY_RSET_DATA3 P0_0_reset(); //Display Data3 reset
|
25 | #define DISPLAY_RSET_DATA4 P0_1_reset(); //Display Data4 reset
|
26 | #define DISPLAY_RSET_DATA5 P0_2_reset(); //Display Data5 reset
|
27 | #define DISPLAY_RSET_DATA6 P0_3_reset(); //Display Data6 reset
|
28 | #define DISPLAY_RSET_DATA7 P0_4_reset(); //Display Data7 reset
|
29 |
|
30 |
|
31 | ////////////////////////////////////////////////////////////////////////////////
|
32 | // LCD Ausführungszeiten (MS=Millisekunden, US=Mikrosekunden)
|
33 |
|
34 | #define LCD_BOOTUP_MS 15*100 // * 100 = * 1000 us
|
35 | #define LCD_ENABLE_US 2 //2*10us
|
36 | #define LCD_WRITEDATA_US 5 //5*10us
|
37 | #define LCD_COMMAND_US 5 //5*10us
|
38 |
|
39 | #define LCD_SOFT_RESET_MS1 5*100
|
40 | #define LCD_SOFT_RESET_MS2 1*100
|
41 | #define LCD_SOFT_RESET_MS3 1*100
|
42 | #define LCD_SET_4BITMODE_MS 5*100
|
43 |
|
44 | #define LCD_CLEAR_DISPLAY_MS 2*100
|
45 | #define LCD_CURSOR_HOME_MS 2*100
|
46 |
|
47 | ////////////////////////////////////////////////////////////////////////////////
|
48 | // LCD Befehle und Argumente.
|
49 | // Zur Verwendung in lcd_command
|
50 |
|
51 | // Clear Display -------------- 0b00000001
|
52 | #define LCD_CLEAR_DISPLAY 0x01
|
53 |
|
54 | // Cursor Home ---------------- 0b0000001x
|
55 | #define LCD_CURSOR_HOME 0x02
|
56 |
|
57 | // Set Entry Mode ------------- 0b000001xx
|
58 | #define LCD_SET_ENTRY 0x04
|
59 |
|
60 | #define LCD_ENTRY_DECREASE 0x00
|
61 | #define LCD_ENTRY_INCREASE 0x02
|
62 | #define LCD_ENTRY_NOSHIFT 0x00
|
63 | #define LCD_ENTRY_SHIFT 0x01
|
64 |
|
65 | // Set Display ---------------- 0b00001xxx
|
66 | #define LCD_SET_DISPLAY 0x08
|
67 |
|
68 | #define LCD_DISPLAY_OFF 0x00
|
69 | #define LCD_DISPLAY_ON 0x04
|
70 | #define LCD_CURSOR_OFF 0x00
|
71 | #define LCD_CURSOR_ON 0x02
|
72 | #define LCD_BLINKING_OFF 0x00
|
73 | #define LCD_BLINKING_ON 0x01
|
74 |
|
75 | // Set Shift ------------------ 0b0001xxxx
|
76 | #define LCD_SET_SHIFT 0x10
|
77 |
|
78 | #define LCD_CURSOR_MOVE 0x00
|
79 | #define LCD_DISPLAY_SHIFT 0x08
|
80 | #define LCD_SHIFT_LEFT 0x00
|
81 | #define LCD_SHIFT_RIGHT 0x04
|
82 |
|
83 | // Set Function --------------- 0b001xxxxx
|
84 | #define LCD_SET_FUNCTION 0x20
|
85 |
|
86 | #define LCD_FUNCTION_4BIT 0x00
|
87 | #define LCD_FUNCTION_8BIT 0x10
|
88 | #define LCD_FUNCTION_1LINE 0x00
|
89 | #define LCD_FUNCTION_2LINE 0x08
|
90 | #define LCD_FUNCTION_5X7 0x00
|
91 | #define LCD_FUNCTION_5X10 0x04
|
92 |
|
93 | #define LCD_SOFT_RESET 0x30
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | bool WaitForSysTickInterrupt=1; //Indicates if SysTickInterrupt occurs (is set to 0 if interrupt occurs)
|
102 |
|
103 |
|
104 | //SyssTickInterrupt
|
105 | void SysTick_Handler(void)
|
106 | {
|
107 | WaitForSysTickInterrupt=0;
|
108 | }
|
109 |
|
110 | void wait_10us(uint32_t wait10us)
|
111 | {
|
112 | uint32_t count=0;
|
113 | //SYSTICK-SETUP => Interrupt every 10us
|
114 | SystemCoreClockUpdate();
|
115 | SysTick_Config(SystemCoreClock / 100000);
|
116 | WaitForSysTickInterrupt=1;
|
117 | //Wait "wait10us" interrupts
|
118 | while(count < wait10us) {
|
119 | if(!WaitForSysTickInterrupt) {
|
120 | WaitForSysTickInterrupt=1;
|
121 | count++;
|
122 | }
|
123 | }
|
124 | //disable SysTickCounter
|
125 | SysTick->CTRL = 0;
|
126 | }
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | //Setzte die gewünschten Datenbits
|
133 | void lcd_datapin(uint16_t data)
|
134 | {
|
135 | uint16_t mask= 0x01;
|
136 | int i=0;
|
137 | //Alle Bits Reset
|
138 | DISPLAY_RSET_DATA0;DISPLAY_RSET_DATA1;DISPLAY_RSET_DATA2;DISPLAY_RSET_DATA3;
|
139 | DISPLAY_RSET_DATA4;DISPLAY_RSET_DATA5;DISPLAY_RSET_DATA6;DISPLAY_RSET_DATA7;
|
140 |
|
141 | if(data>0)
|
142 | {
|
143 | //Setzt die Datenbits des Displays die in data stehen
|
144 | for(i=0;i<=7;i++)
|
145 | {
|
146 | if(data&mask) //ist BitX gesetzt?
|
147 | {
|
148 | switch(i)//Setzte BitX am DIsplay
|
149 | {
|
150 | case 0: DISPLAY_SET_DATA0; break;
|
151 | case 1: DISPLAY_SET_DATA1; break;
|
152 | case 2: DISPLAY_SET_DATA2; break;
|
153 | case 3: DISPLAY_SET_DATA3; break;
|
154 | case 4: DISPLAY_SET_DATA4; break;
|
155 | case 5: DISPLAY_SET_DATA5; break;
|
156 | case 6: DISPLAY_SET_DATA6; break;
|
157 | case 7: DISPLAY_SET_DATA7; break;
|
158 | }
|
159 | }
|
160 |
|
161 | data=data>>1; //nächste Bit
|
162 |
|
163 | if(data==0) //wenn kein bit mehr vorhanden break
|
164 | break;
|
165 | }
|
166 | }
|
167 | }
|
168 |
|
169 | int main(void)
|
170 | {
|
171 |
|
172 |
|
173 |
|
174 | //--------------------------------------------------------------------------------------------------
|
175 |
|
176 | //----CLOCK-SETUP-----------------------------------------------------------------------------------
|
177 | SCU_GENERAL->PASSWD = 0x000000C0UL;
|
178 | SCU_CLK->CLKCR = 0x3FF00401UL; // 8 MHz MCLK, 8 MHz PCLK
|
179 | while((SCU_CLK->CLKCR)&0x40000000UL); // wait for VDDC to stabilize
|
180 | SCU_GENERAL->PASSWD = 0x000000C3UL;
|
181 | //--------------------------------------------------------------------------------------------------
|
182 |
|
183 |
|
184 |
|
185 | P0_9_set_mode(OUTPUT_PP_GP); //Display Enable
|
186 |
|
187 | P0_12_set_mode(OUTPUT_PP_GP); //Display Datamode
|
188 |
|
189 | P1_2_set_mode(OUTPUT_PP_GP); //Display Data0 set
|
190 | P1_3_set_mode(OUTPUT_PP_GP); //Display Data1 set
|
191 | P1_4_set_mode(OUTPUT_PP_GP); //Display Data2 set
|
192 | P0_0_set_mode(OUTPUT_PP_GP); //Display Data3 set
|
193 | P0_1_set_mode(OUTPUT_PP_GP); //Display Data4 set
|
194 | P0_2_set_mode(OUTPUT_PP_GP); //Display Data5 set
|
195 | P0_3_set_mode(OUTPUT_PP_GP); //Display Data6 set
|
196 | P0_4_set_mode(OUTPUT_PP_GP); //Display Data7 set
|
197 |
|
198 | //ALLE PINS AUF 0
|
199 | DISPLAY_INS_MOD;
|
200 | DISPLAY_DIS;
|
201 | lcd_datapin(0x00);
|
202 |
|
203 |
|
204 |
|
205 | //################################### START INIT
|
206 | wait_10us(LCD_BOOTUP_MS);
|
207 |
|
208 |
|
209 | //3 mal softreset
|
210 | lcd_datapin(LCD_SOFT_RESET);
|
211 | wait_10us(450);
|
212 |
|
213 | DISPLAY_EN;
|
214 | wait_10us(1);
|
215 | DISPLAY_DIS;
|
216 |
|
217 | wait_10us(11);
|
218 | DISPLAY_EN;
|
219 | wait_10us(1);
|
220 | DISPLAY_DIS;
|
221 |
|
222 | wait_10us(3);
|
223 | DISPLAY_EN;
|
224 | wait_10us(1);
|
225 | DISPLAY_DIS;
|
226 |
|
227 | DISPLAY_EN;
|
228 |
|
229 | lcd_datapin(0x0E); //LCD on , display on, curser on,
|
230 | wait_10us(5);
|
231 |
|
232 |
|
233 | lcd_datapin(0x01); //clera
|
234 | wait_10us(160);
|
235 |
|
236 |
|
237 | lcd_datapin(0x06); //entery mod, decement on, schift off
|
238 | wait_10us(5);
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | while(1)
|
245 | {
|
246 | }
|
247 |
|
248 | return 0;
|
249 | }
|