| Nano100BN Series BSP V3.03.002 The Board Support Package for Nano100BN Series

lcd.c
Go to the documentation of this file.
1 /**************************************************************************/
15 #include <stdio.h>
16 #include <string.h>
17 #include <stdlib.h>
18 #include "Nano100Series.h"
19
20
21
31
36 /*---------------------------------------------------------------------------------------------------------*/
37 /* Global file scope (static) variables */
38 /*---------------------------------------------------------------------------------------------------------*/
39
40 double g_LCDFreq;
41 static uint32_t g_LCDFrameRate; /* src:32768Hz, COM:4, FREQ Div:64, frame-rate 64Hz */
42 /* src:10240Hz, COM:4, FREQ Div:32, frame-rate 40Hz */
43
44 /* end of group NANO100_LCD_EXPORTED_VARIABLES */
46
48
64 void LCD_SetPixel(uint32_t u32Com, uint32_t u32Seg, uint32_t u32OnFlag)
65 {
66 int32_t memnum = u32Seg / 4;
67 int32_t seg_shift = 8*(u32Seg-(4*memnum));
68
69 if(u32OnFlag)
70 {
71 if(memnum==0)
72 {
73 LCD->MEM_0 |= (1<<u32Com)<<seg_shift;
74 }
75 else if(memnum==1)
76 {
77 LCD->MEM_1 |= (1<<u32Com)<<seg_shift;
78 }
79 else if(memnum==2)
80 {
81 LCD->MEM_2 |= (1<<u32Com)<<seg_shift;
82 }
83 else if(memnum==3)
84 {
85 LCD->MEM_3 |= (1<<u32Com)<<seg_shift;
86 }
87 else if(memnum==4)
88 {
89 LCD->MEM_4 |= (1<<u32Com)<<seg_shift;
90 }
91 else if(memnum==5)
92 {
93 LCD->MEM_5 |= (1<<u32Com)<<seg_shift;
94 }
95 else if(memnum==6)
96 {
97 LCD->MEM_6 |= (1<<u32Com)<<seg_shift;
98 }
99 else if(memnum==7)
100 {
101 LCD->MEM_7 |= (1<<u32Com)<<seg_shift;
102 }
103 else if(memnum==8)
104 {
105 LCD->MEM_8 |= (1<<u32Com)<<seg_shift;
106 }
107 else if(memnum==9)
108 {
109 LCD->MEM_9 |= (1<<u32Com)<<seg_shift;
110 }
111 }
112 else
113 {
114 if(memnum==0)
115 {
116 LCD->MEM_0 &= ~((1<<u32Com)<<seg_shift);
117 }
118 else if(memnum==1)
119 {
120 LCD->MEM_1 &= ~((1<<u32Com)<<seg_shift);
121 }
122 else if(memnum==2)
123 {
124 LCD->MEM_2 &= ~((1<<u32Com)<<seg_shift);
125 }
126 else if(memnum==3)
127 {
128 LCD->MEM_3 &= ~((1<<u32Com)<<seg_shift);
129 }
130 else if(memnum==4)
131 {
132 LCD->MEM_4 &= ~((1<<u32Com)<<seg_shift);
133 }
134 else if(memnum==5)
135 {
136 LCD->MEM_5 &= ~((1<<u32Com)<<seg_shift);
137 }
138 else if(memnum==6)
139 {
140 LCD->MEM_6 &= ~((1<<u32Com)<<seg_shift);
141 }
142 else if(memnum==7)
143 {
144 LCD->MEM_7 &= ~((1<<u32Com)<<seg_shift);
145 }
146 else if(memnum==8)
147 {
148 LCD->MEM_8 &= ~((1<<u32Com)<<seg_shift);
149 }
150 else if(memnum==9)
151 {
152 LCD->MEM_9 &= ~((1<<u32Com)<<seg_shift);
153 }
154
155 }
156
157 if(CyclesPerUs > 0)
158 SysTick->LOAD = 300 * CyclesPerUs;
159 else
160 SysTick->LOAD = 15;
161 SysTick->VAL = (0x00);
162 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
163
164 /* Waiting for down-count to zero */
165 while((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0);
166 }
167
177 void LCD_SetAllPixels(uint32_t u32OnOff)
178 {
179 uint32_t u32SetValue;
180
181 if(u32OnOff)
182 {
183 u32SetValue = 0xFFFFFFFF;
184 }
185 else
186 {
187 u32SetValue = 0x00000000;
188 }
189
190 LCD->MEM_0 = u32SetValue;
191 LCD->MEM_1 = u32SetValue;
192 LCD->MEM_2 = u32SetValue;
193 LCD->MEM_3 = u32SetValue;
194 LCD->MEM_4 = u32SetValue;
195 LCD->MEM_5 = u32SetValue;
196 LCD->MEM_6 = u32SetValue;
197 LCD->MEM_7 = u32SetValue;
198 LCD->MEM_8 = u32SetValue;
199
200 if(CyclesPerUs > 0)
201 SysTick->LOAD = 300 * CyclesPerUs;
202 else
203 SysTick->LOAD = 15;
204 SysTick->VAL = (0x00);
205 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
206
207 /* Waiting for down-count to zero */
208 while((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0);
209 }
210
211
221 uint32_t LCD_EnableFrameCounter(uint32_t u32Count)
222 {
223 uint32_t div = 1; // default prediv == LCD_FCPRESC_DIV1
224
225 LCD->FCR = 0x00;
226 LCD->FCSTS |= LCD_FCSTS_FCSTS_Msk; // clear fcsts flag
227
228 if(u32Count == 0) return 0;
229
230 if(u32Count > 0x3F) // top value max. 63 = 0x3F
231 {
232 div = u32Count/64;
233
234 if(div > 3)
235 {
236 div = 8;
237 LCD->FCR = LCD->FCR & ~LCD_FCR_PRESCL_Msk | LCD_FCPRESC_DIV8;
238 }
239 else if(div > 1)
240 {
241 div = 4;
242 LCD->FCR = LCD->FCR & ~LCD_FCR_PRESCL_Msk | LCD_FCPRESC_DIV4;
243 }
244 else
245 {
246 div = 2;
247 LCD->FCR = LCD->FCR & ~LCD_FCR_PRESCL_Msk | LCD_FCPRESC_DIV2;
248 }
249
250 u32Count = (u32Count+(div/2))/div;
251 }
252 else
253 {
254 div = 1;
255 LCD->FCR = LCD->FCR & ~LCD_FCR_PRESCL_Msk | LCD_FCPRESC_DIV1;
256 }
257
258 LCD->FCR = LCD->FCR & ~LCD_FCR_FCV_Msk | (u32Count << LCD_FCR_FCV_Pos);
259
260 u32Count = u32Count*div;
261
262 LCD->FCR |= LCD_FCR_FCEN_Msk; // enable LCD frame count
263
264 return u32Count;
265 }
266
275 void LCD_DisableFrameCounter(void)
276 {
277 LCD->FCR = 0x00; // disable LCD frame count
278
279 if( LCD->FCSTS & LCD_FCSTS_FCSTS_Msk) // clear status flag
280 LCD->FCSTS = LCD_FCSTS_FCSTS_Msk;
281 }
282
283
298 uint32_t LCD_Open(uint32_t u32DrivingType, uint32_t u32ComNum, uint32_t u32BiasLevel, uint32_t u32FramerateDiv, uint32_t u32DrivingVol)
299 {
300 uint32_t clkdiv, muldiv;
301 uint32_t lcd_freq_div[] = {32, 64, 96, 128, 192, 256, 384, 512};
302 uint32_t multiplex_freq_div[] = {2, 4, 6, 8, 10, 12};
303 uint32_t u32clk_src;
304
305 /* IP reset */
306 SYS->IPRST_CTL2 |= SYS_IPRST_CTL2_LCD_RST_Msk;
307 SYS->IPRST_CTL2 &= ~SYS_IPRST_CTL2_LCD_RST_Msk;
308
309 LCD_DisableDisplay();
310
311 /* Turn all segments off */
312 LCD_SetAllPixels(0);
313
314
315 switch(u32DrivingType)
316 {
317 case LCD_C_TYPE:
318 case LCD_EXTERNAL_C_TYPE:
319
320 LCD->DISPCTL &= ~LCD_DISPCTL_BV_SEL_Msk; // internal source for charge pump
321 LCD->DISPCTL = LCD->DISPCTL & ~LCD_DISPCTL_CPUMP_FREQ_Msk | (LCD_CPUMP_DIV1);
322 LCD->DISPCTL = LCD->DISPCTL & ~LCD_DISPCTL_CPUMP_VOL_SET_Msk | (u32DrivingVol);
323 LCD->DISPCTL &= ~LCD_DISPCTL_IBRL_EN_Msk;
324 LCD->DISPCTL |= LCD_DISPCTL_CPUMP_EN_Msk; // enable charge pump
325
326 break;
327
328 case LCD_EXTERNAL_R_TYPE:
329 case LCD_INTERNAL_R_TYPE:
330
331 LCD->DISPCTL &= ~LCD_DISPCTL_CPUMP_EN_Msk;
332 LCD->DISPCTL |= LCD_DISPCTL_BV_SEL_Msk;
333 LCD->DISPCTL &= ~LCD_DISPCTL_IBRL_EN_Msk;
334 LCD->DISPCTL |= (u32DrivingType == LCD_INTERNAL_R_TYPE)?LCD_DISPCTL_IBRL_EN_Msk:0;
335 break;
336
337 };
338
339 LCD->CTL &= ~LCD_CTL_FREQ_Msk;
340 LCD->CTL |= u32FramerateDiv;
341
342 LCD->CTL = (LCD->CTL & ~LCD_CTL_MUX_Msk) | ((u32ComNum - 1) << LCD_CTL_MUX_Pos);
343 LCD->DISPCTL = LCD->DISPCTL & ~LCD_DISPCTL_BIAS_SEL_Msk | u32BiasLevel;
344
345 if((CLK->CLKSEL1 & CLK_CLKSEL1_LCD_S_Msk) == 0)
346 u32clk_src = 32 * 1024;
347 else
348 u32clk_src = 10 * 1024;
349
350 clkdiv = (LCD->CTL & LCD_CTL_FREQ_Msk) >> LCD_CTL_FREQ_Pos;
351 muldiv = (LCD->CTL & LCD_CTL_MUX_Msk) >> LCD_CTL_MUX_Pos;
352
353 g_LCDFreq = (double)u32clk_src / lcd_freq_div[clkdiv];
354 g_LCDFrameRate = (uint32_t)g_LCDFreq / multiplex_freq_div[muldiv];
355
356 return g_LCDFrameRate;
357 }
358
359
360
369 void LCD_Close(void)
370 {
371 LCD_DisableDisplay();
372 }
373
374
383 uint32_t LCD_EnableBlink(uint32_t u32ms)
384 {
385 uint32_t prescale=LCD_FCPRESC_DIV1, div=1;
386 uint32_t framecount;
387
388 if((1000/u32ms) > g_LCDFrameRate) u32ms = (1000/g_LCDFrameRate);
389
390 framecount = (uint32_t) (u32ms / (1000/g_LCDFrameRate)) ;
391
392 if(framecount > 0x3F)
393 {
394 for(div=2; div<=8; div*=2)
395 {
396 framecount = (uint32_t) (u32ms / (1000/(g_LCDFrameRate/div)) );
397
398 if( framecount <= 0x40 )
399 break;
400 }
401 if(div==2) prescale = LCD_FCPRESC_DIV2;
402 else if(div==4) prescale = LCD_FCPRESC_DIV4;
403 else if(div==8) prescale = LCD_FCPRESC_DIV8;
404 else return 0;
405 }
406 else if(framecount == 0)
407 {
408 framecount = 1;
409 }
410
411 LCD->FCR = LCD->FCR & ~LCD_FCR_PRESCL_Msk | prescale;
412 LCD->FCR = LCD->FCR & ~LCD_FCR_FCV_Msk | ((framecount - 1) << LCD_FCR_FCV_Pos);
413 LCD->FCR |= LCD_FCR_FCEN_Msk;
414
415 /* Enable Blink LCD */
416 LCD->CTL |= LCD_CTL_BLINK_Msk;
417
418 return ( (framecount*1000)/(g_LCDFrameRate/div) );
419 }
420
421
430 void LCD_DisableBlink(void)
431 {
432 /* Disable Blink LCD */
433 LCD->CTL &= ~LCD_CTL_BLINK_Msk;
434
435 /* Disable frame count */
436 LCD->FCR = 0x00; // disable LCD frame count
437
438 if( LCD->FCSTS & LCD_FCSTS_FCSTS_Msk) // clear status flag
439 LCD->FCSTS = LCD_FCSTS_FCSTS_Msk;
440
441 }
442
451 void LCD_EnableInt(uint32_t IntSrc)
452 {
453 if((IntSrc & LCD_FRAMECOUNT_INT) == LCD_FRAMECOUNT_INT )
454 {
455 LCD->FCR |= LCD_FCR_FCEN_Msk;
456 }
457
458 if((IntSrc & LCD_POWERDOWN_INT) == LCD_POWERDOWN_INT )
459 {
460 LCD->CTL |= LCD_CTL_PDINT_EN_Msk;
461 }
462
463 }
464
473 void LCD_DisableInt(uint32_t IntSrc)
474 {
475 if((IntSrc & LCD_FRAMECOUNT_INT) == LCD_FRAMECOUNT_INT )
476 {
477 LCD->FCR &= ~LCD_FCR_FCEN_Msk;
478 LCD->FCSTS = LCD_FCSTS_FCSTS_Msk;
479 }
480
481 if((IntSrc & LCD_POWERDOWN_INT) == LCD_POWERDOWN_INT )
482 {
483 LCD->CTL &= ~LCD_CTL_PDINT_EN_Msk;
484 LCD->FCSTS = LCD_FCSTS_PDSTS_Msk;
485 }
486 }
487 /* end of group NANO100_LCD_EXPORTED_FUNCTIONS */
489 /* end of group NANO100_LCD_Driver */
491 /* end of group NANO100_Device_Driver */
493
494 /*** (C) COPYRIGHT 2013~2014 Nuvoton Technology Corp. ***/
495
LCD_EnableFrameCounter
uint32_t LCD_EnableFrameCounter(uint32_t u32Count)
Set Frame Count and Enable frame count.
Definition: lcd.c:221
LCD_SetAllPixels
void LCD_SetAllPixels(uint32_t u32OnOff)
LCD Enable/Disable all segments.
Definition: lcd.c:177
LCD_FRAMECOUNT_INT
#define LCD_FRAMECOUNT_INT
Definition: lcd.h:87
LCD_DISPCTL_IBRL_EN_Msk
#define LCD_DISPCTL_IBRL_EN_Msk
Definition: Nano100Series.h:5401
LCD_FCR_FCV_Msk
#define LCD_FCR_FCV_Msk
Definition: Nano100Series.h:5542
LCD
#define LCD
Pointer to LCD register structure.
Definition: Nano100Series.h:11683
LCD_DisableInt
void LCD_DisableInt(uint32_t IntSrc)
This function is used to disable LCD specified interrupt.
Definition: lcd.c:473
CLK
#define CLK
Pointer to CLK register structure.
Definition: Nano100Series.h:11693
LCD_EXTERNAL_R_TYPE
Definition: lcd.h:102
LCD_POWERDOWN_INT
#define LCD_POWERDOWN_INT
Definition: lcd.h:88
LCD_FCSTS_PDSTS_Msk
#define LCD_FCSTS_PDSTS_Msk
Definition: Nano100Series.h:5548
Nano100Series.h
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
LCD_DISPCTL_CPUMP_EN_Msk
#define LCD_DISPCTL_CPUMP_EN_Msk
Definition: Nano100Series.h:5395
LCD_CTL_PDINT_EN_Msk
#define LCD_CTL_PDINT_EN_Msk
Definition: Nano100Series.h:5392
LCD_FCPRESC_DIV8
#define LCD_FCPRESC_DIV8
Definition: lcd.h:85
LCD_SetPixel
void LCD_SetPixel(uint32_t u32Com, uint32_t u32Seg, uint32_t u32OnFlag)
Enables a segment on the LCD display.
Definition: lcd.c:64
LCD_INTERNAL_R_TYPE
Definition: lcd.h:103
CLK_CLKSEL1_LCD_S_Msk
#define CLK_CLKSEL1_LCD_S_Msk
Definition: Nano100Series.h:1381
LCD_FCR_PRESCL_Msk
#define LCD_FCR_PRESCL_Msk
Definition: Nano100Series.h:5539
CyclesPerUs
uint32_t CyclesPerUs
Definition: system_Nano100Series.c:21
LCD_DisableBlink
void LCD_DisableBlink(void)
Disable Blink function in LCD controller.
Definition: lcd.c:430
LCD_FCPRESC_DIV4
#define LCD_FCPRESC_DIV4
Definition: lcd.h:84
LCD_CTL_BLINK_Msk
#define LCD_CTL_BLINK_Msk
Definition: Nano100Series.h:5386
LCD_EnableBlink
uint32_t LCD_EnableBlink(uint32_t u32ms)
Enable Blink function in LCD controller.
Definition: lcd.c:383
LCD_FCR_FCEN_Msk
#define LCD_FCR_FCEN_Msk
Definition: Nano100Series.h:5533
LCD_DISPCTL_BIAS_SEL_Msk
#define LCD_DISPCTL_BIAS_SEL_Msk
Definition: Nano100Series.h:5398
LCD_CTL_MUX_Msk
#define LCD_CTL_MUX_Msk
Definition: Nano100Series.h:5380
LCD_DisableFrameCounter
void LCD_DisableFrameCounter(void)
Disable frame count function.
Definition: lcd.c:275
LCD_FCPRESC_DIV1
#define LCD_FCPRESC_DIV1
Definition: lcd.h:82
SYS_IPRST_CTL2_LCD_RST_Msk
#define SYS_IPRST_CTL2_LCD_RST_Msk
Definition: Nano100Series.h:3032
LCD_DISPCTL_BV_SEL_Msk
#define LCD_DISPCTL_BV_SEL_Msk
Definition: Nano100Series.h:5404
LCD_DISPCTL_CPUMP_FREQ_Msk
#define LCD_DISPCTL_CPUMP_FREQ_Msk
Definition: Nano100Series.h:5410
LCD_Close
void LCD_Close(void)
The function is used to disable LCD controller.
Definition: lcd.c:369
LCD_EnableInt
void LCD_EnableInt(uint32_t IntSrc)
This function is used to enable LCD interrupt.
Definition: lcd.c:451
LCD_Open
uint32_t LCD_Open(uint32_t u32DrivingType, uint32_t u32ComNum, uint32_t u32BiasLevel, uint32_t u32FramerateDiv, uint32_t u32DrivingVol)
LCD Initialization routine.
Definition: lcd.c:298
LCD_CPUMP_DIV1
#define LCD_CPUMP_DIV1
Definition: lcd.h:64
LCD_FCSTS_FCSTS_Msk
#define LCD_FCSTS_FCSTS_Msk
Definition: Nano100Series.h:5545
LCD_FCR_FCV_Pos
#define LCD_FCR_FCV_Pos
Definition: Nano100Series.h:5541
LCD_DISPCTL_CPUMP_VOL_SET_Msk
#define LCD_DISPCTL_CPUMP_VOL_SET_Msk
Definition: Nano100Series.h:5407
LCD_FCPRESC_DIV2
#define LCD_FCPRESC_DIV2
Definition: lcd.h:83
LCD_DisableDisplay
static __INLINE void LCD_DisableDisplay(void)
Disable LCD controller.
Definition: lcd.h:201
LCD_CTL_FREQ_Pos
#define LCD_CTL_FREQ_Pos
Definition: Nano100Series.h:5382
LCD_CTL_FREQ_Msk
#define LCD_CTL_FREQ_Msk
Definition: Nano100Series.h:5383
LCD_CTL_MUX_Pos
#define LCD_CTL_MUX_Pos
Definition: Nano100Series.h:5379
LCD_EXTERNAL_C_TYPE
Definition: lcd.h:104
LCD_C_TYPE
Definition: lcd.h:101
SYS
#define SYS
Pointer to SYS register structure.
Definition: Nano100Series.h:11692