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.
GLCD_MCB1700.cpp
00001 #include "mbed.h" 00002 /******************************************************************************/ 00003 /* GLCD_SPI_LPC1700.c: LPC1700 low level Graphic LCD (240x320 pixels) driven */ 00004 /* with SPI functions */ 00005 /******************************************************************************/ 00006 /* This file is part of the uVision/ARM development tools. */ 00007 /* Copyright (c) 2005-2010 Keil Software. All rights reserved. */ 00008 /* This software may only be used under the terms of a valid, current, */ 00009 /* end user licence from KEIL for a compatible version of KEIL software */ 00010 /* development tools. Nothing else gives you the right to use this software. */ 00011 /******************************************************************************/ 00012 00013 00014 #include "mbed.h" 00015 #include "GLCD_MCB1700.h" 00016 #include "font_6x8_h.h" 00017 #include "font_16x24_h.h" 00018 00019 /************************** Orientation configuration ************************/ 00020 00021 #define HORIZONTAL 1 /* If vertical = 0, if horizontal = 1 */ 00022 00023 /*********************** Hardware specific configuration **********************/ 00024 00025 /* SPI Interface: SPI3 00026 00027 PINS: 00028 - CS = P0.6 (GPIO pin) 00029 - RS = GND 00030 - WR/SCK = P0.7 (SCK1) 00031 - RD = GND 00032 - SDO = P0.8 (MISO1) 00033 - SDI = P0.9 (MOSI1) */ 00034 00035 #define PIN_CS (1 << 6) 00036 00037 /* SPI_SR - bit definitions */ 00038 #define TFE 0x01 00039 #define RNE 0x04 00040 #define BSY 0x10 00041 00042 /*------------------------- Speed dependant settings -------------------------*/ 00043 00044 /* If processor works on high frequency delay has to be increased, it can be 00045 increased by factor 2^N by this constant */ 00046 #define DELAY_2N 18 00047 00048 /*---------------------- Graphic LCD size definitions ------------------------*/ 00049 00050 #if (HORIZONTAL == 1) 00051 #define WIDTH 320 /* Screen Width (in pixels) */ 00052 #define HEIGHT 240 /* Screen Hight (in pixels) */ 00053 #else 00054 #define WIDTH 240 /* Screen Width (in pixels) */ 00055 #define HEIGHT 320 /* Screen Hight (in pixels) */ 00056 #endif 00057 #define BPP 16 /* Bits per pixel */ 00058 #define BYPP ((BPP+7)/8) /* Bytes per pixel */ 00059 00060 /*--------------- Graphic LCD interface hardware definitions -----------------*/ 00061 00062 /* Pin CS setting to 0 or 1 */ 00063 #define LCD_CS(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_CS) : (LPC_GPIO0->FIOCLR = PIN_CS)); 00064 00065 #define SPI_START (0x70) /* Start byte for SPI transfer */ 00066 #define SPI_RD (0x01) /* WR bit 1 within start */ 00067 #define SPI_WR (0x00) /* WR bit 0 within start */ 00068 #define SPI_DATA (0x02) /* RS bit 1 within start byte */ 00069 #define SPI_INDEX (0x00) /* RS bit 0 within start byte */ 00070 00071 /*---------------------------- Global variables ------------------------------*/ 00072 00073 /******************************************************************************/ 00074 static volatile unsigned short TextColor = Black, BackColor = White; 00075 00076 00077 /************************ Local auxiliary functions ***************************/ 00078 00079 /******************************************************************************* 00080 * Delay in while loop cycles * 00081 * Parameter: cnt: number of while cycles to delay * 00082 * Return: * 00083 *******************************************************************************/ 00084 00085 static void delay (int cnt) { 00086 00087 cnt <<= DELAY_2N; 00088 while (cnt--); 00089 } 00090 00091 00092 /******************************************************************************* 00093 * Send 1 byte over the serial communication * 00094 * Parameter: byte: byte to be sent * 00095 * Return: byte read while sending * 00096 *******************************************************************************/ 00097 00098 static __inline unsigned char spi_send (unsigned char byte) { 00099 00100 LPC_SSP1->DR = byte; 00101 while (!(LPC_SSP1->SR & RNE)); /* Wait for send to finish */ 00102 return (LPC_SSP1->DR); 00103 } 00104 00105 00106 /******************************************************************************* 00107 * Write a command the LCD controller * 00108 * Parameter: cmd: command to be written * 00109 * Return: * 00110 *******************************************************************************/ 00111 00112 static __inline void wr_cmd (unsigned char cmd) { 00113 00114 LCD_CS(0) 00115 spi_send(SPI_START | SPI_WR | SPI_INDEX); /* Write : RS = 0, RW = 0 */ 00116 spi_send(0); 00117 spi_send(cmd); 00118 LCD_CS(1) 00119 } 00120 00121 00122 /******************************************************************************* 00123 * Write data to the LCD controller * 00124 * Parameter: dat: data to be written * 00125 * Return: * 00126 *******************************************************************************/ 00127 00128 static __inline void wr_dat (unsigned short dat) { 00129 00130 LCD_CS(0) 00131 spi_send(SPI_START | SPI_WR | SPI_DATA); /* Write : RS = 1, RW = 0 */ 00132 spi_send((dat >> 8)); /* Write D8..D15 */ 00133 spi_send((dat & 0xFF)); /* Write D0..D7 */ 00134 LCD_CS(1) 00135 } 00136 00137 00138 /******************************************************************************* 00139 * Start of data writing to the LCD controller * 00140 * Parameter: * 00141 * Return: * 00142 *******************************************************************************/ 00143 00144 static __inline void wr_dat_start (void) { 00145 00146 LCD_CS(0) 00147 spi_send(SPI_START | SPI_WR | SPI_DATA); /* Write : RS = 1, RW = 0 */ 00148 } 00149 00150 00151 /******************************************************************************* 00152 * Stop of data writing to the LCD controller * 00153 * Parameter: * 00154 * Return: * 00155 *******************************************************************************/ 00156 00157 static __inline void wr_dat_stop (void) { 00158 00159 LCD_CS(1) 00160 } 00161 00162 00163 /******************************************************************************* 00164 * Data writing to the LCD controller * 00165 * Parameter: dat: data to be written * 00166 * Return: * 00167 *******************************************************************************/ 00168 00169 static __inline void wr_dat_only (unsigned short dat) { 00170 00171 spi_send((dat >> 8)); /* Write D8..D15 */ 00172 spi_send((dat & 0xFF)); /* Write D0..D7 */ 00173 } 00174 00175 00176 /******************************************************************************* 00177 * Read data from the LCD controller * 00178 * Parameter: * 00179 * Return: read data * 00180 *******************************************************************************/ 00181 00182 static __inline unsigned short rd_dat (void) { 00183 unsigned short val = 0; 00184 00185 LCD_CS(0) 00186 spi_send(SPI_START | SPI_RD | SPI_DATA); /* Read: RS = 1, RW = 1 */ 00187 spi_send(0); /* Dummy read 1 */ 00188 val = spi_send(0); /* Read D8..D15 */ 00189 val <<= 8; 00190 val |= spi_send(0); /* Read D0..D7 */ 00191 LCD_CS(1) 00192 return (val); 00193 } 00194 00195 00196 /******************************************************************************* 00197 * Write a value to the to LCD register * 00198 * Parameter: reg: register to be written * 00199 * val: value to write to the register * 00200 *******************************************************************************/ 00201 00202 static __inline void wr_reg (unsigned char reg, unsigned short val) { 00203 00204 wr_cmd(reg); 00205 wr_dat(val); 00206 } 00207 00208 00209 /******************************************************************************* 00210 * Read from the LCD register * 00211 * Parameter: reg: register to be read * 00212 * Return: value read from the register * 00213 *******************************************************************************/ 00214 00215 static unsigned short rd_reg (unsigned char reg) { 00216 00217 wr_cmd(reg); 00218 return(rd_dat()); 00219 } 00220 00221 00222 /************************ Exported functions **********************************/ 00223 00224 /******************************************************************************* 00225 * Initialize the Graphic LCD controller * 00226 * Parameter: * 00227 * Return: * 00228 *******************************************************************************/ 00229 00230 void GLCD_Init (void) { 00231 static unsigned short driverCode; 00232 00233 /* Enable clock for SSP1, clock = CCLK / 2 */ 00234 LPC_SC->PCONP |= 0x00000400; 00235 LPC_SC->PCLKSEL0 |= 0x00200000; 00236 00237 /* Configure the LCD Control pins */ 00238 LPC_PINCON->PINSEL9 &= 0xF0FFFFFF; 00239 LPC_GPIO4->FIODIR |= 0x30000000; 00240 LPC_GPIO4->FIOSET = 0x20000000; 00241 00242 /* SSEL1 is GPIO output set to high */ 00243 LPC_GPIO0->FIODIR |= 0x00000040; 00244 LPC_GPIO0->FIOSET = 0x00000040; 00245 LPC_PINCON->PINSEL0 &= 0xFFF03FFF; 00246 LPC_PINCON->PINSEL0 |= 0x000A8000; 00247 00248 /* Enable SPI in Master Mode, CPOL=1, CPHA=1 */ 00249 /* Max. 12.5 MBit used for Data Transfer @ 100MHz */ 00250 LPC_SSP1->CR0 = 0x01C7; 00251 LPC_SSP1->CPSR = 0x02; 00252 LPC_SSP1->CR1 = 0x02; 00253 00254 delay(5); /* Delay 50 ms */ 00255 driverCode = rd_reg(0x00); 00256 00257 /* Start Initial Sequence --------------------------------------------------*/ 00258 wr_reg(0x01, 0x0100); /* Set SS bit */ 00259 wr_reg(0x02, 0x0700); /* Set 1 line inversion */ 00260 wr_reg(0x04, 0x0000); /* Resize register */ 00261 wr_reg(0x08, 0x0207); /* 2 lines front, 7 back porch */ 00262 wr_reg(0x09, 0x0000); /* Set non-disp area refresh cyc ISC */ 00263 wr_reg(0x0A, 0x0000); /* FMARK function */ 00264 wr_reg(0x0C, 0x0000); /* RGB interface setting */ 00265 wr_reg(0x0D, 0x0000); /* Frame marker Position */ 00266 wr_reg(0x0F, 0x0000); /* RGB interface polarity */ 00267 00268 /* Power On sequence -------------------------------------------------------*/ 00269 wr_reg(0x10, 0x0000); /* Reset Power Control 1 */ 00270 wr_reg(0x11, 0x0000); /* Reset Power Control 2 */ 00271 wr_reg(0x12, 0x0000); /* Reset Power Control 3 */ 00272 wr_reg(0x13, 0x0000); /* Reset Power Control 4 */ 00273 delay(20); /* Discharge cap power voltage (200ms)*/ 00274 wr_reg(0x10, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ 00275 wr_reg(0x11, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */ 00276 delay(5); /* Delay 50 ms */ 00277 wr_reg(0x12, 0x01BD); /* VREG1OUT voltage */ 00278 delay(5); /* Delay 50 ms */ 00279 wr_reg(0x13, 0x1400); /* VDV[4:0] for VCOM amplitude */ 00280 wr_reg(0x29, 0x000E); /* VCM[4:0] for VCOMH */ 00281 delay(5); /* Delay 50 ms */ 00282 wr_reg(0x20, 0x0000); /* GRAM horizontal Address */ 00283 wr_reg(0x21, 0x0000); /* GRAM Vertical Address */ 00284 00285 /* Adjust the Gamma Curve --------------------------------------------------*/ 00286 if (driverCode == 0x5408) { /* LCD with SPFD5408 LCD Controller */ 00287 wr_reg(0x30, 0x0B0D); 00288 wr_reg(0x31, 0x1923); 00289 wr_reg(0x32, 0x1C26); 00290 wr_reg(0x33, 0x261C); 00291 wr_reg(0x34, 0x2419); 00292 wr_reg(0x35, 0x0D0B); 00293 wr_reg(0x36, 0x1006); 00294 wr_reg(0x37, 0x0610); 00295 wr_reg(0x38, 0x0706); 00296 wr_reg(0x39, 0x0304); 00297 wr_reg(0x3A, 0x0E05); 00298 wr_reg(0x3B, 0x0E01); 00299 wr_reg(0x3C, 0x010E); 00300 wr_reg(0x3D, 0x050E); 00301 wr_reg(0x3E, 0x0403); 00302 wr_reg(0x3F, 0x0607); 00303 } 00304 else { /* LCD with other LCD Controller */ 00305 wr_reg(0x30, 0x0006); 00306 wr_reg(0x31, 0x0101); 00307 wr_reg(0x32, 0x0003); 00308 wr_reg(0x35, 0x0106); 00309 wr_reg(0x36, 0x0B02); 00310 wr_reg(0x37, 0x0302); 00311 wr_reg(0x38, 0x0707); 00312 wr_reg(0x39, 0x0007); 00313 wr_reg(0x3C, 0x0600); 00314 wr_reg(0x3D, 0x020B); 00315 } 00316 00317 /* Set GRAM area -----------------------------------------------------------*/ 00318 wr_reg(0x50, 0x0000); /* Horizontal GRAM Start Address */ 00319 wr_reg(0x51, (HEIGHT-1)); /* Horizontal GRAM End Address */ 00320 wr_reg(0x52, 0x0000); /* Vertical GRAM Start Address */ 00321 wr_reg(0x53, (WIDTH-1)); /* Vertical GRAM End Address */ 00322 if (driverCode == 0x5408) /* LCD with SPFD5408 LCD Controller */ 00323 wr_reg(0x60, 0xA700); /* Gate Scan Line */ 00324 else /* LCD with other LCD Controller */ 00325 wr_reg(0x60, 0x2700); /* Gate Scan Line */ 00326 wr_reg(0x61, 0x0001); /* NDL,VLE, REV */ 00327 wr_reg(0x6A, 0x0000); /* Set scrolling line */ 00328 00329 /* Partial Display Control -------------------------------------------------*/ 00330 wr_reg(0x80, 0x0000); 00331 wr_reg(0x81, 0x0000); 00332 wr_reg(0x82, 0x0000); 00333 wr_reg(0x83, 0x0000); 00334 wr_reg(0x84, 0x0000); 00335 wr_reg(0x85, 0x0000); 00336 00337 /* Panel Control -----------------------------------------------------------*/ 00338 wr_reg(0x90, 0x0010); 00339 wr_reg(0x92, 0x0000); 00340 wr_reg(0x93, 0x0003); 00341 wr_reg(0x95, 0x0110); 00342 wr_reg(0x97, 0x0000); 00343 wr_reg(0x98, 0x0000); 00344 00345 /* Set GRAM write direction 00346 I/D=11 (Horizontal : increment, Vertical : increment) */ 00347 00348 #if (HORIZONTAL == 1) 00349 /* AM=1 (address is updated in vertical writing direction) */ 00350 wr_reg(0x03, 0x1038); 00351 #else 00352 /* AM=0 (address is updated in horizontal writing direction) */ 00353 wr_reg(0x03, 0x1030); 00354 #endif 00355 00356 wr_reg(0x07, 0x0137); /* 262K color and display ON */ 00357 LPC_GPIO4->FIOSET = 0x10000000; 00358 } 00359 00360 00361 /******************************************************************************* 00362 * Set draw window region * 00363 * Parameter: x: horizontal position * 00364 * y: vertical position * 00365 * w: window width in pixel * 00366 * h: window height in pixels * 00367 * Return: * 00368 *******************************************************************************/ 00369 00370 void GLCD_SetWindow (unsigned int x, unsigned int y, unsigned int w, unsigned int h) { 00371 00372 wr_reg(0x50, x); /* Horizontal GRAM Start Address */ 00373 wr_reg(0x51, x+w-1); /* Horizontal GRAM End Address (-1) */ 00374 wr_reg(0x52, y); /* Vertical GRAM Start Address */ 00375 wr_reg(0x53, y+h-1); /* Vertical GRAM End Address (-1) */ 00376 00377 wr_reg(0x20, x); 00378 wr_reg(0x21, y); 00379 } 00380 00381 00382 /******************************************************************************* 00383 * Set draw window region to whole screen * 00384 * Parameter: * 00385 * Return: * 00386 *******************************************************************************/ 00387 00388 void GLCD_WindowMax (void) { 00389 00390 #if (HORIZONTAL == 1) 00391 GLCD_SetWindow (0, 0, HEIGHT, WIDTH); 00392 #else 00393 GLCD_SetWindow (0, 0, WIDTH, HEIGHT); 00394 #endif 00395 } 00396 00397 00398 /******************************************************************************* 00399 * Draw a pixel in foreground color * 00400 * Parameter: x: horizontal position * 00401 * y: vertical position * 00402 * Return: * 00403 *******************************************************************************/ 00404 00405 void GLCD_PutPixel (unsigned int x, unsigned int y) { 00406 00407 #if (HORIZONTAL == 1) 00408 wr_reg(0x20, y); 00409 wr_reg(0x21, WIDTH-1-x); 00410 #else 00411 wr_reg(0x20, x); 00412 wr_reg(0x21, y); 00413 #endif 00414 wr_cmd(0x22); 00415 wr_dat(TextColor); 00416 } 00417 00418 00419 /******************************************************************************* 00420 * Set foreground color * 00421 * Parameter: color: foreground color * 00422 * Return: * 00423 *******************************************************************************/ 00424 00425 void GLCD_SetTextColor (unsigned short color) { 00426 00427 TextColor = color; 00428 } 00429 00430 00431 /******************************************************************************* 00432 * Set background color * 00433 * Parameter: color: background color * 00434 * Return: * 00435 *******************************************************************************/ 00436 00437 void GLCD_SetBackColor (unsigned short color) { 00438 00439 BackColor = color; 00440 } 00441 00442 00443 /******************************************************************************* 00444 * Clear display * 00445 * Parameter: color: display clearing color * 00446 * Return: * 00447 *******************************************************************************/ 00448 00449 void GLCD_Clear (unsigned short color) { 00450 unsigned int i; 00451 00452 GLCD_WindowMax(); 00453 wr_cmd(0x22); 00454 wr_dat_start(); 00455 for(i = 0; i < (WIDTH*HEIGHT); i++) 00456 wr_dat_only(color); 00457 wr_dat_stop(); 00458 } 00459 00460 00461 /******************************************************************************* 00462 * Draw character on given position * 00463 * Parameter: x: horizontal position * 00464 * y: vertical position * 00465 * cw: character width in pixel * 00466 * ch: character height in pixels * 00467 * c: pointer to character bitmap * 00468 * Return: * 00469 *******************************************************************************/ 00470 00471 void GLCD_DrawChar_U8 (unsigned int x, unsigned int y, unsigned int cw, unsigned int ch, unsigned char *c) { 00472 int idx = 0, i, j; 00473 00474 #if (HORIZONTAL == 1) 00475 x = WIDTH-x-cw; 00476 GLCD_SetWindow(y, x, ch, cw); 00477 #else 00478 GLCD_SetWindow(x, y, cw, ch); 00479 #endif 00480 wr_cmd(0x22); 00481 wr_dat_start(); 00482 for (j = 0; j < ch; j++) { 00483 #if (HORIZONTAL == 1) 00484 for (i = cw-1; i >= 0; i--) { 00485 #else 00486 for (i = 0; i <= cw-1; i++) { 00487 #endif 00488 if((c[idx] & (1 << i)) == 0x00) { 00489 wr_dat_only(BackColor); 00490 } else { 00491 wr_dat_only(TextColor); 00492 } 00493 } 00494 c++; 00495 } 00496 wr_dat_stop(); 00497 } 00498 00499 00500 /******************************************************************************* 00501 * Draw character on given position * 00502 * Parameter: x: horizontal position * 00503 * y: vertical position * 00504 * cw: character width in pixel * 00505 * ch: character height in pixels * 00506 * c: pointer to character bitmap * 00507 * Return: * 00508 *******************************************************************************/ 00509 00510 void GLCD_DrawChar_U16 (unsigned int x, unsigned int y, unsigned int cw, unsigned int ch, unsigned short *c) { 00511 int idx = 0, i, j; 00512 00513 #if (HORIZONTAL == 1) 00514 x = WIDTH-x-cw; 00515 GLCD_SetWindow(y, x, ch, cw); 00516 #else 00517 GLCD_SetWindow(x, y, cw, ch); 00518 #endif 00519 wr_cmd(0x22); 00520 wr_dat_start(); 00521 for (j = 0; j < ch; j++) { 00522 #if (HORIZONTAL == 1) 00523 for (i = cw-1; i >= 0; i--) { 00524 #else 00525 for (i = 0; i <= cw-1; i++) { 00526 #endif 00527 if((c[idx] & (1 << i)) == 0x00) { 00528 wr_dat_only(BackColor); 00529 } else { 00530 wr_dat_only(TextColor); 00531 } 00532 } 00533 c++; 00534 } 00535 wr_dat_stop(); 00536 } 00537 00538 00539 /******************************************************************************* 00540 * Disply character on given line * 00541 * Parameter: ln: line number * 00542 * col: column number * 00543 * fi: font index (0 = 6x8, 1 = 16x24) * 00544 * c: ascii character * 00545 * Return: * 00546 *******************************************************************************/ 00547 00548 void GLCD_DisplayChar (unsigned int ln, unsigned int col, unsigned char fi, unsigned char c) { 00549 00550 c -= 32; 00551 switch (fi) { 00552 case 0: /* Font 6 x 8 */ 00553 GLCD_DrawChar_U8 (col * 6, ln * 8, 6, 8, (unsigned char *)&Font_6x8_h [c * 8]); 00554 break; 00555 case 1: /* Font 16 x 24 */ 00556 GLCD_DrawChar_U16(col * 16, ln * 24, 16, 24, (unsigned short *)&Font_16x24_h[c * 24]); 00557 break; 00558 } 00559 } 00560 00561 00562 /******************************************************************************* 00563 * Disply string on given line * 00564 * Parameter: ln: line number * 00565 * col: column number * 00566 * fi: font index (0 = 6x8, 1 = 16x24) * 00567 * s: pointer to string * 00568 * Return: * 00569 *******************************************************************************/ 00570 00571 void GLCD_DisplayString (unsigned int ln, unsigned int col, unsigned char fi, unsigned char *s) { 00572 00573 GLCD_WindowMax(); 00574 while (*s) { 00575 GLCD_DisplayChar(ln, col++, fi, *s++); 00576 } 00577 } 00578 00579 00580 /******************************************************************************* 00581 * Clear given line * 00582 * Parameter: ln: line number * 00583 * fi: font index (0 = 6x8, 1 = 16x24) * 00584 * Return: * 00585 *******************************************************************************/ 00586 00587 void GLCD_ClearLn (unsigned int ln, unsigned char fi) { 00588 unsigned char i; 00589 unsigned char buf[60]; 00590 00591 GLCD_WindowMax(); 00592 switch (fi) { 00593 case 0: /* Font 6 x 8 */ 00594 for (i = 0; i < (WIDTH+5)/6; i++) 00595 buf[i] = ' '; 00596 buf[i+1] = 0; 00597 break; 00598 case 1: /* Font 16 x 24 */ 00599 for (i = 0; i < (WIDTH+15)/16; i++) 00600 buf[i] = ' '; 00601 buf[i+1] = 0; 00602 break; 00603 } 00604 GLCD_DisplayString (ln, 0, fi, buf); 00605 } 00606 00607 /******************************************************************************* 00608 * Draw bargraph * 00609 * Parameter: x: horizontal position * 00610 * y: vertical position * 00611 * w: maximum width of bargraph (in pixels) * 00612 * val: value of active bargraph (in 1/1024) * 00613 * Return: * 00614 *******************************************************************************/ 00615 00616 void GLCD_Bargraph (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) { 00617 int i,j; 00618 00619 val = (val * w) >> 10; /* Scale value */ 00620 #if (HORIZONTAL == 1) 00621 x = WIDTH-x-w; 00622 GLCD_SetWindow(y, x, h, w); 00623 #else 00624 GLCD_SetWindow(x, y, w, h); 00625 #endif 00626 wr_cmd(0x22); 00627 wr_dat_start(); 00628 for (i = 0; i < h; i++) { 00629 #if (HORIZONTAL == 1) 00630 for (j = w-1; j >= 0; j--) { 00631 #else 00632 for (j = 0; j <= w-1; j++) { 00633 #endif 00634 if(j >= val) { 00635 wr_dat_only(BackColor); 00636 } else { 00637 wr_dat_only(TextColor); 00638 } 00639 } 00640 } 00641 wr_dat_stop(); 00642 } 00643 00644 00645 /******************************************************************************* 00646 * Display graphical bitmap image at position x horizontally and y vertically * 00647 * (This function is optimized for 16 bits per pixel format, it has to be * 00648 * adapted for any other bits per pixel format) * 00649 * Parameter: x: horizontal position * 00650 * y: vertical position * 00651 * w: width of bitmap * 00652 * h: height of bitmap * 00653 * bitmap: address at which the bitmap data resides * 00654 * Return: * 00655 *******************************************************************************/ 00656 00657 void GLCD_Bitmap (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap) { 00658 unsigned int i, j; 00659 unsigned short *bitmap_ptr = (unsigned short *)bitmap; 00660 00661 #if (HORIZONTAL == 1) 00662 x = WIDTH-x-w; 00663 GLCD_SetWindow(y, x, h, w); 00664 #else 00665 GLCD_SetWindow(x, y, w, h); 00666 #endif 00667 wr_cmd(0x22); 00668 wr_dat_start(); 00669 for (j = 0; j < h; j++) { 00670 #if (HORIZONTAL == 1) 00671 for (i = 0; i < w; i++) { 00672 wr_dat_only(*bitmap_ptr++); 00673 } 00674 #else 00675 bitmap_ptr += w-1; 00676 for (i = 0; i < w; i++) { 00677 wr_dat_only(*bitmap_ptr--); 00678 } 00679 bitmap_ptr += w+1; 00680 #endif 00681 } 00682 wr_dat_stop(); 00683 } 00684 00685 00686 /******************************************************************************* 00687 * Display graphical bmp file image at position x horizontally and y vertically * 00688 * (This function is optimized for 16 bits per pixel format, it has to be * 00689 * adapted for any other bits per pixel format) * 00690 * Parameter: x: horizontal position * 00691 * y: vertical position * 00692 * w: width of bitmap * 00693 * h: height of bitmap * 00694 * bmp: address at which the bmp data resides * 00695 * Return: * 00696 *******************************************************************************/ 00697 00698 void GLCD_Bmp (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bmp) { 00699 unsigned int i, j; 00700 unsigned short *bitmap_ptr = (unsigned short *)bmp; 00701 00702 #if (HORIZONTAL == 1) 00703 x = WIDTH-x-w; 00704 GLCD_SetWindow(y, x, h, w); 00705 #else 00706 GLCD_SetWindow(x, y, w, h); 00707 #endif 00708 wr_cmd(0x22); 00709 wr_dat_start(); 00710 #if (HORIZONTAL == 1) 00711 bitmap_ptr += (h*w)-1; 00712 for (j = 0; j < h; j++) { 00713 for (i = 0; i < w; i++) { 00714 wr_dat_only(*bitmap_ptr--); 00715 } 00716 } 00717 #else 00718 bitmap_ptr += ((h-1)*w); 00719 for (j = 0; j < h; j++) { 00720 for (i = 0; i < w; i++) { 00721 wr_dat_only(*bitmap_ptr++); 00722 } 00723 bitmap_ptr -= 2*w; 00724 } 00725 #endif 00726 wr_dat_stop(); 00727 } 00728 00729 00730 /******************************************************************************* 00731 * Scroll content of the whole display for dy pixels vertically * 00732 * Parameter: dy: number of pixels for vertical scroll * 00733 * Return: * 00734 *******************************************************************************/ 00735 00736 void GLCD_ScrollVertical (unsigned int dy) { 00737 #if (HORIZONTAL == 0) 00738 static unsigned int y = 0; 00739 00740 y = y + dy; 00741 while (y >= HEIGHT) 00742 y -= HEIGHT; 00743 00744 wr_reg(0x6A, y); 00745 wr_reg(0x61, 3); 00746 #endif 00747 } 00748 00749 /******************************************************************************/
Generated on Mon Jul 18 2022 02:30:29 by
1.7.2