00001
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include "asuro.h"
00055 #include "lcd.h"
00056 #include "i2c.h"
00057
00062 void InitLCD(void)
00063 {
00064 unsigned char init[] = LCD_INIT;
00065 unsigned char i = 0;
00066
00067 SetIOLCD(OFF, LCD_EN);
00068 Msleep(1);
00069
00070
00071 CommandLCD( LCD_8BIT | (LCD_8BIT >> 4) );
00072 CommandLCD( LCD_8BIT | (LCD_4BIT >> 4) );
00073
00074 while (init[i] != 0x00)
00075 {
00076 CommandLCD(init[i]);
00077 i++;
00078 }
00079
00080 CommandLCD( LCD_DISPLAYON );
00081 CommandLCD( LCD_INCREASE );
00082 CommandLCD( LCD_CLEAR );
00083 CommandLCD( LCD_HOME );
00084 Msleep(1);
00085 }
00086
00097 void BacklightLCD(unsigned char state)
00098 {
00099 SetIOLCD(state, LCD_BL);
00100 }
00101
00108 void SetDataLCD(unsigned char data)
00109 {
00110 unsigned char dataPins;
00111
00112
00113 dataPins &= 0x00;
00114 dataPins |= ((data & 0x80) >> 7) << LD7;
00115 dataPins |= ((data & 0x40) >> 6) << LD6;
00116 dataPins |= ((data & 0x20) >> 5) << LD5;
00117 dataPins |= ((data & 0x10) >> 4) << LD4;
00118
00119 SetIOLCD(OFF, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7);
00120 SetIOLCD(ON, dataPins);
00121 SetIOLCD(ON, LCD_EN);
00122 Msleep(1);
00123 SetIOLCD(OFF, LCD_EN);
00124
00125
00126 dataPins &= 0x00;
00127 dataPins |= ((data & 0x08) >> 3) << LD7;
00128 dataPins |= ((data & 0x04) >> 2) << LD6;
00129 dataPins |= ((data & 0x02) >> 1) << LD5;
00130 dataPins |= ((data & 0x01) >> 0) << LD4;
00131
00132 SetIOLCD(OFF, LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7);
00133 SetIOLCD(ON, dataPins);
00134 SetIOLCD(ON, LCD_EN);
00135 Msleep(1);
00136 SetIOLCD(OFF, LCD_EN);
00137
00138 Msleep(1);
00139 }
00140
00148 void SetIOLCD(unsigned char setCommand, unsigned char bits)
00149 {
00150 if (setCommand == ON)
00151 portLCD |= bits;
00152 else
00153 portLCD &= ~bits;
00154 StartI2C(LCD_DEV);
00155 WriteI2C(portLCD);
00156 StopI2C();
00157 }
00158
00165 unsigned char GetIOLCD(void)
00166 {
00167 unsigned char data = 0x00;
00168 StartI2C(LCD_DEV+1);
00169 data = ReadI2C(0);
00170 StopI2C();
00171 return data;
00172 }
00173
00181 void SetCursorLCD(unsigned char cursor, unsigned char line)
00182 {
00183 cursorLCD = cursor;
00184 lineLCD = line;
00185
00186 if (line == 0)
00187 line = LCD_LINE1;
00188 #if LCD_LINES>=2
00189 else if (line == 1)
00190 line = LCD_LINE2;
00191 #endif
00192 #if LCD_LINES>=3
00193 else if (line == 2)
00194 line = LCD_LINE3;
00195 #endif
00196 #if LCD_LINES>=4
00197 else if (line == 3)
00198 line = LCD_LINE4;
00199 #endif
00200 else
00201 line = LCD_LINE1;
00202
00203 CommandLCD(LCD_DDRAM | (line+cursor));
00204 }
00205
00212 void CommandLCD(unsigned char command)
00213 {
00214 if (command == LCD_HOME)
00215 lineLCD = cursorLCD = 0x00;
00216 SetIOLCD(OFF, LCD_RS);
00217 SetDataLCD(command);
00218 }
00219
00225 void ClearLCD(void)
00226 {
00227 CommandLCD(LCD_CLEAR);
00228 CommandLCD(LCD_HOME);
00229 }
00230
00238 void WriteLCD(unsigned char data)
00239 {
00240 SetIOLCD(ON, LCD_RS);
00241 SetDataLCD(data);
00242 cursorLCD++;
00243 }
00244
00252 void PrintLCD(char *string, unsigned char wrap)
00253 {
00254 unsigned char i = 0;
00255 while (string[i] != 0x00)
00256 {
00257 if (cursorLCD >= LCD_CHARS)
00258 {
00259 if (wrap)
00260 SetCursorLCD(0, lineLCD+1);
00261 else
00262 break;
00263 }
00264 WriteLCD(string[i]);
00265 i++;
00266 }
00267 }
00268
00277 void PrintSetLCD(unsigned char cursor, unsigned char line, char *string)
00278 {
00279 SetCursorLCD(cursor, line);
00280 PrintLCD(string, OFF);
00281 }
00282
00289 void PrintIntLCD(int value)
00290 {
00291 char text[6];
00292 itoa(value,text,10);
00293 PrintLCD(text, OFF);
00294 }
00295
00307 void PrintAlignLCD(unsigned char alignment, unsigned char line, char *string)
00308 {
00309 unsigned char i = 0;
00310 while (string[i] != 0x00)
00311 i++;
00312 if (alignment == RIGHT)
00313 PrintSetLCD(LCD_CHARS-i, line, string);
00314 else if (alignment == CENTER)
00315 PrintSetLCD((LCD_CHARS-i)/2, line, string);
00316 else
00317 PrintSetLCD(0, line, string);
00318 }
00319
00320
00321