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.
TCLcd.cpp
00001 00002 #include "mbed.h" 00003 #include "TCLcd.h" 00004 #include "font.h" 00005 00006 Serial pc(USBTX, USBRX); // tx, rx 00007 00008 00009 signed long TCLcd::search_font_area( unsigned short code ) 00010 { 00011 unsigned short i; 00012 00013 for(i=0;i<fnt_head.Tnum;i++) 00014 { 00015 if( (fnt_head.Block[i].Start<=code) && (fnt_head.Block[i].End>=code) ) 00016 { 00017 return(i); 00018 } 00019 } 00020 00021 return(-1); 00022 } 00023 00024 signed long TCLcd::get_font_pt( unsigned short code ,unsigned char *chr ) 00025 { 00026 signed long font_area; 00027 unsigned long offset; 00028 unsigned long addr; 00029 00030 font_area = search_font_area(code); 00031 00032 if(font_area == -1) 00033 { 00034 code = 0x81a0; 00035 font_area = search_font_area(code); 00036 } 00037 00038 offset = (unsigned long)code - (unsigned long)fnt_head.Block[font_area].Start; 00039 00040 addr = ((unsigned long)font_search_tbl[font_area] + offset) * ((fnt_head.XSize >> 3) * fnt_head.YSize); 00041 00042 addr += font_head_size; 00043 00044 memcpy( chr ,&font[addr] ,8 ); 00045 00046 return( 0 ); 00047 } 00048 00049 int TCLcd::putc(int value) 00050 { 00051 static unsigned char tmp[2] = { 0 , 0 }; 00052 static int flag = 0; 00053 00054 if (value == '\n') 00055 { 00056 _column = 0; 00057 _row+=8; 00058 if (_row >= (ENDROW)) { 00059 _row = 0; 00060 } 00061 } 00062 else if(value == '\r') 00063 { 00064 00065 } 00066 else if(flag == 1) 00067 { 00068 flag = 0; 00069 tmp[1] = value; 00070 putch2( _column , _row , &tmp[0] , BLUE , WHITE ); 00071 _column+=8; 00072 if (_column >= (ENDCOL)) { 00073 _column = 0; 00074 _row+=8; 00075 if (_row >= (ENDROW)) { 00076 _row = 0; 00077 } 00078 } 00079 } 00080 else if((value >= 0x81) && (value <= 0xea)) 00081 { 00082 tmp[0] = value; 00083 flag = 1; 00084 } 00085 else 00086 { 00087 #if 0 00088 _column++; 00089 if (_column >= ENDCOL) { 00090 _column = 0; 00091 _row++; 00092 if (_row >= ENDROW) { 00093 _row = 0; 00094 } 00095 } 00096 #endif 00097 } 00098 return value; 00099 } 00100 00101 00102 unsigned short TCLcd::putch2( short x, short y, unsigned char* c, unsigned short fg, unsigned short bg) 00103 { 00104 unsigned char i,j; 00105 unsigned short select[2] = { bg , fg }; 00106 unsigned short tmp; 00107 unsigned char chr[8]; 00108 00109 tmp = c[0]; 00110 00111 tmp <<= 8; 00112 00113 tmp |= c[1]; 00114 00115 pc.printf( " dat = %02x \r",tmp); 00116 00117 get_font_pt(tmp,&chr[0]); 00118 00119 for(i=0;i<8;i+=1) 00120 { 00121 for(j=0;j<8;j++) 00122 { 00123 lcd_Pixel(x+j, y+i, select[((chr[i] >> (7-j)) & 0x01)]); 00124 } 00125 } 00126 x += 8; 00127 return x; 00128 } 00129 00130 TCLcd::TCLcd(PinName db10 ,PinName db11 ,PinName db12 ,PinName db13 ,PinName db14 ,PinName db15 ,PinName db16 ,PinName db17 , 00131 PinName wr ,PinName rs ,PinName cs ,PinName reset) : _bus( db10,db11,db12,db13,db14,db15,db16,db17 ) , _wr(wr),_rs(rs),_cs(cs),_reset(reset) 00132 { 00133 int i; 00134 wait_ms(20); 00135 00136 _cs = 1; 00137 _wr = 1; 00138 _reset = 0; 00139 wait_ms(1); 00140 _reset = 1; 00141 wait_ms(25); 00142 00143 lcd_out(0x00E3, 0x3008); // Set internal timing 00144 lcd_out(0x00E7, 0x0012); // Set internal timing 00145 lcd_out(0x00EF, 0x1231); // Set internal timing 00146 lcd_out(0x0001, 0x0000); // set SS and SM bit 00147 lcd_out(0x0002, 0x0700); // set line inversion 00148 lcd_out(0x0003, 0x1018); // set GRAM write direction and BGR=1, 16bit color 00149 lcd_out(0x0004, 0x0000); // Resize register 00150 lcd_out(0x0008, 0x0207); // set the back porch and front porch 00151 lcd_out(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0] 00152 lcd_out(0x000A, 0x0000); // FMARK function 00153 lcd_out(0x000C, 0x0000); // RGB interface setting 00154 lcd_out(0x000D, 0x0000); // Frame marker Position 00155 lcd_out(0x000F, 0x0000); // RGB interface polarity 00156 /********* power on seq **************/ 00157 lcd_out(0x0010, 0x0000); // SAP, BT[3:0], AP[2:0], DSTB, SLP, STB 00158 lcd_out(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0] 00159 lcd_out(0x0012, 0x0000); // VREG1OUT voltage 00160 lcd_out(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude 00161 wait_ms(200); 00162 lcd_out(0x0010, 0x1490); // SAP, BT[3:0], AP[2:0], DSTB, SLP, STB 00163 lcd_out(0x0011, 0x0227); // R11h=0x0221 at VCI=3.3V ,DC1[2:0], DC0[2:0], VC[2:0] 00164 wait_ms(50); 00165 lcd_out(0x0012, 0x001c); // External reference voltage= Vci; 00166 wait_ms(50); 00167 lcd_out(0x0013, 0x0A00); // R13=0F00 when R12=009E;VDV[4:0] for VCOM amplitude 00168 lcd_out(0x0029, 0x000F); // R29=0019 when R12=009E;VCM[5:0] for VCOMH//0012// 00169 lcd_out(0x002B, 0x000D); // Frame Rate = 91Hz 00170 wait_ms(50); 00171 lcd_out(0x0020, 0x0000); // GRAM horizontal Address 00172 lcd_out(0x0021, 0x0000); // GRAM Vertical Address 00173 /********** gammer **********/ 00174 lcd_out(0x0030, 0x0000); 00175 lcd_out(0x0031, 0x0203); 00176 lcd_out(0x0032, 0x0001); 00177 lcd_out(0x0035, 0x0205); 00178 lcd_out(0x0036, 0x030C); 00179 lcd_out(0x0037, 0x0607); 00180 lcd_out(0x0038, 0x0405); 00181 lcd_out(0x0039, 0x0707); 00182 lcd_out(0x003C, 0x0502); 00183 lcd_out(0x003D, 0x1008); 00184 /*********** GRAM *********/ 00185 lcd_out(0x0050, 0x0000); // Horizontal GRAM Start Address 00186 lcd_out(0x0051, 0x00EF); // Horizontal GRAM End Address 00187 lcd_out(0x0052, 0x0000); // Vertical GRAM Start Address 00188 lcd_out(0x0053, 0x013F); // Vertical GRAM Start Address 00189 lcd_out(0x0060, 0xA700); // Gate Scan Line wide dsp 00190 lcd_out(0x0061, 0x0001); // NDL,VLE, REV 00191 lcd_out(0x006A, 0x0000); // set scrolling line 00192 /************* bubun ************/ 00193 lcd_out(0x0080, 0x0000); // p dsp 1 00194 lcd_out(0x0081, 0x0000); // p dsp 1 start addr 00195 lcd_out(0x0082, 0x0000); // p dsp 1 end addr 00196 lcd_out(0x0083, 0x0000); // p dsp 1 00197 lcd_out(0x0084, 0x0000); // p dsp 1 start addr 00198 lcd_out(0x0085, 0x0000); // p dsp 1 end addr 00199 /************** panel ************/ 00200 lcd_out(0x0090, 0x0010); // 1Line Clock Num 00201 lcd_out(0x0092, 0x0600); // Gate Overlap Clock Num 00202 lcd_out(0x0093, 0x0003); // Output Timing 00203 lcd_out(0x0095, 0x0110); // RGB 1Line Clock Num 00204 lcd_out(0x0097, 0x0000); // Output Timing 00205 lcd_out(0x0098, 0x0000); // Output Timing 00206 /***** dsp cont *****/ 00207 lcd_out(0x0007, 0x0133); // 262K color and display ON 00208 wait_ms(100); 00209 00210 memcpy( &fnt_head , &font[0] , 18); 00211 font_head_size = 18 + fnt_head.Tnum * 4; 00212 for (i=0;i<fnt_head.Tnum;i++) 00213 { 00214 fnt_head.Block[i].Start = font[19 + i*4]; 00215 fnt_head.Block[i].Start <<= 8; 00216 fnt_head.Block[i].Start |= font[18 + i*4]; 00217 fnt_head.Block[i].End = font[21 + i*4]; 00218 fnt_head.Block[i].End <<= 8; 00219 fnt_head.Block[i].End |= font[20 + i*4]; 00220 } 00221 font_search_tbl[0] = 0; 00222 00223 for (i=1;i<fnt_head.Tnum;i++) 00224 { 00225 font_search_tbl[i] = (fnt_head.Block[i-1].End - fnt_head.Block[i-1].Start + 1) + font_search_tbl[i-1]; 00226 } 00227 _column = 0; 00228 _row = 8; 00229 } 00230 00231 00232 void TCLcd::lcd_out(unsigned short index, unsigned short data) 00233 { 00234 __disable_fault_irq(); 00235 // Index up byte 00236 _cs = 0; // CS Low 00237 _rs = 0; // Command 00238 //_bus = (index & 0xFF00) | (_bus & 0x00FF); 00239 _bus = index >> 8; 00240 _wr = 0; // WR out 00241 __NOP(); 00242 _wr = 1; 00243 // Index down byte 00244 //_bus = ((index<<8)&0xFF00) | (_bus & 0x00FF); 00245 _bus = index & 0x00FF; 00246 _wr = 0; // WR out 00247 __NOP(); 00248 _wr = 1; 00249 // Data up byte 00250 _rs = 1; // Data 00251 //_bus = (data & 0xFF00) | (_bus & 0x00FF); 00252 _bus = data >> 8; 00253 _wr = 0; // WR out 00254 __NOP(); 00255 _wr = 1; 00256 // Index down byte 00257 //_bus = ((data<<8)&0xFF00) | (_bus & 0x00FF); 00258 _bus = data & 0x00FF; 00259 _wr = 0; // WR out 00260 __NOP(); 00261 _wr = 1; 00262 _cs = 1; // CS High 00263 __enable_fault_irq(); 00264 } 00265 00266 00267 // DSP Clear 00268 void TCLcd::lcd_Clear(unsigned short Color) 00269 { 00270 int i, j; 00271 00272 lcd_out(0x0020, 0); // base set 00273 lcd_out(0x0021, 0); 00274 for( j=0; j<ENDROW; j++){ // Y all 00275 for(i=0; i<ENDCOL; i++){ // X all 00276 lcd_out(0x0022, Color); // own color 00277 } 00278 } 00279 } 00280 00281 00282 00283 /*********************************** 00284 * 1pixel 00285 * (0,0)-(161,131) 00286 ***********************************/ 00287 void TCLcd::lcd_Pixel(short Xpos, short Ypos, unsigned short Color) 00288 { 00289 00290 if((Xpos<ENDCOL) && (Ypos<ENDROW)){ 00291 lcd_out(0x0020, Ypos); // pos 00292 lcd_out(0x0021, Xpos); 00293 lcd_out(0x0022, Color); // dot dsp 00294 } 00295 } 00296 00297 /*************************** 00298 * line 00299 ***************************/ 00300 #define abs(a) (((a)>0) ? (a) : -(a)) 00301 void TCLcd::lcd_Line(short x0, short y0, short x1, short y1, unsigned short Color) 00302 { 00303 short steep, t; 00304 short deltax, deltay, error; 00305 short x, y; 00306 short ystep; 00307 00308 y0=ENDROW-y0 -1; // 00309 y1=ENDROW-y1 -1; 00310 00311 steep = (abs(y1 - y0) > abs(x1 - x0)); 00312 if(steep){ 00313 t = x0; x0 = y0; y0 = t; 00314 t = x1; x1 = y1; y1 = t; 00315 } 00316 if(x0 > x1) { 00317 t = x0; x0 = x1; x1 = t; 00318 t = y0; y0 = y1; y1 = t; 00319 } 00320 deltax = x1 - x0; // 00321 deltay = abs(y1 - y0); 00322 error = 0; 00323 y = y0; 00324 /// 00325 if(y0 < y1) ystep = 1; else ystep = -1; 00326 /// 00327 for(x=x0; x<=x1; x++) { 00328 if(steep) lcd_Pixel(y,x,Color); else lcd_Pixel(x,y,Color); 00329 error += deltay; 00330 if((error << 1) >= deltax) { 00331 y += ystep; 00332 error -= deltax; 00333 } 00334 } 00335 } 00336 00337 /************************************* 00338 * circle 00339 **************************************/ 00340 void TCLcd::lcd_Circle(int x0, int y0, int r, unsigned short color) 00341 { 00342 int x = r; 00343 int y = 0; 00344 int F = -2 * r + 3; 00345 00346 while(x >= y){ 00347 lcd_Pixel(x0+x, y0+y, color); 00348 lcd_Pixel(x0-x, y0+y, color); 00349 lcd_Pixel(x0+x, y0-y, color); 00350 lcd_Pixel(x0-x, y0-y, color); 00351 lcd_Pixel(x0+y, y0+x, color); 00352 lcd_Pixel(x0-y, y0+x, color); 00353 lcd_Pixel(x0+y, y0-x, color); 00354 lcd_Pixel(x0-y, y0-x, color); 00355 if(F >= 0){ 00356 x--; 00357 F -= 4 * x; 00358 } 00359 y++; 00360 F += 4 * y + 2; 00361 } 00362 } 00363 #if 0 00364 /***************************************** 00365 * char dsp 00366 ******************************************/ 00367 void TCLcd::lcd_Char(char colum, char line, unsigned char letter, unsigned short Color1, unsigned short Color2){ 00368 unsigned char j, i, Mask; 00369 00370 if((colum < XChar) && (line < YLine)){ // 00371 // 00372 for(j=0; j<6; j++){ 00373 // 00374 Mask = 0x80; 00375 for(i=0; i<8; i++){ 00376 // 00377 if((ANKFont[letter][j*3] & Mask) != 0) 00378 lcd_Pixel(colum*12+i+4, line*14+j*2+2, Color1); 00379 else 00380 lcd_Pixel(colum*12+i+4, line*14+j*2+2, Color2); // 00381 // 00382 if((ANKFont[letter][j*3+2] & Mask) != 0) 00383 lcd_Pixel(colum*12+i+8, line*14+j*2+3, Color1); 00384 else 00385 lcd_Pixel(colum*12+i+8, line*14+j*2+3, Color2); // 00386 Mask = Mask >> 1; 00387 } 00388 // 00389 Mask = 0x80; 00390 // 00391 for(i=0; i<4; i++){ 00392 if((ANKFont[letter][j*3+1] & Mask) != 0) 00393 lcd_Pixel(colum*12+i+12, line*14+j*2+2, Color1); 00394 else 00395 lcd_Pixel(colum*12+i+12, line*14+j*2+2, Color2); // 00396 Mask = Mask >> 1; 00397 } 00398 // 00399 for(i=4; i<8; i++){ 00400 if((ANKFont[letter][j*3+1] & Mask) != 0) 00401 lcd_Pixel(colum*12+i, line*14+j*2+3, Color1); 00402 else 00403 lcd_Pixel(colum*12+i, line*14+j*2+3, Color2); // 00404 Mask = Mask >> 1; 00405 } 00406 } 00407 } 00408 } 00409 /****************************** 00410 * str dsp 00411 ******************************/ 00412 void TCLcd::lcd_Str(char colum, char line, char *s, unsigned short Color1, unsigned short Color2) 00413 { 00414 while (*s){ 00415 lcd_Char(colum++, line, *s++, Color1, Color2); 00416 if(colum >= XChar){ 00417 line++; 00418 colum = 0; 00419 if(line >= YLine) 00420 line = 0; 00421 } 00422 } 00423 } 00424 00425 #endif
Generated on Wed Jul 13 2022 15:02:52 by
1.7.2