Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
LCD4884.cpp
00001 /* 00002 Modified by COX 00003 version 0.1 00004 00005 Editor : COX 00006 Date : 06.03.2013 00007 00008 * 00009 * Update DFRobot source to work on FRDM KL25Z 00010 * 00011 */ 00012 00013 #include "LCD4884.h" 00014 #include "font_6x8.h" 00015 #include "font_big.h" 00016 00017 DigitalOut SpiClk(SPI_SCK); //2- Serial Clock(Master Output) 00018 DigitalOut SpiMosi(SPI_MOSI); //3- Master Output,Slave Input 00019 DigitalOut LcdDC(LCD_DC); //4- Data/Command(command active low) 00020 DigitalOut SpiCS(SPI_CS); //5- Chip Select,Slave Transmit Enable(active low,Master Output) 00021 DigitalOut LcdRst(LCD_RST); //6- One Reset button 00022 PwmOut LcdBl(LCD_BL); //7- LCD backlight 00023 00024 LCD4884::LCD4884() 00025 {}; 00026 00027 /******************************************************************/ 00028 void LCD4884::backlight(float dat) 00029 { 00030 LcdBl = dat; 00031 } 00032 00033 /******************************************************************/ 00034 void LCD4884::LCD_init(void) 00035 { 00036 /* pin intializer */ 00037 SpiClk = LOW; 00038 SpiMosi = LOW; 00039 SpiCS = LOW; 00040 LcdDC = LOW; 00041 LcdBl = LOW; 00042 00043 LcdRst = LOW; 00044 wait(ONE_US); 00045 LcdRst = HIGH; 00046 00047 SpiCS = LOW; //Chip Select, Slave Transmit Enable(active low, Master Output) 00048 wait(ONE_US); 00049 SpiCS = HIGH; 00050 wait(ONE_US); 00051 LcdBl = LCD_INITIAL_BRIGHTNESS; 00052 00053 //data_type=0, all are command bytes 00054 LCD_write_byte(0x21, 0); //Function Set:0 0 1 0 0 PD V H=0010 0001;PD=0,V=0,H=1; 00055 LCD_write_byte(0xc0, 0); //Set Vop:1 Vop6 Vop5 Vop4 Vop3 Vop2 Vop1 Vop0=1100 0000 00056 LCD_write_byte(0x06, 0); //Set Temperature Coefficient:0 0 0 0 0 1 Tc1 Tc0=0000 0110;Tc1=1,Tc0=0(Vlcd temperature coefficient 2) 00057 LCD_write_byte(0x13, 0); //Set Bias System (BSx):0 0 0 1 0 BS2 BS1 BS0=0001 0011;BS2=0, BS1=1, BS0=1==>N=4,MUX RATE=1:48 00058 00059 LCD_write_byte(0x20, 0);//Function Set:0 0 1 0 0 PD V H=0010 0000;PD=0,V=0,H=0; 00060 LCD_clear(); 00061 LCD_write_byte(0x0c, 0);//Display Control: 0 0 0 0 1 D 0 E=0000 1100 ;D=1,E=0:normal mode 00062 00063 SpiCS = LOW; 00064 } 00065 00066 /******************************************************************/ 00067 void LCD4884::LCD_write_byte(unsigned char dat, unsigned char dat_type) 00068 { 00069 unsigned int i; 00070 SpiCS = LOW; //Chip Enable:Active LOW 00071 00072 if (dat_type == 0) 00073 LcdDC = LOW; // D/C=0:the current data byte is interpreted as command byte 00074 else 00075 LcdDC = HIGH; // D/C=1:write data to display RAM 00076 00077 for(i=0;i<8;i++) 00078 { 00079 if(dat&0x80) //1000 0000 00080 { 00081 SpiMosi = HIGH; 00082 } 00083 else 00084 { 00085 SpiMosi = LOW; 00086 } 00087 SpiClk = LOW; 00088 dat = dat << 1; 00089 SpiClk = HIGH; 00090 } 00091 SpiCS = HIGH; 00092 } 00093 00094 /******************************************************************/ 00095 void LCD4884::LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map, 00096 unsigned char Pix_x,unsigned char Pix_y) 00097 { 00098 unsigned int i,n; 00099 unsigned char row; 00100 00101 if (Pix_y%8==0) 00102 row=Pix_y/8; //row from 1 to 6;Pix_y from R0 to R47 00103 else 00104 row=Pix_y/8+1; //Quotient+1 00105 00106 for (n=0;n<row;n++) 00107 { 00108 LCD_set_XY(X,Y); 00109 for(i=0; i<Pix_x; i++) 00110 { 00111 LCD_write_byte(map[i+n*Pix_x], 1); // D/C=1:write data to display RAM 00112 } 00113 Y++; 00114 } 00115 } 00116 00117 /**************************************************************************************/ 00118 void LCD4884::LCD_write_string(unsigned char X,unsigned char Y,char *s, char mode) 00119 { 00120 LCD_set_XY(X,Y); 00121 while (*s) 00122 { 00123 LCD_write_char(*s, mode); 00124 s++; 00125 } 00126 } 00127 00128 /**************************************************************************************/ 00129 void LCD4884::LCD_prop_write_string(unsigned char X,unsigned char Y,char *s, char mode) 00130 { 00131 LCD_set_XY(X,Y); 00132 while (*s) 00133 { 00134 LCD_prop_write_char(*s, mode); 00135 s++; 00136 } 00137 } 00138 00139 /*************************************************************************************/ 00140 void LCD4884::LCD_write_chinese(unsigned char X, unsigned char Y,unsigned char *c,unsigned char ch_with,unsigned char num,unsigned char line,unsigned char row) 00141 { 00142 unsigned char i,n; 00143 LCD_set_XY(X,Y); 00144 for (i=0;i<num;) 00145 { 00146 for (n=0; n<ch_with*2; n++) 00147 { 00148 if (n==ch_with) 00149 { 00150 if (i==0) 00151 LCD_set_XY(X,Y+1); 00152 else 00153 LCD_set_XY((X+(ch_with+row)*i),Y+1); 00154 } 00155 LCD_write_byte(c[(i*ch_with*2)+n],1); 00156 } 00157 i++; 00158 LCD_set_XY((X+(ch_with+row)*i),Y); 00159 } 00160 } 00161 00162 00163 /******************************************************************/ 00164 void LCD4884::LCD_write_string_big ( unsigned char X,unsigned char Y, char *string, char mode ) 00165 { 00166 while ( *string ) 00167 { 00168 LCD_write_char_big( X, Y, *string , mode ); 00169 00170 if(*string++ == '.') 00171 X += 5; 00172 else 00173 X += 12; 00174 } 00175 } 00176 00177 /******************************************************************/ 00178 /* write char in big font */ 00179 void LCD4884::LCD_write_char_big (unsigned char X,unsigned char Y, unsigned char ch, char mode) 00180 { 00181 unsigned char i, j; 00182 unsigned char *pFont; 00183 unsigned char ch_dat; 00184 00185 pFont = (unsigned char *) big_number; 00186 00187 if(ch == '.') 00188 ch = 10; 00189 else if (ch == '+') 00190 ch = 11; 00191 else if (ch == '-') 00192 ch = 12; 00193 else 00194 ch = ch & 0x0f; 00195 00196 for(i=0;i<3;i++) 00197 { 00198 LCD_set_XY ( X, Y+i); 00199 00200 for(j=0; j<16; j++) 00201 { 00202 ch_dat = *(pFont+ch*48 + i*16 +j); 00203 LCD_write_byte( (mode == MENU_NORMAL)? ch_dat : (ch_dat^0xff), 1); 00204 } 00205 } 00206 } 00207 00208 /******************************************************************/ 00209 void LCD4884::LCD_write_char(unsigned char c, char mode) 00210 { 00211 unsigned char line; 00212 unsigned char *pFont; 00213 unsigned char ch; 00214 00215 pFont = (unsigned char *)font6_8; //pointer *pFont points at font6_8[][6] 00216 c -= 32; // the ASCII of "SP" is 32 00217 00218 for (line=0; line<6; line++) 00219 { 00220 ch = *(pFont+c*6+line); //read c from the font6_8[][6] (the detail information is in the "font6x8.h") 00221 LCD_write_byte( (mode==MENU_NORMAL)? ch: (ch^ 0xff) , 1); //MENU_NORMAL=0,True:return ch;False:return ch 00222 } 00223 } 00224 00225 /*******************************************************************/ 00226 unsigned char LCD4884::LCD_prop_write_char(unsigned char c, char mode) 00227 { 00228 int line, line_s=0, line_e=2; 00229 unsigned char *pFont; 00230 unsigned char ch; 00231 00232 pFont = (unsigned char *)font6_8; 00233 if (c -= 32) 00234 { 00235 for (line_s=0; line_s<6; line_s++) 00236 { 00237 if(*(pFont+c*6+line_s)) 00238 break; 00239 } 00240 for (line_e=5; line_e<0; line_e--) 00241 { 00242 if(*(pFont+c*6+line_e)) 00243 break; 00244 } 00245 } 00246 for (line=line_s; line<line_e+1; line++) 00247 { 00248 ch = *(pFont+c*6+line); 00249 LCD_write_byte( (mode==MENU_NORMAL)? ch: (ch^ 0xff) , 1); 00250 } 00251 LCD_write_byte( (mode==MENU_NORMAL)? 0:0xff, 1); 00252 return ((unsigned char)(line_e+2 - line_s)); 00253 } 00254 00255 /******************************************************************/ 00256 void LCD4884::LCD_set_XY(unsigned char X, unsigned char Y) 00257 { 00258 LCD_write_byte(0x40 | Y, 0); // column 00259 LCD_write_byte(0x80 | X, 0); // row 00260 } 00261 00262 /******************************************************************/ 00263 void LCD4884::LCD_clear(void) 00264 { 00265 unsigned int i; 00266 00267 LCD_write_byte(0x0c, 0); 00268 LCD_write_byte(0x80, 0); 00269 00270 for (i=0; i<504; i++) //6*84 00271 { 00272 LCD_write_byte(0, 1); 00273 } 00274 } 00275
Generated on Tue Jul 12 2022 18:57:16 by
