void SendLcd(unsigned char type, unsigned char dat) { byte i; LCD_DATA(type); // set up first bit as command or data LCD_CS(0); // Enable device CS LCD_CLK(0); // Pull Clock LOW LCD_CLK(1); // Pul Clock HIGH if(dat == 0x0){ // spi cannot transfer zero?? LCD_DATA(0); for(i=0; i<8; i++){ LCD_CLK(0); // Pull Clock LOW LCD_CLK(1); } } else{ SPCR |=0x50; // Enable Hardware SPI SPSR |= 0x1; SPDR = dat; // send data while(!(SPSR & 0x80)); // wait until send complete } SPCR &=~0x50; // Disable Hardware SPI, this releases the SPI pins // for general IO use. which is used to send the 1'st LCD_CS(1); // disable device CS // bit out }
static __inline void wr_cmd (unsigned char cmd) { LCD_CS(0); spi_tran(SPI_START | SPI_WR | SPI_INDEX); /* Write : RS = 0, RW = 0 */ spi_tran(0); spi_tran(cmd); LCD_CS(1); }
static __inline void wr_dat (unsigned short dat) { LCD_CS(0); spi_tran(SPI_START | SPI_WR | SPI_DATA); /* Write : RS = 1, RW = 0 */ spi_tran((dat >> 8)); /* Write D8..D15 */ spi_tran((dat & 0xFF)); /* Write D0..D7 */ LCD_CS(1); }
static void SetData( unsigned short Data) { LCD_CS( 0); spi_delay( 1); SendStartByte( 0, 1); SendByte( Data); spi_delay( 1); LCD_CS( 1); }
static void SetIndex( unsigned char Index) { LCD_CS( 0); spi_delay( 1 ); SendStartByte( 0, 0); SendByte( Index); spi_delay( 1 ); LCD_CS( 1); }
static void LcdSend(unsigned char Value) { LCD_CS(0); spi_delay(5); WriteByte( Value); spi_delay( 5); LCD_CS( 1); spi_delay(5); }
void LCD_Pixel(unsigned char x, unsigned char y, int color) { LCD_GotoXY(x,y); SendLcd(LCDCommand,RAMWR); LCD_CS(0); // SendLcd(LCDData, (unsigned char)((color>>4)& 0xff) ); // SendLcd(LCDData, (unsigned char)((color&0xf)<<4)|0x00 ); SendLcd_color( (unsigned char)((color>>4)& 0xff) ); SendLcd_color( (unsigned char)((color&0xf)<<4)|0x00 ); LCD_CS(1); SendLcd(LCDCommand, NOP); }
void Init_LCD_Pins(void) { // Configure other pins used by the ILI9341 LCD // P0.2 = CS, P0.3 = Reset, P0.21 = DC PINSEL_CFG_Type LCDPin; LCDPin.Portnum = LCD_CS_PORT; LCDPin.Pinnum = LCD_CS_PIN; LCDPin.Funcnum = PINSEL_FUNC_0; // Use as GPIO LCDPin.OpenDrain = PINSEL_PINMODE_NORMAL; LCDPin.Pinmode = PINSEL_PINMODE_PULLUP; PINSEL_ConfigPin(&LCDPin); LCDPin.Portnum = LCD_RESET_PORT; LCDPin.Pinnum = LCD_RESET_PIN; PINSEL_ConfigPin(&LCDPin); LCDPin.Portnum = LCD_DC_PORT; LCDPin.Pinnum = LCD_DC_PIN; PINSEL_ConfigPin(&LCDPin); // Declare LCD pins as output, disable pin masking GPIO_SetDir(LCD_CS_PORT, (1 << LCD_CS_PIN), GPIO_DIR_OUTPUT); // CS GPIO_SetDir(LCD_RESET_PORT, (1 << LCD_RESET_PIN), GPIO_DIR_OUTPUT); // Reset GPIO_SetDir(LCD_DC_PORT, (1 << LCD_DC_PIN), GPIO_DIR_OUTPUT); // DC // Initialize CS to 1 LCD_CS(1); }
static inline void wr_reg (unsigned char reg, unsigned short val) { LCD_CS(0) wr_cmd(reg); wr_dat(val); LCD_CS(1) }
//画点程序 void lcd12864_putpixel(unsigned char x, unsigned char y, unsigned char pixel_mode) { T_SCREEN_PIXEL tmp; if (pixel_mode == PIXEL_MODE_TRANS) { return; } if (LCD_POS_IS_INVALID(x, y)) { return; } LCD_CS(x); DEV_LCD_GET_DATA(X_PIXLE_TO_COL(x), Y_PIXLE_TO_ROW(y), tmp); if (pixel_mode == PIXEL_MODE_SET) { tmp |= (1<<((y & 0x07))); } else if (pixel_mode == PIXEL_MODE_CLEAR) { tmp &= (~(1<<((y & 0x7)))); } else if (pixel_mode == PIXEL_MODE_TURN) { tmp ^= (1<<((y & 0x7))); } else { return; } DEV_LCD_SET_DATA(X_PIXLE_TO_COL(x), Y_PIXLE_TO_ROW(y), tmp); }
void GLCD_DrawChar (unsigned int x, unsigned int y, unsigned short *c) { int idx = 0, i, j; x = WIDTH-x-CHAR_W; wr_reg(0x50, y); /* Horizontal GRAM Start Address */ wr_reg(0x51, y+CHAR_H-1); /* Horizontal GRAM End Address (-1) */ wr_reg(0x52, x); /* Vertical GRAM Start Address */ wr_reg(0x53, x+CHAR_W-1); /* Vertical GRAM End Address (-1) */ wr_reg(0x20, y); wr_reg(0x21, x); LCD_CS(0) wr_cmd(0x22); wr_dat_start(); for (j = 0; j < CHAR_H; j++) { for (i = CHAR_W-1; i >= 0; i--) { if((c[idx] & (1 << i)) == 0x00) { wr_dat_only(BackColor); } else { wr_dat_only(TextColor); } } c++; } wr_dat_stop(); }
static void LCD_ILI9481_CMD(unsigned char cmd) { LCD_CS(0); LCD_SCL(0); spi_delay(1); LCD_SI(0); LCD_SCL(1); spi_delay(1); SendByte(cmd); spi_delay(1); LCD_CS( 1); }
void GLCD_Bargraph (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) { int i,j; x = WIDTH-x-w; wr_reg(0x50, y); /* Horizontal GRAM Start Address */ wr_reg(0x51, y+CHAR_H-1); /* Horizontal GRAM End Address (-1) */ wr_reg(0x52, x); /* Vertical GRAM Start Address */ wr_reg(0x53, x+w-1); /* Vertical GRAM End Address (-1) */ val = (val * w) >> 10; /* Scale value for 24x12 characters */ wr_reg(0x20, y); wr_reg(0x21, x); LCD_CS(0) wr_cmd(0x22); wr_dat_start(); for (i = 0; i < h; i++) { for (j = w-1; j >= 0; j--) { if(j >= val) { wr_dat_only(BackColor); } else { wr_dat_only(TextColor); } } } wr_dat_stop(); }
static __inline void wr_cmd (unsigned char c) { LCD_CS(0) spi_send(SPI_START | SPI_WR | SPI_INDEX); /* Write : RS = 0, RW = 0 */ spi_send(0); spi_send(c); LCD_CS(1) }
static __inline void wr_dat (unsigned short c) { LCD_CS(0) spi_send(SPI_START | SPI_WR | SPI_DATA); /* Write : RS = 1, RW = 0 */ spi_send((c >> 8)); /* Write D8..D15 */ spi_send((c & 0xFF)); /* Write D0..D7 */ LCD_CS(1) }
static void LCD_ILI9481_INDEX(unsigned char index) { LCD_CS(0); LCD_SCL(0); spi_delay(1); LCD_SI(1); LCD_SCL(1); spi_delay(1); SendByte(index); spi_delay(1); LCD_CS( 1); }
void LCD_Window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) { LCD_Cmd(0x2A); SSP0_16(1); SSP0_Write(x); SSP0_Write(x+w-1); SSP0_WaitBusy(); LCD_CS(1); SSP0_16(0); LCD_Cmd(0x2B); SSP0_16(1); SSP0_Write(y) ; SSP0_Write(y+h-1); SSP0_WaitBusy(); LCD_CS(1); SSP0_16(0); }
void GLCD_PutPixel (unsigned int x, unsigned int y) { wr_reg(0x20, y); wr_reg(0x21, WIDTH-1-x); LCD_CS(0) wr_cmd(0x22); wr_dat(TextColor); LCD_CS(1) }
static unsigned short rd_reg (unsigned short reg) { unsigned short val = 0; LCD_CS(0) wr_cmd(reg); val = rd_dat(); LCD_CS(1) return (val); }
void LCD_Cmd(unsigned char cmd) { LCD_DC(0); // Set to command mode LCD_CS(0); SSP0_Write(cmd); // Wait untill it sends out correctly SSP0_WaitBusy(); LCD_DC(1); }
void LCD_Vline(int x, int y0, int y1, int color) { int h,y; h = y1 - y0 + 1; LCD_Window(x,y0,1,h); LCD_DC(0); LCD_CS(0); SSP0_Write(0x2C); // send pixel SSP0_WaitBusy(); LCD_DC(1); SSP0_16(1); // switch to 16 bit Mode 3 for (y=0; y<h; y++) { SSP0_Write(color); } SSP0_WaitBusy(); SSP0_16(0); LCD_CS(1); LCD_WindowMax(); return; }
void LCD_Hline(int x0, int x1, int y, int color) { int w,j; w = x1 - x0 + 1; LCD_Window(x0,y,w,1); LCD_DC(0); LCD_CS(0); SSP0_Write(0x2C); // send pixel SSP0_WaitBusy(); LCD_DC(1); SSP0_16(1); for (j=0; j<w; j++) { SSP0_Write(color); } SSP0_WaitBusy(); SSP0_16(0); LCD_CS(1); LCD_WindowMax(); return; }
void LCD_Init(void) { LCD_CS(1); LCD_CLK(0); LCD_DATA(0); LCD_RESET(1); delay(50); LCD_RESET(0); delay(50); LCD_RESET(1); delay(50); LCD_CS(1); LCD_CLK(1); LCD_DATA(1); delay(10); SendLcd(LCDCommand,SWRESET); delay(10); SendLcd(LCDCommand,SLEEPOUT); // Sleepout // SendLcd(LCDCommand,INVON); // Invert display mode // SendLcd(LCDCommand,BSTRON); // BoostON SendLcd(LCDCommand,MADCTL); // memory access control SendLcd(LCDData,0xe0); SendLcd(LCDCommand,SETCON); // Set Contrast SendLcd(LCDData,0x40); delay(10); SendLcd(LCDCommand,DISPON); // Display On SendLcd(LCDCommand,COLMOD); // Set Color Mode SendLcd(LCDData,0x03); // 12bit per pixel SendLcd(LCDCommand,NOP); // Set Color Mode }
void GLCD_Clear (unsigned short color) { unsigned long i; GLCD_WindowMax(); wr_reg(0x20, 0); wr_reg(0x21, 0); LCD_CS(0) wr_cmd(0x22); wr_dat_start(); for(i = 0; i < ((unsigned long)WIDTH * (unsigned long)HEIGHT); i++) wr_dat_only(color); wr_dat_stop(); }
// write direct to SSP0 register ! void LCD_Pixel(int x, int y, int color) { LCD_Cmd(0x2A); // Set the Horizontal GRAM Address SSP0_16(1); SSP0_Write(x); SSP0_WaitBusy(); LCD_CS(1); SSP0_16(0); LCD_Cmd(0x2B); // Set the Vertical GRAM Address SSP0_16(1); SSP0_Write(y); SSP0_WaitBusy(); LCD_CS(1); SSP0_16(0); LCD_Cmd(0x2C); // Send pixel SSP0_16(1); SSP0_Write(color); SSP0_WaitBusy(); LCD_CS(1); SSP0_16(0); }
void LCD_FillRect(int x0, int y0, int x1, int y1, int color) { int h = y1 - y0 + 1; int w = x1 - x0 + 1; int pixels = h * w; //unsigned int dma_count; LCD_Window(x0,y0,w,h); LCD_Cmd(0x2C); // send pixel SSP0_16(1); // Use 16 bit transfers // Write to LCD using DMA SSP0_WriteLcdDMA(color, pixels); #if 0 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 LPC_SSP0->DMACR = 0x2; // start DMA do { if (pixel > 4095) { dma_count = 4095; pixel = pixel - 4095; } else { dma_count = pixel; pixel = 0; } LPC_GPDMA->DMACIntTCClear = 0x1; LPC_GPDMA->DMACIntErrClr = 0x1; // Configure DMA to use 16bit transfers // no address increment, interrupt LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) ; LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP0_TX; LPC_GPDMA->DMACSoftSReq = 0x1; // DMA request do { } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running } while (pixel > 0); #endif SSP0_WaitBusy(); // wait for end of transfer SSP0_16(0); LCD_CS(1); LCD_WindowMax(); return; }
void LCD_SetOrientation(unsigned int o) { orientation = o; LCD_Cmd(0x36); // MEMORY_ACCESS_CONTROL switch (orientation) { case 0: SSP0_Write(0x48); break; case 1: SSP0_Write(0x28); break; case 2: SSP0_Write(0x88); break; case 3: SSP0_Write(0xE8); break; } SSP0_WaitBusy(); // wait for end of transfer LCD_CS(1); LCD_WindowMax(); }
void GLCD_Bmp (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bmp) { unsigned int i, j; unsigned short *bitmap_ptr = (unsigned short *)bmp; x = WIDTH-x-w; wr_reg(0x50, y); /* Horizontal GRAM Start Address */ wr_reg(0x51, y+h-1); /* Horizontal GRAM End Address (-1) */ wr_reg(0x52, x); /* Vertical GRAM Start Address */ wr_reg(0x53, x+w-1); /* Vertical GRAM End Address (-1) */ wr_reg(0x20, y); wr_reg(0x21, x); LCD_CS(0) wr_cmd(0x22); wr_dat_start(); bitmap_ptr += ((unsigned long)h*(unsigned long)w)-1; for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { wr_dat_only(*bitmap_ptr--); } } wr_dat_stop(); }
static __inline void wr_dat_start (void) { LCD_CS(0) spi_send(SPI_START | SPI_WR | SPI_DATA); /* Write : RS = 1, RW = 0 */ }
static __inline void wr_dat_start (void) { LCD_CS(0) spi_send(SPI_START | SPI_WR | SPI_DATA); /* Write : RS = 1, RW = 0 */ } /******************************************************************************* * Stop of data writing to LCD controller * * Parameter: * * Return: * *******************************************************************************/ static __inline void wr_dat_stop (void) { LCD_CS(1) } /******************************************************************************* * Data writing to LCD controller * * Parameter: c: data to be written * * Return: * *******************************************************************************/ static __inline void wr_dat_only (unsigned short c) { spi_send((c >> 8)); /* Write D8..D15 */ spi_send((c & 0xFF)); /* Write D0..D7 */ }