display control QVGA TFT MCB1700 KEIL
GLCD_MCB1700.cpp@1:0ae206eb6e55, 2015-02-13 (annotated)
- Committer:
- fblanc
- Date:
- Fri Feb 13 14:33:27 2015 +0000
- Revision:
- 1:0ae206eb6e55
- Parent:
- GLCD_MCB1700.c@0:b96b9110daf9
bug 2 main() ?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fblanc | 0:b96b9110daf9 | 1 | #include "mbed.h" |
fblanc | 0:b96b9110daf9 | 2 | /******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 3 | /* GLCD_SPI_LPC1700.c: LPC1700 low level Graphic LCD (240x320 pixels) driven */ |
fblanc | 0:b96b9110daf9 | 4 | /* with SPI functions */ |
fblanc | 0:b96b9110daf9 | 5 | /******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 6 | /* This file is part of the uVision/ARM development tools. */ |
fblanc | 0:b96b9110daf9 | 7 | /* Copyright (c) 2005-2010 Keil Software. All rights reserved. */ |
fblanc | 0:b96b9110daf9 | 8 | /* This software may only be used under the terms of a valid, current, */ |
fblanc | 0:b96b9110daf9 | 9 | /* end user licence from KEIL for a compatible version of KEIL software */ |
fblanc | 0:b96b9110daf9 | 10 | /* development tools. Nothing else gives you the right to use this software. */ |
fblanc | 0:b96b9110daf9 | 11 | /******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 12 | |
fblanc | 0:b96b9110daf9 | 13 | |
fblanc | 0:b96b9110daf9 | 14 | #include "mbed.h" |
fblanc | 0:b96b9110daf9 | 15 | #include "GLCD_MCB1700.h" |
fblanc | 0:b96b9110daf9 | 16 | #include "font_6x8_h.h" |
fblanc | 0:b96b9110daf9 | 17 | #include "font_16x24_h.h" |
fblanc | 0:b96b9110daf9 | 18 | |
fblanc | 0:b96b9110daf9 | 19 | /************************** Orientation configuration ************************/ |
fblanc | 0:b96b9110daf9 | 20 | |
fblanc | 0:b96b9110daf9 | 21 | #define HORIZONTAL 1 /* If vertical = 0, if horizontal = 1 */ |
fblanc | 0:b96b9110daf9 | 22 | |
fblanc | 0:b96b9110daf9 | 23 | /*********************** Hardware specific configuration **********************/ |
fblanc | 0:b96b9110daf9 | 24 | |
fblanc | 0:b96b9110daf9 | 25 | /* SPI Interface: SPI3 |
fblanc | 0:b96b9110daf9 | 26 | |
fblanc | 0:b96b9110daf9 | 27 | PINS: |
fblanc | 0:b96b9110daf9 | 28 | - CS = P0.6 (GPIO pin) |
fblanc | 0:b96b9110daf9 | 29 | - RS = GND |
fblanc | 0:b96b9110daf9 | 30 | - WR/SCK = P0.7 (SCK1) |
fblanc | 0:b96b9110daf9 | 31 | - RD = GND |
fblanc | 0:b96b9110daf9 | 32 | - SDO = P0.8 (MISO1) |
fblanc | 0:b96b9110daf9 | 33 | - SDI = P0.9 (MOSI1) */ |
fblanc | 0:b96b9110daf9 | 34 | |
fblanc | 0:b96b9110daf9 | 35 | #define PIN_CS (1 << 6) |
fblanc | 0:b96b9110daf9 | 36 | |
fblanc | 0:b96b9110daf9 | 37 | /* SPI_SR - bit definitions */ |
fblanc | 0:b96b9110daf9 | 38 | #define TFE 0x01 |
fblanc | 0:b96b9110daf9 | 39 | #define RNE 0x04 |
fblanc | 0:b96b9110daf9 | 40 | #define BSY 0x10 |
fblanc | 0:b96b9110daf9 | 41 | |
fblanc | 0:b96b9110daf9 | 42 | /*------------------------- Speed dependant settings -------------------------*/ |
fblanc | 0:b96b9110daf9 | 43 | |
fblanc | 0:b96b9110daf9 | 44 | /* If processor works on high frequency delay has to be increased, it can be |
fblanc | 0:b96b9110daf9 | 45 | increased by factor 2^N by this constant */ |
fblanc | 0:b96b9110daf9 | 46 | #define DELAY_2N 18 |
fblanc | 0:b96b9110daf9 | 47 | |
fblanc | 0:b96b9110daf9 | 48 | /*---------------------- Graphic LCD size definitions ------------------------*/ |
fblanc | 0:b96b9110daf9 | 49 | |
fblanc | 0:b96b9110daf9 | 50 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 51 | #define WIDTH 320 /* Screen Width (in pixels) */ |
fblanc | 0:b96b9110daf9 | 52 | #define HEIGHT 240 /* Screen Hight (in pixels) */ |
fblanc | 0:b96b9110daf9 | 53 | #else |
fblanc | 0:b96b9110daf9 | 54 | #define WIDTH 240 /* Screen Width (in pixels) */ |
fblanc | 0:b96b9110daf9 | 55 | #define HEIGHT 320 /* Screen Hight (in pixels) */ |
fblanc | 0:b96b9110daf9 | 56 | #endif |
fblanc | 0:b96b9110daf9 | 57 | #define BPP 16 /* Bits per pixel */ |
fblanc | 0:b96b9110daf9 | 58 | #define BYPP ((BPP+7)/8) /* Bytes per pixel */ |
fblanc | 0:b96b9110daf9 | 59 | |
fblanc | 0:b96b9110daf9 | 60 | /*--------------- Graphic LCD interface hardware definitions -----------------*/ |
fblanc | 0:b96b9110daf9 | 61 | |
fblanc | 0:b96b9110daf9 | 62 | /* Pin CS setting to 0 or 1 */ |
fblanc | 0:b96b9110daf9 | 63 | #define LCD_CS(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_CS) : (LPC_GPIO0->FIOCLR = PIN_CS)); |
fblanc | 0:b96b9110daf9 | 64 | |
fblanc | 0:b96b9110daf9 | 65 | #define SPI_START (0x70) /* Start byte for SPI transfer */ |
fblanc | 0:b96b9110daf9 | 66 | #define SPI_RD (0x01) /* WR bit 1 within start */ |
fblanc | 0:b96b9110daf9 | 67 | #define SPI_WR (0x00) /* WR bit 0 within start */ |
fblanc | 0:b96b9110daf9 | 68 | #define SPI_DATA (0x02) /* RS bit 1 within start byte */ |
fblanc | 0:b96b9110daf9 | 69 | #define SPI_INDEX (0x00) /* RS bit 0 within start byte */ |
fblanc | 0:b96b9110daf9 | 70 | |
fblanc | 0:b96b9110daf9 | 71 | /*---------------------------- Global variables ------------------------------*/ |
fblanc | 0:b96b9110daf9 | 72 | |
fblanc | 0:b96b9110daf9 | 73 | /******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 74 | static volatile unsigned short TextColor = Black, BackColor = White; |
fblanc | 0:b96b9110daf9 | 75 | |
fblanc | 0:b96b9110daf9 | 76 | |
fblanc | 0:b96b9110daf9 | 77 | /************************ Local auxiliary functions ***************************/ |
fblanc | 0:b96b9110daf9 | 78 | |
fblanc | 0:b96b9110daf9 | 79 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 80 | * Delay in while loop cycles * |
fblanc | 0:b96b9110daf9 | 81 | * Parameter: cnt: number of while cycles to delay * |
fblanc | 0:b96b9110daf9 | 82 | * Return: * |
fblanc | 0:b96b9110daf9 | 83 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 84 | |
fblanc | 0:b96b9110daf9 | 85 | static void delay (int cnt) { |
fblanc | 0:b96b9110daf9 | 86 | |
fblanc | 0:b96b9110daf9 | 87 | cnt <<= DELAY_2N; |
fblanc | 0:b96b9110daf9 | 88 | while (cnt--); |
fblanc | 0:b96b9110daf9 | 89 | } |
fblanc | 0:b96b9110daf9 | 90 | |
fblanc | 0:b96b9110daf9 | 91 | |
fblanc | 0:b96b9110daf9 | 92 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 93 | * Send 1 byte over the serial communication * |
fblanc | 0:b96b9110daf9 | 94 | * Parameter: byte: byte to be sent * |
fblanc | 0:b96b9110daf9 | 95 | * Return: byte read while sending * |
fblanc | 0:b96b9110daf9 | 96 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 97 | |
fblanc | 0:b96b9110daf9 | 98 | static __inline unsigned char spi_send (unsigned char byte) { |
fblanc | 0:b96b9110daf9 | 99 | |
fblanc | 0:b96b9110daf9 | 100 | LPC_SSP1->DR = byte; |
fblanc | 0:b96b9110daf9 | 101 | while (!(LPC_SSP1->SR & RNE)); /* Wait for send to finish */ |
fblanc | 0:b96b9110daf9 | 102 | return (LPC_SSP1->DR); |
fblanc | 0:b96b9110daf9 | 103 | } |
fblanc | 0:b96b9110daf9 | 104 | |
fblanc | 0:b96b9110daf9 | 105 | |
fblanc | 0:b96b9110daf9 | 106 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 107 | * Write a command the LCD controller * |
fblanc | 0:b96b9110daf9 | 108 | * Parameter: cmd: command to be written * |
fblanc | 0:b96b9110daf9 | 109 | * Return: * |
fblanc | 0:b96b9110daf9 | 110 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 111 | |
fblanc | 0:b96b9110daf9 | 112 | static __inline void wr_cmd (unsigned char cmd) { |
fblanc | 0:b96b9110daf9 | 113 | |
fblanc | 0:b96b9110daf9 | 114 | LCD_CS(0) |
fblanc | 0:b96b9110daf9 | 115 | spi_send(SPI_START | SPI_WR | SPI_INDEX); /* Write : RS = 0, RW = 0 */ |
fblanc | 0:b96b9110daf9 | 116 | spi_send(0); |
fblanc | 0:b96b9110daf9 | 117 | spi_send(cmd); |
fblanc | 0:b96b9110daf9 | 118 | LCD_CS(1) |
fblanc | 0:b96b9110daf9 | 119 | } |
fblanc | 0:b96b9110daf9 | 120 | |
fblanc | 0:b96b9110daf9 | 121 | |
fblanc | 0:b96b9110daf9 | 122 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 123 | * Write data to the LCD controller * |
fblanc | 0:b96b9110daf9 | 124 | * Parameter: dat: data to be written * |
fblanc | 0:b96b9110daf9 | 125 | * Return: * |
fblanc | 0:b96b9110daf9 | 126 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 127 | |
fblanc | 0:b96b9110daf9 | 128 | static __inline void wr_dat (unsigned short dat) { |
fblanc | 0:b96b9110daf9 | 129 | |
fblanc | 0:b96b9110daf9 | 130 | LCD_CS(0) |
fblanc | 0:b96b9110daf9 | 131 | spi_send(SPI_START | SPI_WR | SPI_DATA); /* Write : RS = 1, RW = 0 */ |
fblanc | 0:b96b9110daf9 | 132 | spi_send((dat >> 8)); /* Write D8..D15 */ |
fblanc | 0:b96b9110daf9 | 133 | spi_send((dat & 0xFF)); /* Write D0..D7 */ |
fblanc | 0:b96b9110daf9 | 134 | LCD_CS(1) |
fblanc | 0:b96b9110daf9 | 135 | } |
fblanc | 0:b96b9110daf9 | 136 | |
fblanc | 0:b96b9110daf9 | 137 | |
fblanc | 0:b96b9110daf9 | 138 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 139 | * Start of data writing to the LCD controller * |
fblanc | 0:b96b9110daf9 | 140 | * Parameter: * |
fblanc | 0:b96b9110daf9 | 141 | * Return: * |
fblanc | 0:b96b9110daf9 | 142 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 143 | |
fblanc | 0:b96b9110daf9 | 144 | static __inline void wr_dat_start (void) { |
fblanc | 0:b96b9110daf9 | 145 | |
fblanc | 0:b96b9110daf9 | 146 | LCD_CS(0) |
fblanc | 0:b96b9110daf9 | 147 | spi_send(SPI_START | SPI_WR | SPI_DATA); /* Write : RS = 1, RW = 0 */ |
fblanc | 0:b96b9110daf9 | 148 | } |
fblanc | 0:b96b9110daf9 | 149 | |
fblanc | 0:b96b9110daf9 | 150 | |
fblanc | 0:b96b9110daf9 | 151 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 152 | * Stop of data writing to the LCD controller * |
fblanc | 0:b96b9110daf9 | 153 | * Parameter: * |
fblanc | 0:b96b9110daf9 | 154 | * Return: * |
fblanc | 0:b96b9110daf9 | 155 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 156 | |
fblanc | 0:b96b9110daf9 | 157 | static __inline void wr_dat_stop (void) { |
fblanc | 0:b96b9110daf9 | 158 | |
fblanc | 0:b96b9110daf9 | 159 | LCD_CS(1) |
fblanc | 0:b96b9110daf9 | 160 | } |
fblanc | 0:b96b9110daf9 | 161 | |
fblanc | 0:b96b9110daf9 | 162 | |
fblanc | 0:b96b9110daf9 | 163 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 164 | * Data writing to the LCD controller * |
fblanc | 0:b96b9110daf9 | 165 | * Parameter: dat: data to be written * |
fblanc | 0:b96b9110daf9 | 166 | * Return: * |
fblanc | 0:b96b9110daf9 | 167 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 168 | |
fblanc | 0:b96b9110daf9 | 169 | static __inline void wr_dat_only (unsigned short dat) { |
fblanc | 0:b96b9110daf9 | 170 | |
fblanc | 0:b96b9110daf9 | 171 | spi_send((dat >> 8)); /* Write D8..D15 */ |
fblanc | 0:b96b9110daf9 | 172 | spi_send((dat & 0xFF)); /* Write D0..D7 */ |
fblanc | 0:b96b9110daf9 | 173 | } |
fblanc | 0:b96b9110daf9 | 174 | |
fblanc | 0:b96b9110daf9 | 175 | |
fblanc | 0:b96b9110daf9 | 176 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 177 | * Read data from the LCD controller * |
fblanc | 0:b96b9110daf9 | 178 | * Parameter: * |
fblanc | 0:b96b9110daf9 | 179 | * Return: read data * |
fblanc | 0:b96b9110daf9 | 180 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 181 | |
fblanc | 0:b96b9110daf9 | 182 | static __inline unsigned short rd_dat (void) { |
fblanc | 0:b96b9110daf9 | 183 | unsigned short val = 0; |
fblanc | 0:b96b9110daf9 | 184 | |
fblanc | 0:b96b9110daf9 | 185 | LCD_CS(0) |
fblanc | 0:b96b9110daf9 | 186 | spi_send(SPI_START | SPI_RD | SPI_DATA); /* Read: RS = 1, RW = 1 */ |
fblanc | 0:b96b9110daf9 | 187 | spi_send(0); /* Dummy read 1 */ |
fblanc | 0:b96b9110daf9 | 188 | val = spi_send(0); /* Read D8..D15 */ |
fblanc | 0:b96b9110daf9 | 189 | val <<= 8; |
fblanc | 0:b96b9110daf9 | 190 | val |= spi_send(0); /* Read D0..D7 */ |
fblanc | 0:b96b9110daf9 | 191 | LCD_CS(1) |
fblanc | 0:b96b9110daf9 | 192 | return (val); |
fblanc | 0:b96b9110daf9 | 193 | } |
fblanc | 0:b96b9110daf9 | 194 | |
fblanc | 0:b96b9110daf9 | 195 | |
fblanc | 0:b96b9110daf9 | 196 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 197 | * Write a value to the to LCD register * |
fblanc | 0:b96b9110daf9 | 198 | * Parameter: reg: register to be written * |
fblanc | 0:b96b9110daf9 | 199 | * val: value to write to the register * |
fblanc | 0:b96b9110daf9 | 200 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 201 | |
fblanc | 0:b96b9110daf9 | 202 | static __inline void wr_reg (unsigned char reg, unsigned short val) { |
fblanc | 0:b96b9110daf9 | 203 | |
fblanc | 0:b96b9110daf9 | 204 | wr_cmd(reg); |
fblanc | 0:b96b9110daf9 | 205 | wr_dat(val); |
fblanc | 0:b96b9110daf9 | 206 | } |
fblanc | 0:b96b9110daf9 | 207 | |
fblanc | 0:b96b9110daf9 | 208 | |
fblanc | 0:b96b9110daf9 | 209 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 210 | * Read from the LCD register * |
fblanc | 0:b96b9110daf9 | 211 | * Parameter: reg: register to be read * |
fblanc | 0:b96b9110daf9 | 212 | * Return: value read from the register * |
fblanc | 0:b96b9110daf9 | 213 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 214 | |
fblanc | 0:b96b9110daf9 | 215 | static unsigned short rd_reg (unsigned char reg) { |
fblanc | 0:b96b9110daf9 | 216 | |
fblanc | 0:b96b9110daf9 | 217 | wr_cmd(reg); |
fblanc | 0:b96b9110daf9 | 218 | return(rd_dat()); |
fblanc | 0:b96b9110daf9 | 219 | } |
fblanc | 0:b96b9110daf9 | 220 | |
fblanc | 0:b96b9110daf9 | 221 | |
fblanc | 0:b96b9110daf9 | 222 | /************************ Exported functions **********************************/ |
fblanc | 0:b96b9110daf9 | 223 | |
fblanc | 0:b96b9110daf9 | 224 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 225 | * Initialize the Graphic LCD controller * |
fblanc | 0:b96b9110daf9 | 226 | * Parameter: * |
fblanc | 0:b96b9110daf9 | 227 | * Return: * |
fblanc | 0:b96b9110daf9 | 228 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 229 | |
fblanc | 0:b96b9110daf9 | 230 | void GLCD_Init (void) { |
fblanc | 0:b96b9110daf9 | 231 | static unsigned short driverCode; |
fblanc | 0:b96b9110daf9 | 232 | |
fblanc | 0:b96b9110daf9 | 233 | /* Enable clock for SSP1, clock = CCLK / 2 */ |
fblanc | 0:b96b9110daf9 | 234 | LPC_SC->PCONP |= 0x00000400; |
fblanc | 0:b96b9110daf9 | 235 | LPC_SC->PCLKSEL0 |= 0x00200000; |
fblanc | 0:b96b9110daf9 | 236 | |
fblanc | 0:b96b9110daf9 | 237 | /* Configure the LCD Control pins */ |
fblanc | 0:b96b9110daf9 | 238 | LPC_PINCON->PINSEL9 &= 0xF0FFFFFF; |
fblanc | 0:b96b9110daf9 | 239 | LPC_GPIO4->FIODIR |= 0x30000000; |
fblanc | 0:b96b9110daf9 | 240 | LPC_GPIO4->FIOSET = 0x20000000; |
fblanc | 0:b96b9110daf9 | 241 | |
fblanc | 0:b96b9110daf9 | 242 | /* SSEL1 is GPIO output set to high */ |
fblanc | 0:b96b9110daf9 | 243 | LPC_GPIO0->FIODIR |= 0x00000040; |
fblanc | 0:b96b9110daf9 | 244 | LPC_GPIO0->FIOSET = 0x00000040; |
fblanc | 0:b96b9110daf9 | 245 | LPC_PINCON->PINSEL0 &= 0xFFF03FFF; |
fblanc | 0:b96b9110daf9 | 246 | LPC_PINCON->PINSEL0 |= 0x000A8000; |
fblanc | 0:b96b9110daf9 | 247 | |
fblanc | 0:b96b9110daf9 | 248 | /* Enable SPI in Master Mode, CPOL=1, CPHA=1 */ |
fblanc | 0:b96b9110daf9 | 249 | /* Max. 12.5 MBit used for Data Transfer @ 100MHz */ |
fblanc | 0:b96b9110daf9 | 250 | LPC_SSP1->CR0 = 0x01C7; |
fblanc | 0:b96b9110daf9 | 251 | LPC_SSP1->CPSR = 0x02; |
fblanc | 0:b96b9110daf9 | 252 | LPC_SSP1->CR1 = 0x02; |
fblanc | 0:b96b9110daf9 | 253 | |
fblanc | 0:b96b9110daf9 | 254 | delay(5); /* Delay 50 ms */ |
fblanc | 0:b96b9110daf9 | 255 | driverCode = rd_reg(0x00); |
fblanc | 0:b96b9110daf9 | 256 | |
fblanc | 0:b96b9110daf9 | 257 | /* Start Initial Sequence --------------------------------------------------*/ |
fblanc | 0:b96b9110daf9 | 258 | wr_reg(0x01, 0x0100); /* Set SS bit */ |
fblanc | 0:b96b9110daf9 | 259 | wr_reg(0x02, 0x0700); /* Set 1 line inversion */ |
fblanc | 0:b96b9110daf9 | 260 | wr_reg(0x04, 0x0000); /* Resize register */ |
fblanc | 0:b96b9110daf9 | 261 | wr_reg(0x08, 0x0207); /* 2 lines front, 7 back porch */ |
fblanc | 0:b96b9110daf9 | 262 | wr_reg(0x09, 0x0000); /* Set non-disp area refresh cyc ISC */ |
fblanc | 0:b96b9110daf9 | 263 | wr_reg(0x0A, 0x0000); /* FMARK function */ |
fblanc | 0:b96b9110daf9 | 264 | wr_reg(0x0C, 0x0000); /* RGB interface setting */ |
fblanc | 0:b96b9110daf9 | 265 | wr_reg(0x0D, 0x0000); /* Frame marker Position */ |
fblanc | 0:b96b9110daf9 | 266 | wr_reg(0x0F, 0x0000); /* RGB interface polarity */ |
fblanc | 0:b96b9110daf9 | 267 | |
fblanc | 0:b96b9110daf9 | 268 | /* Power On sequence -------------------------------------------------------*/ |
fblanc | 0:b96b9110daf9 | 269 | wr_reg(0x10, 0x0000); /* Reset Power Control 1 */ |
fblanc | 0:b96b9110daf9 | 270 | wr_reg(0x11, 0x0000); /* Reset Power Control 2 */ |
fblanc | 0:b96b9110daf9 | 271 | wr_reg(0x12, 0x0000); /* Reset Power Control 3 */ |
fblanc | 0:b96b9110daf9 | 272 | wr_reg(0x13, 0x0000); /* Reset Power Control 4 */ |
fblanc | 0:b96b9110daf9 | 273 | delay(20); /* Discharge cap power voltage (200ms)*/ |
fblanc | 0:b96b9110daf9 | 274 | wr_reg(0x10, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ |
fblanc | 0:b96b9110daf9 | 275 | wr_reg(0x11, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */ |
fblanc | 0:b96b9110daf9 | 276 | delay(5); /* Delay 50 ms */ |
fblanc | 0:b96b9110daf9 | 277 | wr_reg(0x12, 0x01BD); /* VREG1OUT voltage */ |
fblanc | 0:b96b9110daf9 | 278 | delay(5); /* Delay 50 ms */ |
fblanc | 0:b96b9110daf9 | 279 | wr_reg(0x13, 0x1400); /* VDV[4:0] for VCOM amplitude */ |
fblanc | 0:b96b9110daf9 | 280 | wr_reg(0x29, 0x000E); /* VCM[4:0] for VCOMH */ |
fblanc | 0:b96b9110daf9 | 281 | delay(5); /* Delay 50 ms */ |
fblanc | 0:b96b9110daf9 | 282 | wr_reg(0x20, 0x0000); /* GRAM horizontal Address */ |
fblanc | 0:b96b9110daf9 | 283 | wr_reg(0x21, 0x0000); /* GRAM Vertical Address */ |
fblanc | 0:b96b9110daf9 | 284 | |
fblanc | 0:b96b9110daf9 | 285 | /* Adjust the Gamma Curve --------------------------------------------------*/ |
fblanc | 0:b96b9110daf9 | 286 | if (driverCode == 0x5408) { /* LCD with SPFD5408 LCD Controller */ |
fblanc | 0:b96b9110daf9 | 287 | wr_reg(0x30, 0x0B0D); |
fblanc | 0:b96b9110daf9 | 288 | wr_reg(0x31, 0x1923); |
fblanc | 0:b96b9110daf9 | 289 | wr_reg(0x32, 0x1C26); |
fblanc | 0:b96b9110daf9 | 290 | wr_reg(0x33, 0x261C); |
fblanc | 0:b96b9110daf9 | 291 | wr_reg(0x34, 0x2419); |
fblanc | 0:b96b9110daf9 | 292 | wr_reg(0x35, 0x0D0B); |
fblanc | 0:b96b9110daf9 | 293 | wr_reg(0x36, 0x1006); |
fblanc | 0:b96b9110daf9 | 294 | wr_reg(0x37, 0x0610); |
fblanc | 0:b96b9110daf9 | 295 | wr_reg(0x38, 0x0706); |
fblanc | 0:b96b9110daf9 | 296 | wr_reg(0x39, 0x0304); |
fblanc | 0:b96b9110daf9 | 297 | wr_reg(0x3A, 0x0E05); |
fblanc | 0:b96b9110daf9 | 298 | wr_reg(0x3B, 0x0E01); |
fblanc | 0:b96b9110daf9 | 299 | wr_reg(0x3C, 0x010E); |
fblanc | 0:b96b9110daf9 | 300 | wr_reg(0x3D, 0x050E); |
fblanc | 0:b96b9110daf9 | 301 | wr_reg(0x3E, 0x0403); |
fblanc | 0:b96b9110daf9 | 302 | wr_reg(0x3F, 0x0607); |
fblanc | 0:b96b9110daf9 | 303 | } |
fblanc | 0:b96b9110daf9 | 304 | else { /* LCD with other LCD Controller */ |
fblanc | 0:b96b9110daf9 | 305 | wr_reg(0x30, 0x0006); |
fblanc | 0:b96b9110daf9 | 306 | wr_reg(0x31, 0x0101); |
fblanc | 0:b96b9110daf9 | 307 | wr_reg(0x32, 0x0003); |
fblanc | 0:b96b9110daf9 | 308 | wr_reg(0x35, 0x0106); |
fblanc | 0:b96b9110daf9 | 309 | wr_reg(0x36, 0x0B02); |
fblanc | 0:b96b9110daf9 | 310 | wr_reg(0x37, 0x0302); |
fblanc | 0:b96b9110daf9 | 311 | wr_reg(0x38, 0x0707); |
fblanc | 0:b96b9110daf9 | 312 | wr_reg(0x39, 0x0007); |
fblanc | 0:b96b9110daf9 | 313 | wr_reg(0x3C, 0x0600); |
fblanc | 0:b96b9110daf9 | 314 | wr_reg(0x3D, 0x020B); |
fblanc | 0:b96b9110daf9 | 315 | } |
fblanc | 0:b96b9110daf9 | 316 | |
fblanc | 0:b96b9110daf9 | 317 | /* Set GRAM area -----------------------------------------------------------*/ |
fblanc | 0:b96b9110daf9 | 318 | wr_reg(0x50, 0x0000); /* Horizontal GRAM Start Address */ |
fblanc | 0:b96b9110daf9 | 319 | wr_reg(0x51, (HEIGHT-1)); /* Horizontal GRAM End Address */ |
fblanc | 0:b96b9110daf9 | 320 | wr_reg(0x52, 0x0000); /* Vertical GRAM Start Address */ |
fblanc | 0:b96b9110daf9 | 321 | wr_reg(0x53, (WIDTH-1)); /* Vertical GRAM End Address */ |
fblanc | 0:b96b9110daf9 | 322 | if (driverCode == 0x5408) /* LCD with SPFD5408 LCD Controller */ |
fblanc | 0:b96b9110daf9 | 323 | wr_reg(0x60, 0xA700); /* Gate Scan Line */ |
fblanc | 0:b96b9110daf9 | 324 | else /* LCD with other LCD Controller */ |
fblanc | 0:b96b9110daf9 | 325 | wr_reg(0x60, 0x2700); /* Gate Scan Line */ |
fblanc | 0:b96b9110daf9 | 326 | wr_reg(0x61, 0x0001); /* NDL,VLE, REV */ |
fblanc | 0:b96b9110daf9 | 327 | wr_reg(0x6A, 0x0000); /* Set scrolling line */ |
fblanc | 0:b96b9110daf9 | 328 | |
fblanc | 0:b96b9110daf9 | 329 | /* Partial Display Control -------------------------------------------------*/ |
fblanc | 0:b96b9110daf9 | 330 | wr_reg(0x80, 0x0000); |
fblanc | 0:b96b9110daf9 | 331 | wr_reg(0x81, 0x0000); |
fblanc | 0:b96b9110daf9 | 332 | wr_reg(0x82, 0x0000); |
fblanc | 0:b96b9110daf9 | 333 | wr_reg(0x83, 0x0000); |
fblanc | 0:b96b9110daf9 | 334 | wr_reg(0x84, 0x0000); |
fblanc | 0:b96b9110daf9 | 335 | wr_reg(0x85, 0x0000); |
fblanc | 0:b96b9110daf9 | 336 | |
fblanc | 0:b96b9110daf9 | 337 | /* Panel Control -----------------------------------------------------------*/ |
fblanc | 0:b96b9110daf9 | 338 | wr_reg(0x90, 0x0010); |
fblanc | 0:b96b9110daf9 | 339 | wr_reg(0x92, 0x0000); |
fblanc | 0:b96b9110daf9 | 340 | wr_reg(0x93, 0x0003); |
fblanc | 0:b96b9110daf9 | 341 | wr_reg(0x95, 0x0110); |
fblanc | 0:b96b9110daf9 | 342 | wr_reg(0x97, 0x0000); |
fblanc | 0:b96b9110daf9 | 343 | wr_reg(0x98, 0x0000); |
fblanc | 0:b96b9110daf9 | 344 | |
fblanc | 0:b96b9110daf9 | 345 | /* Set GRAM write direction |
fblanc | 0:b96b9110daf9 | 346 | I/D=11 (Horizontal : increment, Vertical : increment) */ |
fblanc | 0:b96b9110daf9 | 347 | |
fblanc | 0:b96b9110daf9 | 348 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 349 | /* AM=1 (address is updated in vertical writing direction) */ |
fblanc | 0:b96b9110daf9 | 350 | wr_reg(0x03, 0x1038); |
fblanc | 0:b96b9110daf9 | 351 | #else |
fblanc | 0:b96b9110daf9 | 352 | /* AM=0 (address is updated in horizontal writing direction) */ |
fblanc | 0:b96b9110daf9 | 353 | wr_reg(0x03, 0x1030); |
fblanc | 0:b96b9110daf9 | 354 | #endif |
fblanc | 0:b96b9110daf9 | 355 | |
fblanc | 0:b96b9110daf9 | 356 | wr_reg(0x07, 0x0137); /* 262K color and display ON */ |
fblanc | 0:b96b9110daf9 | 357 | LPC_GPIO4->FIOSET = 0x10000000; |
fblanc | 0:b96b9110daf9 | 358 | } |
fblanc | 0:b96b9110daf9 | 359 | |
fblanc | 0:b96b9110daf9 | 360 | |
fblanc | 0:b96b9110daf9 | 361 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 362 | * Set draw window region * |
fblanc | 0:b96b9110daf9 | 363 | * Parameter: x: horizontal position * |
fblanc | 0:b96b9110daf9 | 364 | * y: vertical position * |
fblanc | 0:b96b9110daf9 | 365 | * w: window width in pixel * |
fblanc | 0:b96b9110daf9 | 366 | * h: window height in pixels * |
fblanc | 0:b96b9110daf9 | 367 | * Return: * |
fblanc | 0:b96b9110daf9 | 368 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 369 | |
fblanc | 0:b96b9110daf9 | 370 | void GLCD_SetWindow (unsigned int x, unsigned int y, unsigned int w, unsigned int h) { |
fblanc | 0:b96b9110daf9 | 371 | |
fblanc | 0:b96b9110daf9 | 372 | wr_reg(0x50, x); /* Horizontal GRAM Start Address */ |
fblanc | 0:b96b9110daf9 | 373 | wr_reg(0x51, x+w-1); /* Horizontal GRAM End Address (-1) */ |
fblanc | 0:b96b9110daf9 | 374 | wr_reg(0x52, y); /* Vertical GRAM Start Address */ |
fblanc | 0:b96b9110daf9 | 375 | wr_reg(0x53, y+h-1); /* Vertical GRAM End Address (-1) */ |
fblanc | 0:b96b9110daf9 | 376 | |
fblanc | 0:b96b9110daf9 | 377 | wr_reg(0x20, x); |
fblanc | 0:b96b9110daf9 | 378 | wr_reg(0x21, y); |
fblanc | 0:b96b9110daf9 | 379 | } |
fblanc | 0:b96b9110daf9 | 380 | |
fblanc | 0:b96b9110daf9 | 381 | |
fblanc | 0:b96b9110daf9 | 382 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 383 | * Set draw window region to whole screen * |
fblanc | 0:b96b9110daf9 | 384 | * Parameter: * |
fblanc | 0:b96b9110daf9 | 385 | * Return: * |
fblanc | 0:b96b9110daf9 | 386 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 387 | |
fblanc | 0:b96b9110daf9 | 388 | void GLCD_WindowMax (void) { |
fblanc | 0:b96b9110daf9 | 389 | |
fblanc | 0:b96b9110daf9 | 390 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 391 | GLCD_SetWindow (0, 0, HEIGHT, WIDTH); |
fblanc | 0:b96b9110daf9 | 392 | #else |
fblanc | 0:b96b9110daf9 | 393 | GLCD_SetWindow (0, 0, WIDTH, HEIGHT); |
fblanc | 0:b96b9110daf9 | 394 | #endif |
fblanc | 0:b96b9110daf9 | 395 | } |
fblanc | 0:b96b9110daf9 | 396 | |
fblanc | 0:b96b9110daf9 | 397 | |
fblanc | 0:b96b9110daf9 | 398 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 399 | * Draw a pixel in foreground color * |
fblanc | 0:b96b9110daf9 | 400 | * Parameter: x: horizontal position * |
fblanc | 0:b96b9110daf9 | 401 | * y: vertical position * |
fblanc | 0:b96b9110daf9 | 402 | * Return: * |
fblanc | 0:b96b9110daf9 | 403 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 404 | |
fblanc | 0:b96b9110daf9 | 405 | void GLCD_PutPixel (unsigned int x, unsigned int y) { |
fblanc | 0:b96b9110daf9 | 406 | |
fblanc | 0:b96b9110daf9 | 407 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 408 | wr_reg(0x20, y); |
fblanc | 0:b96b9110daf9 | 409 | wr_reg(0x21, WIDTH-1-x); |
fblanc | 0:b96b9110daf9 | 410 | #else |
fblanc | 0:b96b9110daf9 | 411 | wr_reg(0x20, x); |
fblanc | 0:b96b9110daf9 | 412 | wr_reg(0x21, y); |
fblanc | 0:b96b9110daf9 | 413 | #endif |
fblanc | 0:b96b9110daf9 | 414 | wr_cmd(0x22); |
fblanc | 0:b96b9110daf9 | 415 | wr_dat(TextColor); |
fblanc | 0:b96b9110daf9 | 416 | } |
fblanc | 0:b96b9110daf9 | 417 | |
fblanc | 0:b96b9110daf9 | 418 | |
fblanc | 0:b96b9110daf9 | 419 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 420 | * Set foreground color * |
fblanc | 0:b96b9110daf9 | 421 | * Parameter: color: foreground color * |
fblanc | 0:b96b9110daf9 | 422 | * Return: * |
fblanc | 0:b96b9110daf9 | 423 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 424 | |
fblanc | 0:b96b9110daf9 | 425 | void GLCD_SetTextColor (unsigned short color) { |
fblanc | 0:b96b9110daf9 | 426 | |
fblanc | 0:b96b9110daf9 | 427 | TextColor = color; |
fblanc | 0:b96b9110daf9 | 428 | } |
fblanc | 0:b96b9110daf9 | 429 | |
fblanc | 0:b96b9110daf9 | 430 | |
fblanc | 0:b96b9110daf9 | 431 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 432 | * Set background color * |
fblanc | 0:b96b9110daf9 | 433 | * Parameter: color: background color * |
fblanc | 0:b96b9110daf9 | 434 | * Return: * |
fblanc | 0:b96b9110daf9 | 435 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 436 | |
fblanc | 0:b96b9110daf9 | 437 | void GLCD_SetBackColor (unsigned short color) { |
fblanc | 0:b96b9110daf9 | 438 | |
fblanc | 0:b96b9110daf9 | 439 | BackColor = color; |
fblanc | 0:b96b9110daf9 | 440 | } |
fblanc | 0:b96b9110daf9 | 441 | |
fblanc | 0:b96b9110daf9 | 442 | |
fblanc | 0:b96b9110daf9 | 443 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 444 | * Clear display * |
fblanc | 0:b96b9110daf9 | 445 | * Parameter: color: display clearing color * |
fblanc | 0:b96b9110daf9 | 446 | * Return: * |
fblanc | 0:b96b9110daf9 | 447 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 448 | |
fblanc | 0:b96b9110daf9 | 449 | void GLCD_Clear (unsigned short color) { |
fblanc | 0:b96b9110daf9 | 450 | unsigned int i; |
fblanc | 0:b96b9110daf9 | 451 | |
fblanc | 0:b96b9110daf9 | 452 | GLCD_WindowMax(); |
fblanc | 0:b96b9110daf9 | 453 | wr_cmd(0x22); |
fblanc | 0:b96b9110daf9 | 454 | wr_dat_start(); |
fblanc | 0:b96b9110daf9 | 455 | for(i = 0; i < (WIDTH*HEIGHT); i++) |
fblanc | 0:b96b9110daf9 | 456 | wr_dat_only(color); |
fblanc | 0:b96b9110daf9 | 457 | wr_dat_stop(); |
fblanc | 0:b96b9110daf9 | 458 | } |
fblanc | 0:b96b9110daf9 | 459 | |
fblanc | 0:b96b9110daf9 | 460 | |
fblanc | 0:b96b9110daf9 | 461 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 462 | * Draw character on given position * |
fblanc | 0:b96b9110daf9 | 463 | * Parameter: x: horizontal position * |
fblanc | 0:b96b9110daf9 | 464 | * y: vertical position * |
fblanc | 0:b96b9110daf9 | 465 | * cw: character width in pixel * |
fblanc | 0:b96b9110daf9 | 466 | * ch: character height in pixels * |
fblanc | 0:b96b9110daf9 | 467 | * c: pointer to character bitmap * |
fblanc | 0:b96b9110daf9 | 468 | * Return: * |
fblanc | 0:b96b9110daf9 | 469 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 470 | |
fblanc | 0:b96b9110daf9 | 471 | void GLCD_DrawChar_U8 (unsigned int x, unsigned int y, unsigned int cw, unsigned int ch, unsigned char *c) { |
fblanc | 0:b96b9110daf9 | 472 | int idx = 0, i, j; |
fblanc | 0:b96b9110daf9 | 473 | |
fblanc | 0:b96b9110daf9 | 474 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 475 | x = WIDTH-x-cw; |
fblanc | 0:b96b9110daf9 | 476 | GLCD_SetWindow(y, x, ch, cw); |
fblanc | 0:b96b9110daf9 | 477 | #else |
fblanc | 0:b96b9110daf9 | 478 | GLCD_SetWindow(x, y, cw, ch); |
fblanc | 0:b96b9110daf9 | 479 | #endif |
fblanc | 0:b96b9110daf9 | 480 | wr_cmd(0x22); |
fblanc | 0:b96b9110daf9 | 481 | wr_dat_start(); |
fblanc | 0:b96b9110daf9 | 482 | for (j = 0; j < ch; j++) { |
fblanc | 0:b96b9110daf9 | 483 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 484 | for (i = cw-1; i >= 0; i--) { |
fblanc | 0:b96b9110daf9 | 485 | #else |
fblanc | 0:b96b9110daf9 | 486 | for (i = 0; i <= cw-1; i++) { |
fblanc | 0:b96b9110daf9 | 487 | #endif |
fblanc | 0:b96b9110daf9 | 488 | if((c[idx] & (1 << i)) == 0x00) { |
fblanc | 0:b96b9110daf9 | 489 | wr_dat_only(BackColor); |
fblanc | 0:b96b9110daf9 | 490 | } else { |
fblanc | 0:b96b9110daf9 | 491 | wr_dat_only(TextColor); |
fblanc | 0:b96b9110daf9 | 492 | } |
fblanc | 0:b96b9110daf9 | 493 | } |
fblanc | 0:b96b9110daf9 | 494 | c++; |
fblanc | 0:b96b9110daf9 | 495 | } |
fblanc | 0:b96b9110daf9 | 496 | wr_dat_stop(); |
fblanc | 0:b96b9110daf9 | 497 | } |
fblanc | 0:b96b9110daf9 | 498 | |
fblanc | 0:b96b9110daf9 | 499 | |
fblanc | 0:b96b9110daf9 | 500 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 501 | * Draw character on given position * |
fblanc | 0:b96b9110daf9 | 502 | * Parameter: x: horizontal position * |
fblanc | 0:b96b9110daf9 | 503 | * y: vertical position * |
fblanc | 0:b96b9110daf9 | 504 | * cw: character width in pixel * |
fblanc | 0:b96b9110daf9 | 505 | * ch: character height in pixels * |
fblanc | 0:b96b9110daf9 | 506 | * c: pointer to character bitmap * |
fblanc | 0:b96b9110daf9 | 507 | * Return: * |
fblanc | 0:b96b9110daf9 | 508 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 509 | |
fblanc | 0:b96b9110daf9 | 510 | void GLCD_DrawChar_U16 (unsigned int x, unsigned int y, unsigned int cw, unsigned int ch, unsigned short *c) { |
fblanc | 0:b96b9110daf9 | 511 | int idx = 0, i, j; |
fblanc | 0:b96b9110daf9 | 512 | |
fblanc | 0:b96b9110daf9 | 513 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 514 | x = WIDTH-x-cw; |
fblanc | 0:b96b9110daf9 | 515 | GLCD_SetWindow(y, x, ch, cw); |
fblanc | 0:b96b9110daf9 | 516 | #else |
fblanc | 0:b96b9110daf9 | 517 | GLCD_SetWindow(x, y, cw, ch); |
fblanc | 0:b96b9110daf9 | 518 | #endif |
fblanc | 0:b96b9110daf9 | 519 | wr_cmd(0x22); |
fblanc | 0:b96b9110daf9 | 520 | wr_dat_start(); |
fblanc | 0:b96b9110daf9 | 521 | for (j = 0; j < ch; j++) { |
fblanc | 0:b96b9110daf9 | 522 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 523 | for (i = cw-1; i >= 0; i--) { |
fblanc | 0:b96b9110daf9 | 524 | #else |
fblanc | 0:b96b9110daf9 | 525 | for (i = 0; i <= cw-1; i++) { |
fblanc | 0:b96b9110daf9 | 526 | #endif |
fblanc | 0:b96b9110daf9 | 527 | if((c[idx] & (1 << i)) == 0x00) { |
fblanc | 0:b96b9110daf9 | 528 | wr_dat_only(BackColor); |
fblanc | 0:b96b9110daf9 | 529 | } else { |
fblanc | 0:b96b9110daf9 | 530 | wr_dat_only(TextColor); |
fblanc | 0:b96b9110daf9 | 531 | } |
fblanc | 0:b96b9110daf9 | 532 | } |
fblanc | 0:b96b9110daf9 | 533 | c++; |
fblanc | 0:b96b9110daf9 | 534 | } |
fblanc | 0:b96b9110daf9 | 535 | wr_dat_stop(); |
fblanc | 0:b96b9110daf9 | 536 | } |
fblanc | 0:b96b9110daf9 | 537 | |
fblanc | 0:b96b9110daf9 | 538 | |
fblanc | 0:b96b9110daf9 | 539 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 540 | * Disply character on given line * |
fblanc | 0:b96b9110daf9 | 541 | * Parameter: ln: line number * |
fblanc | 0:b96b9110daf9 | 542 | * col: column number * |
fblanc | 0:b96b9110daf9 | 543 | * fi: font index (0 = 6x8, 1 = 16x24) * |
fblanc | 0:b96b9110daf9 | 544 | * c: ascii character * |
fblanc | 0:b96b9110daf9 | 545 | * Return: * |
fblanc | 0:b96b9110daf9 | 546 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 547 | |
fblanc | 0:b96b9110daf9 | 548 | void GLCD_DisplayChar (unsigned int ln, unsigned int col, unsigned char fi, unsigned char c) { |
fblanc | 0:b96b9110daf9 | 549 | |
fblanc | 0:b96b9110daf9 | 550 | c -= 32; |
fblanc | 0:b96b9110daf9 | 551 | switch (fi) { |
fblanc | 0:b96b9110daf9 | 552 | case 0: /* Font 6 x 8 */ |
fblanc | 0:b96b9110daf9 | 553 | GLCD_DrawChar_U8 (col * 6, ln * 8, 6, 8, (unsigned char *)&Font_6x8_h [c * 8]); |
fblanc | 0:b96b9110daf9 | 554 | break; |
fblanc | 0:b96b9110daf9 | 555 | case 1: /* Font 16 x 24 */ |
fblanc | 0:b96b9110daf9 | 556 | GLCD_DrawChar_U16(col * 16, ln * 24, 16, 24, (unsigned short *)&Font_16x24_h[c * 24]); |
fblanc | 0:b96b9110daf9 | 557 | break; |
fblanc | 0:b96b9110daf9 | 558 | } |
fblanc | 0:b96b9110daf9 | 559 | } |
fblanc | 0:b96b9110daf9 | 560 | |
fblanc | 0:b96b9110daf9 | 561 | |
fblanc | 0:b96b9110daf9 | 562 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 563 | * Disply string on given line * |
fblanc | 0:b96b9110daf9 | 564 | * Parameter: ln: line number * |
fblanc | 0:b96b9110daf9 | 565 | * col: column number * |
fblanc | 0:b96b9110daf9 | 566 | * fi: font index (0 = 6x8, 1 = 16x24) * |
fblanc | 0:b96b9110daf9 | 567 | * s: pointer to string * |
fblanc | 0:b96b9110daf9 | 568 | * Return: * |
fblanc | 0:b96b9110daf9 | 569 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 570 | |
fblanc | 0:b96b9110daf9 | 571 | void GLCD_DisplayString (unsigned int ln, unsigned int col, unsigned char fi, unsigned char *s) { |
fblanc | 0:b96b9110daf9 | 572 | |
fblanc | 0:b96b9110daf9 | 573 | GLCD_WindowMax(); |
fblanc | 0:b96b9110daf9 | 574 | while (*s) { |
fblanc | 0:b96b9110daf9 | 575 | GLCD_DisplayChar(ln, col++, fi, *s++); |
fblanc | 0:b96b9110daf9 | 576 | } |
fblanc | 0:b96b9110daf9 | 577 | } |
fblanc | 0:b96b9110daf9 | 578 | |
fblanc | 0:b96b9110daf9 | 579 | |
fblanc | 0:b96b9110daf9 | 580 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 581 | * Clear given line * |
fblanc | 0:b96b9110daf9 | 582 | * Parameter: ln: line number * |
fblanc | 0:b96b9110daf9 | 583 | * fi: font index (0 = 6x8, 1 = 16x24) * |
fblanc | 0:b96b9110daf9 | 584 | * Return: * |
fblanc | 0:b96b9110daf9 | 585 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 586 | |
fblanc | 0:b96b9110daf9 | 587 | void GLCD_ClearLn (unsigned int ln, unsigned char fi) { |
fblanc | 0:b96b9110daf9 | 588 | unsigned char i; |
fblanc | 0:b96b9110daf9 | 589 | unsigned char buf[60]; |
fblanc | 0:b96b9110daf9 | 590 | |
fblanc | 0:b96b9110daf9 | 591 | GLCD_WindowMax(); |
fblanc | 0:b96b9110daf9 | 592 | switch (fi) { |
fblanc | 0:b96b9110daf9 | 593 | case 0: /* Font 6 x 8 */ |
fblanc | 0:b96b9110daf9 | 594 | for (i = 0; i < (WIDTH+5)/6; i++) |
fblanc | 0:b96b9110daf9 | 595 | buf[i] = ' '; |
fblanc | 0:b96b9110daf9 | 596 | buf[i+1] = 0; |
fblanc | 0:b96b9110daf9 | 597 | break; |
fblanc | 0:b96b9110daf9 | 598 | case 1: /* Font 16 x 24 */ |
fblanc | 0:b96b9110daf9 | 599 | for (i = 0; i < (WIDTH+15)/16; i++) |
fblanc | 0:b96b9110daf9 | 600 | buf[i] = ' '; |
fblanc | 0:b96b9110daf9 | 601 | buf[i+1] = 0; |
fblanc | 0:b96b9110daf9 | 602 | break; |
fblanc | 0:b96b9110daf9 | 603 | } |
fblanc | 0:b96b9110daf9 | 604 | GLCD_DisplayString (ln, 0, fi, buf); |
fblanc | 0:b96b9110daf9 | 605 | } |
fblanc | 0:b96b9110daf9 | 606 | |
fblanc | 0:b96b9110daf9 | 607 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 608 | * Draw bargraph * |
fblanc | 0:b96b9110daf9 | 609 | * Parameter: x: horizontal position * |
fblanc | 0:b96b9110daf9 | 610 | * y: vertical position * |
fblanc | 0:b96b9110daf9 | 611 | * w: maximum width of bargraph (in pixels) * |
fblanc | 0:b96b9110daf9 | 612 | * val: value of active bargraph (in 1/1024) * |
fblanc | 0:b96b9110daf9 | 613 | * Return: * |
fblanc | 0:b96b9110daf9 | 614 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 615 | |
fblanc | 0:b96b9110daf9 | 616 | void GLCD_Bargraph (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) { |
fblanc | 0:b96b9110daf9 | 617 | int i,j; |
fblanc | 0:b96b9110daf9 | 618 | |
fblanc | 0:b96b9110daf9 | 619 | val = (val * w) >> 10; /* Scale value */ |
fblanc | 0:b96b9110daf9 | 620 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 621 | x = WIDTH-x-w; |
fblanc | 0:b96b9110daf9 | 622 | GLCD_SetWindow(y, x, h, w); |
fblanc | 0:b96b9110daf9 | 623 | #else |
fblanc | 0:b96b9110daf9 | 624 | GLCD_SetWindow(x, y, w, h); |
fblanc | 0:b96b9110daf9 | 625 | #endif |
fblanc | 0:b96b9110daf9 | 626 | wr_cmd(0x22); |
fblanc | 0:b96b9110daf9 | 627 | wr_dat_start(); |
fblanc | 0:b96b9110daf9 | 628 | for (i = 0; i < h; i++) { |
fblanc | 0:b96b9110daf9 | 629 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 630 | for (j = w-1; j >= 0; j--) { |
fblanc | 0:b96b9110daf9 | 631 | #else |
fblanc | 0:b96b9110daf9 | 632 | for (j = 0; j <= w-1; j++) { |
fblanc | 0:b96b9110daf9 | 633 | #endif |
fblanc | 0:b96b9110daf9 | 634 | if(j >= val) { |
fblanc | 0:b96b9110daf9 | 635 | wr_dat_only(BackColor); |
fblanc | 0:b96b9110daf9 | 636 | } else { |
fblanc | 0:b96b9110daf9 | 637 | wr_dat_only(TextColor); |
fblanc | 0:b96b9110daf9 | 638 | } |
fblanc | 0:b96b9110daf9 | 639 | } |
fblanc | 0:b96b9110daf9 | 640 | } |
fblanc | 0:b96b9110daf9 | 641 | wr_dat_stop(); |
fblanc | 0:b96b9110daf9 | 642 | } |
fblanc | 0:b96b9110daf9 | 643 | |
fblanc | 0:b96b9110daf9 | 644 | |
fblanc | 0:b96b9110daf9 | 645 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 646 | * Display graphical bitmap image at position x horizontally and y vertically * |
fblanc | 0:b96b9110daf9 | 647 | * (This function is optimized for 16 bits per pixel format, it has to be * |
fblanc | 0:b96b9110daf9 | 648 | * adapted for any other bits per pixel format) * |
fblanc | 0:b96b9110daf9 | 649 | * Parameter: x: horizontal position * |
fblanc | 0:b96b9110daf9 | 650 | * y: vertical position * |
fblanc | 0:b96b9110daf9 | 651 | * w: width of bitmap * |
fblanc | 0:b96b9110daf9 | 652 | * h: height of bitmap * |
fblanc | 0:b96b9110daf9 | 653 | * bitmap: address at which the bitmap data resides * |
fblanc | 0:b96b9110daf9 | 654 | * Return: * |
fblanc | 0:b96b9110daf9 | 655 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 656 | |
fblanc | 0:b96b9110daf9 | 657 | void GLCD_Bitmap (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap) { |
fblanc | 0:b96b9110daf9 | 658 | unsigned int i, j; |
fblanc | 0:b96b9110daf9 | 659 | unsigned short *bitmap_ptr = (unsigned short *)bitmap; |
fblanc | 0:b96b9110daf9 | 660 | |
fblanc | 0:b96b9110daf9 | 661 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 662 | x = WIDTH-x-w; |
fblanc | 0:b96b9110daf9 | 663 | GLCD_SetWindow(y, x, h, w); |
fblanc | 0:b96b9110daf9 | 664 | #else |
fblanc | 0:b96b9110daf9 | 665 | GLCD_SetWindow(x, y, w, h); |
fblanc | 0:b96b9110daf9 | 666 | #endif |
fblanc | 0:b96b9110daf9 | 667 | wr_cmd(0x22); |
fblanc | 0:b96b9110daf9 | 668 | wr_dat_start(); |
fblanc | 0:b96b9110daf9 | 669 | for (j = 0; j < h; j++) { |
fblanc | 0:b96b9110daf9 | 670 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 671 | for (i = 0; i < w; i++) { |
fblanc | 0:b96b9110daf9 | 672 | wr_dat_only(*bitmap_ptr++); |
fblanc | 0:b96b9110daf9 | 673 | } |
fblanc | 0:b96b9110daf9 | 674 | #else |
fblanc | 0:b96b9110daf9 | 675 | bitmap_ptr += w-1; |
fblanc | 0:b96b9110daf9 | 676 | for (i = 0; i < w; i++) { |
fblanc | 0:b96b9110daf9 | 677 | wr_dat_only(*bitmap_ptr--); |
fblanc | 0:b96b9110daf9 | 678 | } |
fblanc | 0:b96b9110daf9 | 679 | bitmap_ptr += w+1; |
fblanc | 0:b96b9110daf9 | 680 | #endif |
fblanc | 0:b96b9110daf9 | 681 | } |
fblanc | 0:b96b9110daf9 | 682 | wr_dat_stop(); |
fblanc | 0:b96b9110daf9 | 683 | } |
fblanc | 0:b96b9110daf9 | 684 | |
fblanc | 0:b96b9110daf9 | 685 | |
fblanc | 0:b96b9110daf9 | 686 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 687 | * Display graphical bmp file image at position x horizontally and y vertically * |
fblanc | 0:b96b9110daf9 | 688 | * (This function is optimized for 16 bits per pixel format, it has to be * |
fblanc | 0:b96b9110daf9 | 689 | * adapted for any other bits per pixel format) * |
fblanc | 0:b96b9110daf9 | 690 | * Parameter: x: horizontal position * |
fblanc | 0:b96b9110daf9 | 691 | * y: vertical position * |
fblanc | 0:b96b9110daf9 | 692 | * w: width of bitmap * |
fblanc | 0:b96b9110daf9 | 693 | * h: height of bitmap * |
fblanc | 0:b96b9110daf9 | 694 | * bmp: address at which the bmp data resides * |
fblanc | 0:b96b9110daf9 | 695 | * Return: * |
fblanc | 0:b96b9110daf9 | 696 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 697 | |
fblanc | 0:b96b9110daf9 | 698 | void GLCD_Bmp (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bmp) { |
fblanc | 0:b96b9110daf9 | 699 | unsigned int i, j; |
fblanc | 0:b96b9110daf9 | 700 | unsigned short *bitmap_ptr = (unsigned short *)bmp; |
fblanc | 0:b96b9110daf9 | 701 | |
fblanc | 0:b96b9110daf9 | 702 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 703 | x = WIDTH-x-w; |
fblanc | 0:b96b9110daf9 | 704 | GLCD_SetWindow(y, x, h, w); |
fblanc | 0:b96b9110daf9 | 705 | #else |
fblanc | 0:b96b9110daf9 | 706 | GLCD_SetWindow(x, y, w, h); |
fblanc | 0:b96b9110daf9 | 707 | #endif |
fblanc | 0:b96b9110daf9 | 708 | wr_cmd(0x22); |
fblanc | 0:b96b9110daf9 | 709 | wr_dat_start(); |
fblanc | 0:b96b9110daf9 | 710 | #if (HORIZONTAL == 1) |
fblanc | 0:b96b9110daf9 | 711 | bitmap_ptr += (h*w)-1; |
fblanc | 0:b96b9110daf9 | 712 | for (j = 0; j < h; j++) { |
fblanc | 0:b96b9110daf9 | 713 | for (i = 0; i < w; i++) { |
fblanc | 0:b96b9110daf9 | 714 | wr_dat_only(*bitmap_ptr--); |
fblanc | 0:b96b9110daf9 | 715 | } |
fblanc | 0:b96b9110daf9 | 716 | } |
fblanc | 0:b96b9110daf9 | 717 | #else |
fblanc | 0:b96b9110daf9 | 718 | bitmap_ptr += ((h-1)*w); |
fblanc | 0:b96b9110daf9 | 719 | for (j = 0; j < h; j++) { |
fblanc | 0:b96b9110daf9 | 720 | for (i = 0; i < w; i++) { |
fblanc | 0:b96b9110daf9 | 721 | wr_dat_only(*bitmap_ptr++); |
fblanc | 0:b96b9110daf9 | 722 | } |
fblanc | 0:b96b9110daf9 | 723 | bitmap_ptr -= 2*w; |
fblanc | 0:b96b9110daf9 | 724 | } |
fblanc | 0:b96b9110daf9 | 725 | #endif |
fblanc | 0:b96b9110daf9 | 726 | wr_dat_stop(); |
fblanc | 0:b96b9110daf9 | 727 | } |
fblanc | 0:b96b9110daf9 | 728 | |
fblanc | 0:b96b9110daf9 | 729 | |
fblanc | 0:b96b9110daf9 | 730 | /******************************************************************************* |
fblanc | 0:b96b9110daf9 | 731 | * Scroll content of the whole display for dy pixels vertically * |
fblanc | 0:b96b9110daf9 | 732 | * Parameter: dy: number of pixels for vertical scroll * |
fblanc | 0:b96b9110daf9 | 733 | * Return: * |
fblanc | 0:b96b9110daf9 | 734 | *******************************************************************************/ |
fblanc | 0:b96b9110daf9 | 735 | |
fblanc | 0:b96b9110daf9 | 736 | void GLCD_ScrollVertical (unsigned int dy) { |
fblanc | 0:b96b9110daf9 | 737 | #if (HORIZONTAL == 0) |
fblanc | 0:b96b9110daf9 | 738 | static unsigned int y = 0; |
fblanc | 0:b96b9110daf9 | 739 | |
fblanc | 0:b96b9110daf9 | 740 | y = y + dy; |
fblanc | 0:b96b9110daf9 | 741 | while (y >= HEIGHT) |
fblanc | 0:b96b9110daf9 | 742 | y -= HEIGHT; |
fblanc | 0:b96b9110daf9 | 743 | |
fblanc | 0:b96b9110daf9 | 744 | wr_reg(0x6A, y); |
fblanc | 0:b96b9110daf9 | 745 | wr_reg(0x61, 3); |
fblanc | 0:b96b9110daf9 | 746 | #endif |
fblanc | 0:b96b9110daf9 | 747 | } |
fblanc | 0:b96b9110daf9 | 748 | |
fblanc | 0:b96b9110daf9 | 749 | /******************************************************************************/ |