1 /***********************************************************************************************************************
\r
3 * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No
\r
4 * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
\r
5 * applicable laws, including copyright laws.
\r
6 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
\r
7 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
\r
8 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM
\r
9 * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES
\r
10 * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS
\r
11 * SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\r
12 * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
\r
13 * this software. By using this software, you agree to the additional terms and conditions found by accessing the
\r
15 * http://www.renesas.com/disclaimer
\r
17 * Copyright (C) 2012 Renesas Electronics Corporation. All rights reserved.
\r
18 ***********************************************************************************************************************/
\r
19 /***********************************************************************************************************************
\r
22 * H/W Platform : RSK+RX63N
\r
23 * Description : Provides variable and function declarations for lcd.c file
\r
24 ***********************************************************************************************************************/
\r
25 /***********************************************************************************************************************
\r
26 * History : DD.MM.YYYY Version Description
\r
27 * : 22.11.2011 1.00 First Release
\r
28 ***********************************************************************************************************************/
\r
30 /***********************************************************************************************************************
\r
31 Includes <System Includes> , "Project Includes"
\r
32 ***********************************************************************************************************************/
\r
33 /* Processor-specific details */
35 /* Standard string manipulation & formatting functions */
38 /* Defines standard variable types used in this function */
40 /* Bring in board includes. */
\r
42 /* Following header file provides function prototypes for LCD controlling functions & macro defines */
45 /***********************************************************************************************************************
\r
46 Private global variables and functions
\r
47 ***********************************************************************************************************************/
\r
48 static void lcd_delay(volatile int32_t nsecs);
\r
49 static void lcd_nibble_write(uint8_t data_or_ctrl, uint8_t value);
\r
50 static void lcd_write(uint8_t data_or_ctrl, uint8_t value);
\r
52 /***********************************************************************************************************************
53 * Function name : lcd_initialize
54 * Description : Initializes the LCD display.
57 ***********************************************************************************************************************/
\r
58 void lcd_initialize(void)
60 /* Set LCD data pins as outputs. */
\r
61 PORT8.PDR.BYTE |= 0xF0;
\r
63 /* Set LCD control pins as outputs. */
\r
67 /* Power Up Delay for the LCD Module */
\r
68 lcd_delay(50000000);
\r
70 /* Display initialises in 8 bit mode - so send one write (seen as 8 bit) to set to 4 bit mode. */
\r
71 lcd_nibble_write(CTRL_WR, 0x03);
\r
73 lcd_nibble_write(CTRL_WR, 0x03);
\r
75 lcd_nibble_write(CTRL_WR, 0x03);
\r
79 lcd_nibble_write(CTRL_WR, 0x02);
\r
81 lcd_nibble_write(CTRL_WR, 0x02);
\r
82 lcd_nibble_write(CTRL_WR, (LCD_DISPLAY_ON | LCD_TWO_LINE ));
\r
85 /* Display ON/OFF control */
\r
86 lcd_write(CTRL_WR, LCD_CURSOR_OFF);
\r
90 lcd_write(CTRL_WR, LCD_CLEAR);
\r
93 /* Entry Mode Set */
\r
94 lcd_write(CTRL_WR, 0x06);
\r
97 /* Home the cursor */
\r
98 lcd_write(CTRL_WR, LCD_HOME_L1);
\r
99 lcd_delay(5000000);
\r
102 /***********************************************************************************************************************
103 * Function name : lcd_clear
104 * Description : Clears the LCD
106 * Return Value : none
107 ***********************************************************************************************************************/
110 /* Display Clear */
\r
111 lcd_write(CTRL_WR, LCD_CLEAR);
\r
112 lcd_delay(2000000);
\r
115 /***********************************************************************************************************************
116 * Function name : lcd_display
117 * Description : This function controls LCD writes to line 1 or 2 of the LCD.
\r
118 * You need to use the defines LCD_LINE1 and LCD_LINE2 in order to specify the starting position.
\r
119 * For example, to start at the 2nd position on line 1...
\r
120 * lcd_display(LCD_LINE1 + 1, "Hello")
121 * Arguments : position -
\r
122 * Line number of display
124 * Pointer to null terminated string
125 * Return Value : none
126 ***********************************************************************************************************************/
127 void lcd_display(uint8_t position, uint8_t const * string)
129 /* Declare next position variable */
\r
130 static uint8_t next_pos = 0xFF;
\r
132 /* Set line position if needed. We don't want to if we don't need to because LCD control operations take longer
\r
133 than LCD data operations. */
\r
134 if (next_pos != position)
\r
136 if(position < LCD_LINE2)
\r
138 /* Display on Line 1 */
\r
139 lcd_write(CTRL_WR, ((uint8_t)(LCD_HOME_L1 + position)));
\r
143 /* Display on Line 2 */
\r
144 lcd_write(CTRL_WR, ((uint8_t)((LCD_HOME_L2 + position) - LCD_LINE2)));
\r
149 /* set position index to known value */
\r
150 next_pos = position;
\r
155 /* Write character to LCD. */
\r
156 lcd_write(DATA_WR,*string++);
\r
160 /* Increment position index */
\r
166 /***********************************************************************************************************************
\r
167 * Function name : lcd_delay
\r
168 * Description : Implements LCD required delays.
\r
169 * Arguments : nsecs -
\r
170 * Number of nanoseconds to delay. RX600 has max clock of 100MHz which gives a cycle time of 10ns.
\r
171 * This means that nothing under 100ns should be input. 100ns would be 10 cycles which is still
\r
172 * being optimistic for getting in and out of this function.
\r
173 * Return Value : none
\r
174 ***********************************************************************************************************************/
\r
175 static void lcd_delay(volatile int32_t nsecs)
\r
179 /* Subtract off 10 cycles per iteration. This number was obtained when using the Renesas toolchain at
\r
180 optimization level 2. The number to nanoseconds to subtract off below is calculated off of the ICLK speed. */
\r
181 nsecs -= (int32_t)((100.0)*(100000000.0/(float)ICLK_HZ));
\r
185 /***********************************************************************************************************************
\r
186 * Function name : lcd_nibble_write
\r
187 * Description : Writes data to display. Sends command to display.
\r
188 * Arguments : value -
\r
189 * The value to write
\r
191 * Whether to write data or control.
\r
194 * Return Value : none
\r
195 ***********************************************************************************************************************/
\r
196 static void lcd_nibble_write(uint8_t data_or_ctrl, uint8_t value)
\r
198 /* Set Register Select pin high for Data */
\r
199 if (data_or_ctrl == DATA_WR)
\r
206 /* Control write. */
\r
213 /* EN enable chip (HIGH) */
\r
216 /* Output the data */
\r
217 PORT8.PODR.BYTE = (value << 4u);
\r
222 /* Latch data by dropping E */
\r
232 /***********************************************************************************************************************
\r
233 * Function name : lcd_write
\r
234 * Description : This function controls LCD writes to line 1 or 2 of the LCD. You need to use the defines LCD_LINE1 and
\r
235 * LCD_LINE2 in order to specify the starting position.
\r
236 * For example, to start at the 2nd position on line 1...
\r
237 * lcd_display(LCD_LINE1 + 1, "Hello")
\r
238 * Arguments : value -
\r
239 * The value to write
\r
241 * Whether to write data or control.
\r
244 * Return Value : none
\r
245 ***********************************************************************************************************************/
\r
246 static void lcd_write(uint8_t data_or_ctrl, uint8_t value)
\r
248 /* Write upper nibble first */
\r
249 lcd_nibble_write(data_or_ctrl, (uint8_t)((value & 0xF0) >> 4));
\r
251 /* Write lower nibble second */
\r
252 lcd_nibble_write(data_or_ctrl, (uint8_t)(value & 0x0F));
\r