STM32驱动ST7701S芯片(vⅰV0手机换屏价)

2022-07-28 10:24:29 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

1、配置GPIO口

void LCD_GPIO_Config(void) { /*定义一个GPIO_InitTypeDef类型的结构体*/ GPIO_InitTypeDef GPIO_InitStructure; /* ????IO??*/ RCC_APB2PeriphClockCmd ( RCC_APB2Periph_AFIO, ENABLE ); /*开启GPIOD的外设时钟*/ RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOE, ENABLE); /* 配置FSMC相对应的数据线,FSMC-D0~D15: PD 14 15 0 1,PE 7 8 9 10 11 12 13 14 15,PD 8 9 10 */ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_Init(GPIOD, &GPIO_InitStructure ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_Init(GPIOE, &GPIO_InitStructure ); /* ??FSMC??????? * PD4-FSMC_NOE :LCD-RD * PD5-FSMC_NWE :LCD-WR * PD7-FSMC_NE1 :LCD-CS * PD11-FSMC_A16 :LCD-DC */ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_Init (GPIOD, & GPIO_InitStructure ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_Init (GPIOD, & GPIO_InitStructure ); // ST7789_CS_APBxClock_FUN ( ST7789_CS_CLK, ENABLE ); GPIO_InitStructure.GPIO_Pin = ST7789_CS_PIN; GPIO_Init ( ST7789_CS_PORT, & GPIO_InitStructure ); // ST7789_DC_APBxClock_FUN ( ST7789_DC_CLK, ENABLE ); GPIO_InitStructure.GPIO_Pin = ST7789_DC_PIN; GPIO_Init ( ST7789_DC_PORT, & GPIO_InitStructure );

/* ??LCD??RST????*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // ST7789_RST_APBxClock_FUN ( ST7789_RST_CLK, ENABLE ); GPIO_InitStructure.GPIO_Pin = ST7789_RST_PIN; GPIO_Init ( ST7789_RST_PORT, & GPIO_InitStructure ); /* ??LCD??????BK*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // ST7789_BK_APBxClock_FUN ( ST7789_BK_CLK, ENABLE ); GPIO_InitStructure.GPIO_Pin = ST7789_BK_PIN; GPIO_Init ( ST7789_BK_PORT, & GPIO_InitStructure ); //IO???????? GPIO_SetBits ( ST7789_RST_PORT, ST7789_RST_PIN ); GPIO_SetBits ( ST7789_CS_PORT, ST7789_CS_PIN ); GPIO_SetBits ( ST7789_DC_PORT, ST7789_DC_PIN ); GPIO_SetBits ( ST7789_BK_PORT, ST7789_BK_PIN ); }

/*函数名:LCD_CmdWrite *功 能:向LCD控制器写命令号 *返回值:无 *参 数:u8 cmd命令号 */ void LCD_CmdWrite(u8 cmd) { // u16 num=0; LCD_RSL; LCD_CSL; LCD_RDH; // num=cmd; // num |=((GPIOD->ODR)&0xFF00); // GPIOD->ODR =num; LCD_D0_WRITE(cmd); LCD_D1_WRITE(cmd); LCD_D2_WRITE(cmd); LCD_D3_WRITE(cmd); LCD_D4_WRITE(cmd); LCD_D5_WRITE(cmd); LCD_D6_WRITE(cmd); LCD_D7_WRITE(cmd); LCD_WRL; LCD_WRH; LCD_CSH; LCD_RSH;

}

/*函数名:LCD_DataWrite *功 能:向LCD控制器写命令参数 *返回值:无 *参 数:u8 data 要写入的数据 */ void LCD_DataWrite(u8 data) { // u16 num=0; LCD_RSH; LCD_CSL; LCD_RDH; // num=data; // num |=((GPIOD->ODR)&0xFF00); // (GPIOD->ODR) =num; LCD_D0_WRITE(data); LCD_D1_WRITE(data); LCD_D2_WRITE(data); LCD_D3_WRITE(data); LCD_D4_WRITE(data); LCD_D5_WRITE(data); LCD_D6_WRITE(data); LCD_D7_WRITE(data); LCD_WRL; LCD_WRH; LCD_CSH; }

/*函数名:LCD_Reset *功 能:复位TFT屏 *参 数:无 *返回值:无 */ static void LCD_Reset(void) { //************* Reset LCD Driver ****************// LCD_RSTH; Delayms(1); // Delayms 1ms LCD_RSTL; Delayms(10); // Delayms 10ms // This delay time is necessary LCD_RSTH; Delayms(120); // Delayms 120 ms }

2、屏初始化

/*函数名:LCDInit *功 能:初始化TFT屏 *参 数:无 *返回值:无 */

void LCD_Init(void) { //************* Reset LCD Driver ****************// LCD_GPIO_Config(); LCD_Reset(); // initializing funciton 1 //—————————————————————————————————// LCD_CmdWrite(0x11); Delay(120); //Delay 120ms

//——————————display and color format setting——————————–// LCD_CmdWrite(0x36); LCD_DataWrite(0x60);//0x60

LCD_CmdWrite(0x3A); LCD_DataWrite(0x05);

//——————————–ST7789V Frame rate setting———————————-// LCD_CmdWrite(0xB2); LCD_DataWrite(0x0C); LCD_DataWrite(0x0C); LCD_DataWrite(0x00); LCD_DataWrite(0x33); LCD_DataWrite(0x33);

LCD_CmdWrite(0xB7); LCD_DataWrite(0x35);

//———————————ST7789V Power setting————————————–// LCD_CmdWrite(0xBB); LCD_DataWrite(0x19);//0x1c

LCD_CmdWrite(0xC0); LCD_DataWrite(0x2C);

LCD_CmdWrite(0xC2); LCD_DataWrite(0x01);

LCD_CmdWrite(0xC3); LCD_DataWrite(0x12);//0x0b

LCD_CmdWrite(0xC4); LCD_DataWrite(0x20);

LCD_CmdWrite(0xC6); LCD_DataWrite(0x0F);

LCD_CmdWrite(0xD0); LCD_DataWrite(0xA4); LCD_DataWrite(0xA1);

//——————————–ST7789V gamma setting—————————————// LCD_CmdWrite(0xE0); LCD_DataWrite(0xd0); LCD_DataWrite(0x00);//0x00 LCD_DataWrite(0x03);//0x03 LCD_DataWrite(0x09);//0x09 LCD_DataWrite(0x13); LCD_DataWrite(0x1c);//0x1c LCD_DataWrite(0x3a);//0x3a LCD_DataWrite(0x55);//0x55 LCD_DataWrite(0x48);//0x48 LCD_DataWrite(0x18); LCD_DataWrite(0x12);//0x12 LCD_DataWrite(0x0e);//0x0e LCD_DataWrite(0x19);//0x19 LCD_DataWrite(0x1e);//0x1e

LCD_CmdWrite(0xE1); LCD_DataWrite(0xd0); LCD_DataWrite(0x00);//0x00 LCD_DataWrite(0x03);//0x03 LCD_DataWrite(0x09);//0x09 LCD_DataWrite(0x05);//0x05 LCD_DataWrite(0x25);//0x25 LCD_DataWrite(0x3a);//0x3a LCD_DataWrite(0x55);//0x55 LCD_DataWrite(0x50);//0x50 LCD_DataWrite(0x3d);//0x3d LCD_DataWrite(0x1c);//0x1c LCD_DataWrite(0x1d);//0x1d LCD_DataWrite(0x1d);//0x1d LCD_DataWrite(0x23);//0x23 LCD_CmdWrite(0x29); //display on LCD_CmdWrite(0x2C); // Memory Write LCD_Clear(BLACK);

}

3、写屏操作

void LCD_Clear(u16 Color) { u32 i; Lcd_SetBox(0,0,320,240); for(i=0;i<78900;i ){ //78900 LCD_WriteOneDot(Color); } }

void LCD_WriteOneDot(u16 color) { LCD_DataWrite(color>>8); LCD_DataWrite(color); }

写ASCII 16×16字符操作,这是写

static void LCD_write_acsii16x16(u8 data,u16 color,u16 xcolor ,u8 mode)//写字符 { u8 i=0,j=0,n=0; u8 avl=0; data -=0x20; for (i=0;i<16;i ) {

avl=asc2_1608[data][i]; for (j=0;j<8;j ) { n ; if(avl&0x80)LCD_WriteOneDot(color); else if(mode==0) LCD_WriteOneDot(xcolor); avl<<=1; if(n>15) { n=0; break; }//部分字体如英文16*16,形成的字库3个8位一组,每一组最后4位不显示,用该语句进行判断有几位不需要显示 } } }

这是写英文字符的函数,但是写汉字则要将字体大小增加一倍,即32点阵大小。

void LCD_write_english_string(u16 x, u16 y, char *str,u8 mode)//英文字符串显示 { u16 k = 0; while ((*str<=’~’)&&(*str>=’ ‘)) { Lcd_SetBox(x-k,y,16,16); LCD_write_acsii16x16( *str,WORDCOLOR,BACKCOLOR, mode); k =16; str ; } }

4、写英文字符当超过16点阵大小后,还按这种写入方法就会有问题,显示的字符是错误的。

比如写入40*32的大小的点阵字符,先用字模工具PCtoLCD2002.exe生成字模,逐列显示(逐行的话有会有问题)

将 Lcd_SetBox(x-k,y,16,16);函数去掉,循环的长度有16改为80,或其它生成的字模的长度。

使用更改后的方法写入字符,显示就OK了

5、清除或写入一个区域的块

void Lcd_ColorBox(u16 xStart,u16 yStart,u16 xlong,u16 ylong,u16 Color) { u32 i,j; j=xlong*ylong; Lcd_SetBox(xStart,yStart,xlong,ylong); for(i=0;i<j;i ){ LCD_WriteOneDot(Color); } }

xlong,ylong为要显示或清除块的大小

这是在取字模显示的时候,遇到的一点问题,有其它方法的可以贴出来一起探讨一下

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/128276.html原文链接:https://javaforall.cn

0 人点赞