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