void lcd_init() { GPIO_TypeDef *gpiod = GPIOD ; LCD_BL_Config(); LCD_Hardware_Init(); #ifdef REVPLUS initLcdSpi() ; #endif gpiod->BSRRL = PIN_LCD_RST ; // RST high Delay(5); gpiod->BSRRH = PIN_LCD_RST ; // RST low Delay(120); //11ms gpiod->BSRRL = PIN_LCD_RST ; // RST high Delay(2500); AspiCmd(0xE2); // System Reset Delay(2500); LCD_Init(); Delay(120); AspiCmd(0xAF); //dc2=1, IC into exit SLEEP MODE, dc3=1 gray=ON, dc4=1 Green Enhanc mode disabled }
void lcd_set_row(int y) { AspiCmd(0); //Set Column Address LSB CA[3:0] AspiCmd(0x10); //Set Column Address MSB CA[7:4] AspiCmd((y&0x0F)|0x60); //Set Row Address LSB RA [3:0] AspiCmd(((y>>4)&0x0F)|0x70); //Set Row Address MSB RA [7:4] }
void Set_Address(uint8_t x, uint8_t y) { AspiCmd(x&0x0F); //Set Column Address LSB CA[3:0] AspiCmd((x>>4)|0x10); //Set Column Address MSB CA[7:4] AspiCmd((y&0x0F)|0x60); //Set Row Address LSB RA [3:0] AspiCmd(((y>>4)&0x0F)|0x70); //Set Row Address MSB RA [7:4] }
void LCD_Init() { rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN); //MOSI gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO10); //CLK gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO11); //RST gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12); //A0 gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO13); //CS gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO14); NCS_HI(); RST_HI(); lcd_delay(5); RST_LO(); lcd_delay(120); //11ms RST_HI(); lcd_delay(2500); AspiCmd(0xE2); lcd_delay(2500); lcd_screen_init(); lcd_delay(120); lcd_screen_init(); lcd_delay(120); AspiCmd(0xAF); //dc2=1, IC into exit SLEEP MODE, dc3=1 gray=ON, dc4=1 Green Enhanc mode disabled memset(img, 0, sizeof(img)); memset(dirty, 0, sizeof(dirty)); //Clear screen for (int y = 0; y < LCD_HEIGHT; y++) { lcd_set_row(y); AspiCmd(0xAF); CLK_HI(); A0_HI(); NCS_LO(); for (int x = 0; x < 212; x++) { //write_pixel(((x/53) % 2) ^ ((y / 16) %2)); write_pixel(0); } NCS_HI(); A0_HI(); AspiData(0); } }
void lcdRefresh() { for (uint32_t y=0; y<LCD_H; y++) { uint8_t *p = &displayBuf[(y>>3)*LCD_W]; uint8_t mask = (1 << (y%8)); Set_Address(0, y); AspiCmd(0xAF); LCD_CLK_HIGH(); LCD_A0_HIGH(); LCD_NCS_LOW(); for (uint32_t x=0; x<LCD_W; x++) { LCD_WRITE_BIT(p[3*DISPLAY_PLAN_SIZE+x] & mask); LCD_WRITE_BIT(p[2*DISPLAY_PLAN_SIZE+x] & mask); LCD_WRITE_BIT(p[DISPLAY_PLAN_SIZE+x] & mask); LCD_WRITE_BIT(p[x] & mask); } LCD_NCS_HIGH(); LCD_A0_HIGH(); WriteData(0); } }
void lcdInit() { LCD_BL_Config(); LCD_Hardware_Init(); LCD_RST_HIGH(); Delay(5); LCD_RST_LOW(); Delay(120); //11ms LCD_RST_HIGH(); Delay(2500); AspiCmd(0xE2); Delay(2500); LCD_Init(); Delay(120); LCD_Init(); Delay(120); AspiCmd(0xAF); //dc2=1, IC into exit SLEEP MODE, dc3=1 gray=ON, dc4=1 Green Enhanc mode disabled }
/* Screen is 212 x 64 with 4bpp */ void LCD_DrawStop(void) { for (int y = 0; y < LCD_HEIGHT; y++) { if(! (dirty[y / 8] & (1 << (y % 8)))) continue; u8 *p = &img[(y / 8) * LCD_WIDTH]; u8 mask = 1 << (y % 8); lcd_set_row(y); AspiCmd(0xAF); CLK_HI(); A0_HI(); NCS_LO(); for (int x = 0; x < LCD_WIDTH; x++) { write_pixel(p[x] & mask); } NCS_HI(); A0_HI(); AspiData(0); } memset(dirty, 0, sizeof(dirty)); }
void lcd_screen_init() { AspiCmd(0x2b); //Panel loading set ,Internal VLCD. AspiCmd(0x25); //Temperature compensation curve definition: 0x25 = -0.05%/oC AspiCmd(0xEA); //set bias=1/10 :Command table NO.27 AspiCmd(0x81); //Set Vop AspiCmd(0x80); //Set contrast 0--255 AspiCmd(0xA6); //inverse display off AspiCmd(0xD1); //SET RGB:Command table NO.21 .SET RGB or BGR. D1=RGB AspiCmd(0xD5); //set color mode 4K and 12bits :Command table NO.22 AspiCmd(0xA0); //line rates,25.2 Klps AspiCmd(0xC8); //SET N-LINE INVERSION AspiCmd(0x1D); //Disable NIV AspiCmd(0xF1); //Set CEN AspiCmd(0x3F); // 1/64DUTY AspiCmd(0x84); //Disable Partial Display AspiCmd(0xC4); //MY=1,MX=0 AspiCmd(0x89); //WA=1,column (CA) increment (+1) first until CA reaches CA boundary, then RA will increment by (+1). AspiCmd(0xF8); //Set Window Program Enable ,inside modle AspiCmd(0xF4); //starting column address of RAM program window. AspiCmd(0x00); AspiCmd(0xF5); //starting row address of RAM program window. AspiCmd(0x60); AspiCmd(0xF6); //ending column address of RAM program window. AspiCmd(0x47); AspiCmd(0xF7); //ending row address of RAM program window. AspiCmd(0x9F); }
void LCD_Contrast(u8 contrast) { AspiCmd(0x81); //Set Vop contrast *= 25 + 5; AspiCmd(contrast); }
void lcdSetRefVolt(uint8_t val) { AspiCmd(0x81); //Set Vop AspiCmd(val+CONTRAST_OFS); //0--255 }
static void LCD_Init() { LCD_BL_Config() ; /*Hardware Reset need delay*/ /*LCD_RST_LOW(); Delay(50); LCD_RST_HIGH();*/ AspiCmd(0x25); //Temperature compensation curve definition: 0x25 = -0.05%/oC AspiCmd(0x2b); //Panel loading set ,Internal VLCD. AspiCmd(0xEA); //set bias=1/10 :Command table NO.27 AspiCmd(0x81); //Set Vop AspiCmd(25+CONTRAST_OFS); //0--255 AspiCmd(0xA6); //inverse display off AspiCmd(0xD1); //SET RGB:Command table NO.21 .SET RGB or BGR. D1=RGB AspiCmd(0xD5); //set color mode 4K and 12bits :Command table NO.22 AspiCmd(0xA0); //line rates,25.2 Klps AspiCmd(0xC8); //SET N-LINE INVERSION AspiCmd(0x1D); //Disable NIV AspiCmd(0xF1); //Set CEN AspiCmd(0x3F); // 1/64DUTY AspiCmd(0x84); //Disable Partial Display AspiCmd(0xC4); //MY=1,MX=0 AspiCmd(0x89); //WA=1,column (CA) increment (+1) first until CA reaches CA boundary, then RA will increment by (+1). AspiCmd(0xF8); //Set Window Program Enable ,inside modle AspiCmd(0xF4); //starting column address of RAM program window. AspiCmd(0x00); AspiCmd(0xF5); //starting row address of RAM program window. AspiCmd(0x60); AspiCmd(0xF6); //ending column address of RAM program window. AspiCmd(0x47); AspiCmd(0xF7); //ending row address of RAM program window. AspiCmd(0x9F); AspiCmd(0xAF); //dc2=1,IC into exit SLEEP MODE, dc3=1 gray=ON 开灰阶 ,dc4=1 Green Enhanc mode disabled 绿色增强模式关 }
static void LCD_Init() { // LCD_BL_Config() ; /*Hardware Reset need delay*/ /*LCD_RST_LOW(); Delay(50); LCD_RST_HIGH();*/ // From LCD Manufacturer // WriteCommand(0x2F); //Internal pump control // Delay(20); // WriteCommand(0x24); //Temperature compensation // WriteCommand(0xE9); //set bias=1/10 // WriteCommand(0x81); //Set Vop // WriteCommand(0xBF); //13.9v//(g_eeGeneral.contrast+CONTRAST_OFS); //0--255 // WriteCommand(0xA2); //set line rate:28KLPS // WriteCommand(0x28); //set pannel loading // WriteCommand(0x40); //scroll line LSB // WriteCommand(0x50); //SCROLL LINE MSB // WriteCommand(0x89); //ram address control // WriteCommand(0xc0); //LCD mapping control // WriteCommand(0x04); //MX=0,MY=1 // WriteCommand(0xd0); //DISPLAY PATTERN = 16-SCALE GRAY // WriteCommand(0xF1); //SET COM end // WriteCommand(0x3F); //64 // WriteCommand(0xF8); //Set Window Program dIsable. // WriteCommand(0xF5); //starting row address of RAM program window.PAGE1 // WriteCommand(0x00); // WriteCommand(0xF7); //end row address of RAM program window.PAGE32 // WriteCommand(0x1f); // WriteCommand(0xF4); //start column address of RAM program window. // WriteCommand(0x00); // WriteCommand(0xF6); //end column address of RAM program window.SEG212 // WriteCommand(0xd3); AspiCmd(0x24); //(5) Temperature compensation curve definition: 0x25 = -0.05%/oC AspiCmd(0x2b); //(6) Panel loading set ,Internal VLCD. AspiCmd(0xEA); //(27) set bias=1/10 AspiCmd(0x81); //(11) Set Vop + next byte AspiCmd(25+CONTRAST_OFS); //0--255 AspiCmd(0xA6); //inverse display off AspiCmd(0xA2); //line rates,28 Klps AspiCmd(0x84); //Disable Partial Display AspiCmd(0xC8); //SET N-LINE INVERSION AspiCmd(0x00); //Disable NIV AspiCmd(0xF1); //Set CEN AspiCmd(0x3F); // 1/64DUTY AspiCmd(0xC0); //(21) Set mapping AspiCmd(0x04); // MY=1, MX=0, MSF=0 AspiCmd(0x89); //(15) WA=1,column (CA) increment (+1) first until CA reaches CA boundary, then RA will increment by (+1). AspiCmd(0xF8); //Set Window Program Enable ,inside modle AspiCmd(0xD0); //(23) SET 4 bits/pixel, pattern 0 AspiCmd(0xF4); //starting column address of RAM program window. AspiCmd(0x00); AspiCmd(0xF5); //starting row address of RAM program window. AspiCmd(0x00); AspiCmd(0xF6); //ending column address of RAM program window. AspiCmd(0xD3); AspiCmd(0xF7); //ending row address of RAM program window. AspiCmd(0x3F); AspiCmd(0xAF); // Active and 16-grey scale // AspiCmd(0x28); //set panel loading // AspiCmd(0x40); //scroll line LSB // AspiCmd(0x50); //SCROLL LINE MSB }
void refreshDisplay() { for (uint32_t y=0; y<DISPLAY_H; y++) { uint8_t *p = &DisplayBuf[(y>>3)*DISPLAY_W]; uint8_t mask = (1 << (y%8)); GPIO_TypeDef *gpiod = GPIOD ; uint32_t *bsrr = (uint32_t *)&gpiod->BSRRL ; Set_Address(0, y); AspiCmd(0xAF); gpiod->BSRRL = PIN_LCD_CLK ; // Clock high gpiod->BSRRL = PIN_LCD_A0 ; // A0 high gpiod->BSRRH = PIN_LCD_NCS ; // CS low for (uint32_t x=0; x<DISPLAY_W; x+=2) { uint32_t data ; data = 0 ; if ( p[x] & mask ) { data = 0xF0 ; } if (p[x+1] & mask ) { data += 0x0F ; } if(data&0x80) { gpiod->BSRRL = PIN_LCD_MOSI ; } else { gpiod->BSRRH = PIN_LCD_MOSI ; } gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x40) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x20) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x10) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x08) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x04) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x02) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low if(data&0x01) { gpiod->BSRRL = PIN_LCD_MOSI | PIN_LCD_CLK ; } else { *bsrr = (PIN_LCD_MOSI<<16) | PIN_LCD_CLK ; } __no_operation() ; gpiod->BSRRH = PIN_LCD_CLK ; // Clock low __no_operation() ; gpiod->BSRRL = PIN_LCD_CLK ; // Clock high } gpiod->BSRRL = PIN_LCD_NCS ; // CS high gpiod->BSRRL = PIN_LCD_A0 ; AspiData(0); } }
void LCD_OFF() { AspiCmd(0xE2); Delay(20); }