]> git.sur5r.net Git - freertos/blob - Demo/RX600_RX63N-RDK_Renesas/RTOSDemo/Renesas-Files/board/rskrx63n/lcd.c
Update the Renesas provided BSP files in the RDK RX63N project.
[freertos] / Demo / RX600_RX63N-RDK_Renesas / RTOSDemo / Renesas-Files / board / rskrx63n / lcd.c
1 /***********************************************************************************************************************\r
2 * DISCLAIMER\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
14 * following link:\r
15 * http://www.renesas.com/disclaimer \r
16 *\r
17 * Copyright (C) 2012 Renesas Electronics Corporation. All rights reserved.    \r
18 ***********************************************************************************************************************/\r
19 /***********************************************************************************************************************\r
20 * File Name        : lcd.c\r
21 * Device(s)    : RX\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
29
30 /***********************************************************************************************************************\r
31 Includes   <System Includes> , "Project Includes"\r
32 ***********************************************************************************************************************/\r
33 /* Processor-specific details */
34 #include <machine.h>
35 /* Standard string manipulation & formatting functions */
36 #include <stdio.h>
37 #include <string.h>
38 /* Defines standard variable types used in this function */
39 #include <stdint.h>\r
40 /* Bring in board includes. */\r
41 #include "platform.h"
42 /* Following header file provides function prototypes for LCD controlling functions & macro defines */
43 #include "lcd.h"
44
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
51
52 /***********************************************************************************************************************
53 * Function name : lcd_initialize
54 * Description   : Initializes the LCD display. 
55 * Arguments     : none
56 * Return Value  : none
57 ***********************************************************************************************************************/\r
58 void lcd_initialize(void)
59 {\r
60     /* Set LCD data pins as outputs. */\r
61     PORT8.PDR.BYTE |= 0xF0;\r
62     \r
63     /* Set LCD control pins as outputs. */\r
64     RS_PIN_DDR = 1;\r
65     E_PIN_DDR = 1;\r
66         \r
67         /* Power Up Delay for the LCD Module */         \r
68     lcd_delay(50000000);\r
69 \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
72     lcd_delay(5000000);\r
73         lcd_nibble_write(CTRL_WR, 0x03);\r
74     lcd_delay(5000000);\r
75         lcd_nibble_write(CTRL_WR, 0x03);\r
76         lcd_delay(5000000);\r
77     \r
78         /* Function Set */\r
79         lcd_nibble_write(CTRL_WR, 0x02);\r
80     lcd_delay(39000);    \r
81         lcd_nibble_write(CTRL_WR, 0x02);\r
82         lcd_nibble_write(CTRL_WR, (LCD_DISPLAY_ON | LCD_TWO_LINE ));\r
83     lcd_delay(39000);    \r
84  \r
85         /* Display ON/OFF control */\r
86         lcd_write(CTRL_WR, LCD_CURSOR_OFF);\r
87     lcd_delay(39000);\r
88 \r
89         /* Display Clear */\r
90         lcd_write(CTRL_WR, LCD_CLEAR);\r
91     lcd_delay(2000000);\r
92 \r
93         /* Entry Mode Set */\r
94         lcd_write(CTRL_WR, 0x06);\r
95     lcd_delay(39000);\r
96 \r
97     /* Home the cursor */\r
98         lcd_write(CTRL_WR, LCD_HOME_L1);\r
99     lcd_delay(5000000);    \r
100 }
101
102 /***********************************************************************************************************************
103 * Function name : lcd_clear
104 * Description   : Clears the LCD
105 * Arguments     : none
106 * Return Value  : none
107 ***********************************************************************************************************************/
108 void lcd_clear(void)
109 {
110         /* Display Clear */\r
111         lcd_write(CTRL_WR, LCD_CLEAR);\r
112     lcd_delay(2000000);    \r
113 }
114
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
123 *                 string - \r
124 *                     Pointer to null terminated string
125 * Return Value  : none
126 ***********************************************************************************************************************/
127 void lcd_display(uint8_t position, uint8_t const * string)
128 {
129         /* Declare next position variable */\r
130         static uint8_t next_pos = 0xFF;\r
131         \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
135         {\r
136                 if(position < LCD_LINE2)\r
137                 {\r
138                         /* Display on Line 1 */\r
139                         lcd_write(CTRL_WR, ((uint8_t)(LCD_HOME_L1 + position)));\r
140                 }\r
141                 else\r
142                 {\r
143                         /* Display on Line 2 */\r
144                         lcd_write(CTRL_WR, ((uint8_t)((LCD_HOME_L2 + position) - LCD_LINE2)));\r
145                 }\r
146 \r
147         lcd_delay(39000);\r
148 \r
149                 /* set position index to known value */\r
150                 next_pos = position;            \r
151         }\r
152 \r
153         do\r
154         {\r
155         /* Write character to LCD. */\r
156                 lcd_write(DATA_WR,*string++);\r
157 \r
158         lcd_delay(43000);\r
159                 \r
160                 /* Increment position index */\r
161                 next_pos++;                             \r
162         } \r
163         while(*string); \r
164 }\r
165
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
176 {\r
177     while (0 < nsecs)\r
178     {\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
182     }\r
183 }\r
184 \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
190 *                 data_or_ctrl -\r
191 *                     Whether to write data or control.\r
192 *                     1 = DATA\r
193 *                     0 = CONTROL\r
194 * Return Value  : none\r
195 ***********************************************************************************************************************/\r
196 static void lcd_nibble_write(uint8_t data_or_ctrl, uint8_t value)\r
197 {\r
198         /* Set Register Select pin high for Data */\r
199         if (data_or_ctrl == DATA_WR)\r
200         {\r
201         /* Data write. */\r
202         RS_PIN = 1;\r
203         }\r
204         else\r
205         {\r
206         /* Control write. */\r
207         RS_PIN = 0;\r
208         }\r
209         \r
210         /* tsu1 delay */\r
211     lcd_delay(60);    \r
212         \r
213         /* EN enable chip (HIGH) */\r
214     E_PIN = 1;    \r
215         \r
216         /* Output the data */\r
217     PORT8.PODR.BYTE = (value << 4u);\r
218         \r
219         /* tw delay */              \r
220     lcd_delay(450);    \r
221         \r
222         /* Latch data by dropping E */          \r
223     E_PIN = 0;\r
224         \r
225         /* th2 delay */                         \r
226     lcd_delay(10);\r
227         \r
228         /* tc delay */\r
229     lcd_delay(480);\r
230 }\r
231 \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
240 *                 data_or_ctrl -\r
241 *                     Whether to write data or control.\r
242 *                     1 = DATA\r
243 *                     0 = CONTROL\r
244 * Return Value  : none\r
245 ***********************************************************************************************************************/\r
246 static void lcd_write(uint8_t data_or_ctrl, uint8_t value)\r
247 {\r
248         /* Write upper nibble first */\r
249         lcd_nibble_write(data_or_ctrl, (uint8_t)((value & 0xF0) >> 4));\r
250         \r
251         /* Write lower nibble second */\r
252         lcd_nibble_write(data_or_ctrl, (uint8_t)(value & 0x0F));\r
253 }\r
254 \r