GLCD Library
A C Library for Embedded Applications
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
LPC11Uxx.c
Go to the documentation of this file.
1 
7 /*
8  Copyright (c) 2012, Andy Gock
9 
10  All rights reserved.
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright
17  notice, this list of conditions and the following disclaimer in the
18  documentation and/or other materials provided with the distribution.
19  * Neither the name of Andy Gock nor the
20  names of its contributors may be used to endorse or promote products
21  derived from this software without specific prior written permission.
22 
23  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY
27  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 
35 #include "../glcd.h"
36 #include "LPC11Uxx.h"
37 
38 #if defined(GLCD_DEVICE_LPC11UXX)
39 
40 void glcd_init(void)
41 {
42 
43 #if defined(GLCD_CONTROLLER_PCD8544)
44  /*
45  * Set up SPI (SSP)
46  * Note: Max allowed SPI clock is 4 MHz from datasheet.
47  */
48 
49  /* Select SSP/SPI port */
50  SSP_IOConfig( CONTROLLER_SPI_PORT_NUMBER );
51 
52  /* Initialise SSP/SPI port */
53  SSP_Init( CONTROLLER_SPI_PORT_NUMBER );
54 
55  /* Above functions take care of SPI pins */
56 
57  /* Set SS, DC and RST pins to output */
58  CONTROLLER_SS_PORT->DIR |= (1 << CONTROLLER_SS_PIN);
59  CONTROLLER_DC_PORT->DIR |= (1 << CONTROLLER_DC_PIN);
60  CONTROLLER_RST_PORT->DIR |= (1 << CONTROLLER_RST_PIN);
61 
62  /* Deselect LCD */
63  GLCD_DESELECT();
64 
65  /* Reset the display */
66  glcd_reset();
67 
68  /* Get into the EXTENDED mode! */
70 
71  /* LCD bias select (4 is optimal?) */
73 
74  /* Set VOP */
75  glcd_command(PCD8544_SET_VOP | 50); // Experimentally determined
76 
77  /* Back to standard instructions */
79 
80  /* Normal mode */
82 
84 
85  glcd_clear();
86 
87 #elif defined(GLCD_CONTROLLER_NT75451)
88  /* Parallel interface controller used on NGX BlueBoards */
89 
90  /* Set 4x control lines pins as output */
91  LPC_GPIO->DIR[CONTROLLER_LCD_EN_PORT] |= (1U<<CONTROLLER_LCD_EN_PIN);
92  LPC_GPIO->DIR[CONTROLLER_LCD_RW_PORT] |= (1U<<CONTROLLER_LCD_RW_PIN);
93  LPC_GPIO->DIR[CONTROLLER_LCD_RS_PORT] |= (1U<<CONTROLLER_LCD_RS_PIN);
94  LPC_GPIO->DIR[CONTROLLER_LCD_CS_PORT] |= (1U<<CONTROLLER_LCD_CS_PIN);
95 
96  /* Don't worry about setting default RS/RW/CS/EN, they get set during use */
97 
98 #ifdef CONTROLLER_LCD_DATA_PORT
99  /* Set data pins as output */
100  LPC_GPIO->DIR[CONTROLLER_LCD_D0_PORT] |= GLCD_PARALLEL_MASK;
101 #else
102  #error "Support of parallel data pins on different ports not supported."
103 #endif
104 
105  /* Initialise sequence - code by NGX Technologies */
106  glcd_command(0xE2); /* S/W RESWT */
107  glcd_command(0xA0); /* ADC select */
108  glcd_command(0xC8); /* SHL Normal */
109  glcd_command(0xA3); /* LCD bias */
110  glcd_command(0x2F); /* Power control */
111  glcd_command(0x22); /* reg resistor select */
112  glcd_command(0x40); /* Initial display line 40 */
113  glcd_command(0xA4); /* Normal display */
114  glcd_command(0xA6); /* Reverce display a7 */
115  glcd_command(0x81); /* Ref vg select mode */
116  glcd_command(0x3f); /* Ref vg reg select */
117  glcd_command(0xB0); /* Set page address */
118  glcd_command(0x10); /* Set coloumn addr MSB */
119  glcd_command(0x00); /* Set coloumn addr LSB */
120  glcd_command(0xAF); /* Display ON */
121 
122  /* Select default screen buffer */
124 
125  /* Clear the screen buffer */
126  glcd_clear();
127 
128 #else /* GLCD_CONTROLLER_PCD8544 */
129  #error "Controller not supported by LPC111x"
130 #endif
131 
132 }
133 
134 #if defined(GLCD_USE_PARALLEL)
135 
137 void glcd_parallel_write(uint8_t c)
138 {
139 
140  uint32_t port_output = \
141  ( ( (1U << 0) & c ? 1 : 0 ) << CONTROLLER_LCD_D0_PIN ) | \
142  ( ( (1U << 1) & c ? 1 : 0 ) << CONTROLLER_LCD_D1_PIN ) | \
143  ( ( (1U << 2) & c ? 1 : 0 ) << CONTROLLER_LCD_D2_PIN ) | \
144  ( ( (1U << 3) & c ? 1 : 0 ) << CONTROLLER_LCD_D3_PIN ) | \
145  ( ( (1U << 4) & c ? 1 : 0 ) << CONTROLLER_LCD_D4_PIN ) | \
146  ( ( (1U << 5) & c ? 1 : 0 ) << CONTROLLER_LCD_D5_PIN ) | \
147  ( ( (1U << 6) & c ? 1 : 0 ) << CONTROLLER_LCD_D6_PIN ) | \
148  ( ( (1U << 7) & c ? 1 : 0 ) << CONTROLLER_LCD_D7_PIN );
149 
150  /* Perform the write */
151 
152  /* Clear data bits to zero and set required bits as needed */
153  LPC_GPIO->CLR[CONTROLLER_LCD_D0_PORT] |= GLCD_PARALLEL_MASK;
154  LPC_GPIO->SET[CONTROLLER_LCD_D0_PORT] |= port_output;
155 
156  GLCD_RW_LOW();
157  GLCD_CS_LOW();
158  GLCD_EN_HIGH();
159 
160  /* Must hold for minimum 80 ns = ~12.5 MHz pulse */
161 
162  /* Do whatever is needed for your MCU */
163  //glcd_delay(1);
164 
165  GLCD_EN_LOW();
166  GLCD_CS_HIGH();
167  GLCD_RW_HIGH();
168 
169 }
170 
171 #else
172 
173 void glcd_spi_write(uint8_t c)
174 {
175  GLCD_SELECT();
176  SSP_Send(CONTROLLER_SPI_PORT_NUMBER,&c,1);
177  GLCD_DESELECT();
178 }
179 
180 #endif /* GLCD_USE_PARALLEL */
181 
182 void glcd_reset(void)
183 {
184 #if defined(GLCD_CONTROLLER_PCD8544)
185  /* Toggle RST low to reset. Minimum pulse 100ns on datasheet. */
186  GLCD_SELECT();
187  GLCD_RESET_LOW();
188  delay_ms(GLCD_RESET_TIME);
189  GLCD_RESET_HIGH();
190  GLCD_DESELECT();
191 
192 #elif defined(GLCD_CONTROLLER_NT75451)
193  /* No physical reset possible with our test board (BlueBoard) */
194 
195 #endif /* GLCD_CONTROLLER_PCD8544 */
196 }
197 
198 void glcd_delay(uint32_t count)
199 {
200  uint16_t j=0,i=0;
201 
202  for(j=0;j<count;j++)
203  {
204  /* At 60Mhz, the below loop introduces
205  delay of 10 us */
206  for(i=0;i<35;i++);
207  }
208 }
209 
210 #endif /* GLCD_DEVICE_LPC11UXX */
#define PCD8544_FUNCTION_SET
Definition: PCD8544.h:43
void glcd_spi_write(uint8_t c)
Write a byte to the connected SPI slave.
#define PCD8544_SET_VOP
Definition: PCD8544.h:75
void glcd_select_screen(uint8_t *buffer, glcd_BoundingBox_t *bbox)
Select screen buffer and bounding box structure.
Definition: glcd.c:133
void glcd_reset(void)
Reset the LCD.
#define PCD8544_EXTENDED_INSTRUCTION
Definition: PCD8544.h:47
#define PCD8544_DISPLAY_NORMAL
Definition: PCD8544.h:56
glcd_BoundingBox_t glcd_bbox
Keeps track of bounding box of area on LCD which need to be updated next reresh cycle.
Definition: glcd.c:55
#define PCD8544_DISPLAY_CONTROL
Definition: PCD8544.h:54
Implmentation of NXP LPC11Uxx microcontrollers.
#define PCD8544_SET_BIAS
Definition: PCD8544.h:74
void glcd_command(uint8_t c)
Send command byte to LCD.
void glcd_clear(void)
Clear the display.
Definition: glcd.c:122
uint8_t glcd_buffer[GLCD_LCD_WIDTH *GLCD_LCD_HEIGHT/8]
Screen buffer.
Definition: glcd.c:49
#define GLCD_RESET_TIME
Reset duration by glcd_reset(), in milliseconds.
Definition: glcd.h:156
void glcd_init(void)
Initialise the LCD.