C18 LaurTec Library
2.5
Open Source C Library for PIC18 Microcontrollers
|
00001 /********************************************************************************************** 00002 00003 Author : Mauro Laurenti 00004 Version : 1.0 00005 Date : 4/9/2006 00006 00007 CopyRight 2006 all rights are reserved 00008 00009 ******************************************************** 00010 SOFTWARE LICENSE AGREEMENT 00011 ******************************************************** 00012 00013 The usage of the supplied software imply the acceptance of the following license. 00014 00015 The software supplied herewith by Mauro Laurenti (the Author) 00016 is intended for use solely and exclusively on Microchip PIC Microcontroller (registered mark). 00017 The software is owned by the Author, and is protected under applicable copyright laws. 00018 All rights are reserved. 00019 Any use in violation of the foregoing restrictions may subject the 00020 user to criminal sanctions under applicable laws (Italian or International ones), as well as to 00021 civil liability for the breach of the terms and conditions of this license. 00022 Commercial use is forbidden without a written acknowledgment with the Author. 00023 Personal or educational use is allowed if the application containing the following 00024 software doesn't aim to commercial use or monetary earning of any kind. 00025 00026 THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, 00027 WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED 00028 TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00029 PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT, 00030 IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR 00031 CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 00032 00033 **********************************************************************************************/ 00034 00035 00036 #include "LCD_44780.h" 00037 00038 00039 //************************************************************ 00040 // Epulse Implementation 00041 //************************************************************ 00042 void Epulse (void) { 00043 00044 LCD_E = 1; 00045 delay_ms (1); 00046 LCD_E = 0; 00047 delay_ms (1); 00048 } 00049 00050 00051 //************************************************************ 00052 // SendCommand Implementation 00053 //************************************************************ 00054 void SendCommand (unsigned char D3, unsigned char D2, unsigned char D1, unsigned char D0) { 00055 00056 LCD_D0 = D0; 00057 LCD_D1 = D1; 00058 LCD_D2 = D2; 00059 LCD_D3 = D3; 00060 Epulse (); 00061 } 00062 00063 00064 //************************************************************ 00065 // Line2LCD Implementation 00066 //************************************************************ 00067 void Line2LCD(void) { 00068 00069 SendCommand (1,1,0,0); 00070 SendCommand (0,0,0,0); 00071 } 00072 00073 00074 //************************************************************ 00075 // HomeLCD Implementation 00076 //************************************************************ 00077 void HomeLCD(void) { 00078 00079 SendCommand (0,0,0,0); 00080 SendCommand (0,0,1,0); 00081 } 00082 00083 00084 //************************************************************ 00085 // ShiftLCD Implementation 00086 //************************************************************ 00087 void ShiftLCD(char shift, char number_of_shift) { 00088 00089 char i; 00090 00091 for (i=0; i < number_of_shift; i++) { 00092 SendCommand (0,0,0,1); 00093 SendCommand (1,shift,0,0); 00094 } 00095 } 00096 00097 00098 //************************************************************ 00099 // ShiftCursorLCD Implementation 00100 //************************************************************ 00101 void ShiftCursorLCD(char shift, char number_of_shift){ 00102 00103 char i; 00104 00105 for (i=0; i < number_of_shift; i++) { 00106 SendCommand (0,0,0,1); 00107 SendCommand (0,shift,0,0); 00108 } 00109 } 00110 00111 //************************************************************ 00112 // GotoLineLCD Implementation 00113 //************************************************************ 00114 void GotoLineLCD (char line) { 00115 00116 switch(line) { 00117 00118 case 1: SendCommand(1,0,0,0); 00119 SendCommand(0,0,0,0); 00120 break; 00121 00122 case 2: SendCommand(1,1,0,0); 00123 SendCommand(0,0,0,0); 00124 break; 00125 00126 case 3: SendCommand(1,0,0,1); 00127 SendCommand(0,1,0,0); 00128 break; 00129 00130 case 4: SendCommand(1,1,0,1); 00131 SendCommand(0,1,0,0); 00132 } 00133 } 00134 00135 //************************************************************ 00136 // WriteCharLCD Implementation 00137 //************************************************************ 00138 void WriteCharLCD (unsigned char value) { 00139 00140 unsigned char D3,D2,D1,D0; 00141 00142 LCD_RS = 1; 00143 00144 // Splitting of the first nibble 00145 D3 = (value & 0b10000000) >> 7; 00146 D2 = (value & 0b01000000) >> 6; 00147 D1 = (value & 0b00100000) >> 5; 00148 D0 = (value & 0b00010000) >> 4; 00149 00150 SendCommand (D3,D2,D1,D0); 00151 00152 // Splitting of the second nibble 00153 D3 = (value & 0b00001000) >> 3; 00154 D2 = (value & 0b00000100) >> 2; 00155 D1 = (value & 0b00000010) >> 1; 00156 D0 = (value & 0b00000001); 00157 00158 SendCommand (D3,D2,D1,D0); 00159 00160 LCD_RS = 0; 00161 } 00162 00163 //************************************************************ 00164 // WriteStringLCD Implementation 00165 //************************************************************ 00166 void WriteStringLCD(const rom char *buffer) { 00167 00168 // Write data to LCD up to null 00169 while(*buffer) { 00170 00171 // Write character to LCD 00172 WriteCharLCD(*buffer); 00173 // Increment buffer 00174 buffer++; 00175 } 00176 } 00177 00178 //************************************************************ 00179 // WriteVarLCD Implementation 00180 //************************************************************ 00181 void WriteVarLCD(unsigned char *buffer) { 00182 00183 // Write data to LCD up to null 00184 while(*buffer){ 00185 00186 // Write character to LCD 00187 WriteCharLCD(*buffer); 00188 // Increment buffer 00189 buffer++; 00190 } 00191 } 00192 00193 00194 //************************************************************ 00195 // WriteIntLCD Implementation 00196 //************************************************************ 00197 void WriteIntLCD(int value, char number_of_digits){ 00198 00199 // The array size is 5 plus end of string \0 00200 unsigned char convertedInt [6]; 00201 00202 // Index used to shift to the right the digit 00203 char index; 00204 00205 // Integer is converted to string 00206 itoa (value, (char*) convertedInt); 00207 00208 if (number_of_digits >0 ) { 00209 00210 convertedInt[number_of_digits] = '\0'; 00211 00212 // Shift the digit to the right removing the empty one 00213 while (!isdigit(convertedInt[number_of_digits-1])) { 00214 00215 for (index = number_of_digits-1; index > 0; index--){ 00216 convertedInt[index] = convertedInt[index-1]; 00217 convertedInt[index-1] = ' '; 00218 } 00219 } 00220 } 00221 00222 WriteVarLCD (convertedInt); 00223 00224 } 00225 00226 00227 //************************************************************ 00228 // ClearLCD Implementation 00229 //************************************************************ 00230 void ClearLCD (void){ 00231 00232 SendCommand (0,0,0,0); 00233 SendCommand (0,0,0,1); 00234 } 00235 00236 //************************************************************ 00237 // CursorLCD Implementation 00238 //************************************************************ 00239 void CursorLCD(char active,char blinking) { 00240 00241 SendCommand (0,0,0,0); 00242 SendCommand (1,1,active,blinking); 00243 } 00244 00245 //************************************************************ 00246 // CursorLCD Implementation 00247 //************************************************************ 00248 void BacklightLCD(char active) { 00249 00250 LCD_LED = active; 00251 } 00252 00253 //************************************************************ 00254 // OpenLCD Implementation 00255 //************************************************************ 00256 void OpenLCD(unsigned char quartz_frequency) { 00257 00258 setQuartz (quartz_frequency); 00259 00260 LCD_RS = 0x00; 00261 LCD_E = 0x00; 00262 LCD_RW = 0x00; 00263 00264 delay_ms (100); 00265 SendCommand (0,0,1,1); 00266 delay_ms (5); 00267 SendCommand (0,0,1,1); 00268 delay_ms (5); 00269 SendCommand (0,0,1,1); 00270 delay_ms (5); 00271 SendCommand (0,0,1,0); 00272 SendCommand (0,0,1,0); 00273 SendCommand (1,0,0,0); 00274 SendCommand (0,0,0,0); 00275 SendCommand (1,1,1,0); 00276 CursorLCD (0,0); 00277 ClearLCD (); 00278 } 00279