1 /***********************************************************************************
\r
3 DESCRIPTION LCD Module utility functions.
\r
4 Written for KS0066u compatible LCD Module.
\r
5 (8 characters by 2 lines)
\r
7 Copyright : 2006 Renesas Technology Europe Ltd.
\r
8 Copyright : 2006 Renesas Technology Corporation.
\r
11 ***********************************************************************************/
\r
13 /***********************************************************************************
\r
15 DD.MM.YYYY OSO-UID Description
\r
16 26.07.2006 RTE-MBA First Release
\r
17 ***********************************************************************************/
\r
19 /**********************************************************************************
\r
21 ***********************************************************************************/
\r
22 #include <machine.h>
\r
24 /**********************************************************************************
\r
26 ***********************************************************************************/
\r
27 /* iodefine.h provides a structure to access all of the device registers. */
\r
28 #include "iodefine.h"
\r
29 /* rsk1664def.h provides common defines for widely used items. */
\r
30 #include "rskrx210def.h"
\r
33 /*****************************************************************************
\r
37 Description: Intializes the LCD display.
\r
38 *****************************************************************************/
\r
39 void InitialiseDisplay( void )
\r
41 /* Power Up Delay for LCD Module */
\r
42 EN_PIN = SET_BIT_HIGH;
\r
44 EN_PIN = SET_BIT_LOW;
\r
46 /* Display initialises in 8 bit mode - so send one write (seen as 8 bit)
\r
47 to set to 4 bit mode. */
\r
50 LCD_nibble_write(CTRL_WR,0x03);
\r
51 LCD_nibble_write(CTRL_WR,0x03);
\r
54 /* Configure display */
\r
55 LCD_nibble_write(CTRL_WR,0x03);
\r
56 LCD_nibble_write(CTRL_WR,0x02);
\r
57 LCD_nibble_write(CTRL_WR,(LCD_DISPLAY_ON | LCD_TWO_LINE ));
\r
58 LCD_nibble_write(CTRL_WR,(LCD_DISPLAY_ON | LCD_TWO_LINE ));
\r
61 /* Display ON/OFF control */
\r
62 LCD_write(CTRL_WR,LCD_CURSOR_OFF);
\r
66 LCD_write(CTRL_WR,LCD_CLEAR);
\r
69 /* Entry Mode Set */
\r
70 LCD_write(CTRL_WR,0x06);
\r
71 LCD_write(CTRL_WR,LCD_HOME_L1);
\r
73 /**********************************************************************************
\r
74 End of function InitialiseDisplay
\r
75 ***********************************************************************************/
\r
77 /*****************************************************************************
\r
78 Name: DisplayString
\r
79 Parameters: position Line number of display
\r
80 string Pointer to data to be written to display.
\r
81 Last character should be null.
\r
84 Description: This function controls LCD writes to line 1 or 2 of the LCD.
\r
85 You need to use the defines LCD_LINE1 and LCD_LINE2 in order
\r
86 to specify the starting position.
\r
87 For example, to start at the 2nd position on line 1...
\r
88 DisplayString(LCD_LINE1 + 1, "Hello")
\r
89 *****************************************************************************/
\r
90 void DisplayString(unsigned char position, char * string)
\r
92 static unsigned char next_pos = 0xFF;
\r
94 /* Set line position if needed. We don't want to if we don't need
\r
95 to because LCD control operations take longer than LCD data
\r
97 if( next_pos != position)
\r
99 if(position < LCD_LINE2)
\r
101 /* Display on Line 1 */
\r
102 LCD_write(CTRL_WR, (unsigned char)(LCD_HOME_L1 + position) );
\r
106 /* Display on Line 2 */
\r
107 LCD_write(CTRL_WR, (unsigned char)(LCD_HOME_L2 + position - LCD_LINE2) );
\r
109 /* set position index to known value */
\r
110 next_pos = position;
\r
115 LCD_write(DATA_WR,*string++);
\r
116 /* increment position index */
\r
121 /**********************************************************************************
\r
122 End of function DisplayString
\r
123 ***********************************************************************************/
\r
125 /*****************************************************************************
\r
127 Parameters: value - the value to write
\r
128 data_or_ctrl - To write value as DATA or CONTROL
\r
133 Description: Writes data to display. Sends command to display.
\r
134 *****************************************************************************/
\r
135 void LCD_write(unsigned char data_or_ctrl, unsigned char value)
\r
137 /* Write upper nibble first */
\r
138 LCD_nibble_write(data_or_ctrl, (value & 0xF0) >> 4);
\r
140 /* Write lower nibble second */
\r
141 LCD_nibble_write(data_or_ctrl, (value & 0x0F));
\r
143 /**********************************************************************************
\r
144 End of function LCD_write
\r
145 ***********************************************************************************/
\r
147 /*****************************************************************************
\r
148 Name: LCD_nibble_write
\r
149 Parameters: value - the value to write
\r
150 data_or_ctrl - To write value as DATA or CONTROL
\r
155 Description: Writes data to display. Sends command to display.
\r
156 *****************************************************************************/
\r
157 void LCD_nibble_write(unsigned char data_or_ctrl, unsigned char value)
\r
159 unsigned char ucStore;
\r
160 if (data_or_ctrl == DATA_WR)
\r
162 RS_PIN = SET_BIT_HIGH;
\r
166 RS_PIN = SET_BIT_LOW;
\r
168 /* There must be 40ns between RS write and EN write */
\r
170 /* EN enable chip (HIGH) */
\r
171 EN_PIN = SET_BIT_HIGH;
\r
174 /* Clear port bits used */
\r
175 /* Set upper lower 4 bits of nibble on port pins. */
\r
176 ucStore = DATA_PORT;
\r
177 ucStore &= ~DATA_PORT_MASK;
\r
179 ucStore |= ((value << DATA_PORT_SHIFT) & DATA_PORT_MASK );
\r
180 /* Write lower 4 bits of nibble */
\r
181 DATA_PORT = ucStore;
\r
183 /* write delay while En High */
\r
185 /* Latch data by dropping EN */
\r
186 EN_PIN = SET_BIT_LOW;
\r
187 /* Data hold delay */
\r
190 if(data_or_ctrl == CTRL_WR)
\r
192 /* Extra delay needed for control writes */
\r
196 /**********************************************************************************
\r
197 End of function LCD_nibble_write
\r
198 ***********************************************************************************/
\r
200 /*****************************************************************************
\r
201 Name: DisplayDelay
\r
202 Parameters: units - Approximately in microseconds
\r
205 Description: Delay routine for LCD display.
\r
206 *****************************************************************************/
\r
207 void DisplayDelay(unsigned long int units)
\r
209 unsigned long counter = units * DELAY_TIMING;
\r
215 /**********************************************************************************
\r
216 End of function DisplayDelay
\r
217 ***********************************************************************************/
\r