LCD128664 SPI驱动

2023-12-17 22:25:17

LCD128664 ?SPI驱动??????

??OLED12864自带字库,直接写入字符串就行,显示图片需要一个个像素写入。这个屏幕地址设置的有点恶心,它有说明书里写者有两行地址,但显示的却是错开的,并不连续。且显示文字和图片的地址并不相同。

? ? ? ? 最令人疑惑的是那个反白的功能,迷惑至极,感觉堪称鸡肋,不能指定某一行反白,直接反白两行。虽然知道因为地址的原因,但你既然做不出那种效果为何要加个反白。同样的地址卷动也很搞笑,想要实现一行行卷动需要自己写算法。而且地址卷动是因为这屏幕有页地址可以显示文字,而且第一页相当于有两个图层,一个用来显示图片,一个用来显示图片,第二页貌似不能显示图片,只能显示文字。当然也可能我还没玩明白,反正我感觉是这样的,反正迷惑至极。

unsigned char LCD_addr[]={                   //坐标编码
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
};

//初始化
void LCD_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStruct ={0};
	
	__HAL_RCC_GPIOA_CLK_ENABLE();

	__HAL_RCC_GPIOC_CLK_ENABLE();
	__HAL_RCC_GPIOF_CLK_ENABLE();
	
	
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	
	GPIO_InitStruct.Pin = PIN_CS_RS | PIN_RES_V0;
	HAL_GPIO_Init(GPIOF,&GPIO_InitStruct);
	GPIO_InitStruct.Pin = PIN_SID_RW | PIN_CLK_E;
	HAL_GPIO_Init(GPIOA,&GPIO_InitStruct);
	
	HIGH_RES_V0;

}

//SPI串行驱动
void LCD_write_byte(u8 dat)
{
	u8 i = 0;
	HIGH_CS_RS;
	for(i = 0;i<8;i++)
	{
		((dat<<i) & 0x80)?(HIGH_SID_RW):(LOW_SID_RW);
		LOW_CLK_E;
		HIGH_CLK_E;
	}
	LOW_CS_RS;
}


//写入数据或命令
void LCD_write_cmd_dat(uint8_t cmd,uint8_t data)
{
	
	LCD_write_byte(cmd);
	LCD_write_byte(data&0xf0);
	LCD_write_byte(data<<4);

}

//清屏 接入空格
void LCD_Clear(void)
{
	LCD_write_cmd_dat(LCD_CMD,0x01);
	delay_ms(2);
}

//屏幕初始化

void InitLCD(void)
{

	LCD_write_cmd_dat(LCD_CMD,0xE2);
	delay_ms(5);
	LCD_write_cmd_dat(LCD_CMD,0x2c);		/*升压步聚1*/
	delay_ms(5);
	LCD_write_cmd_dat(LCD_CMD,0x2e);		/*升压步聚2*/
	delay_ms(5);
	LCD_write_cmd_dat(LCD_CMD,0x2f);		/*升压步聚3*/
	delay_ms(5);
	LCD_write_cmd_dat(LCD_CMD,0x25);		/*粗调对比度,可设置范围20~27*/
	LCD_write_cmd_dat(LCD_CMD,0x81);		/*微调对比度*/
	LCD_write_cmd_dat(LCD_CMD,0x1a);		/*微调对比度的值,可设置范围0~63  1f*/
	LCD_write_cmd_dat(LCD_CMD,0xa2);		/*1/9偏压比(bias)*/
	LCD_write_cmd_dat(LCD_CMD,0xc8);		/*行扫描顺序:从上到下*/
	LCD_write_cmd_dat(LCD_CMD,0xa0);		/*列扫描顺序:从左到右*/
	LCD_write_cmd_dat(LCD_CMD,0x40);		/*起始行:从第一行开始*/
	LCD_Clear();
	LCD_write_cmd_dat(LCD_CMD,0xaf);		/*开显示*/
}


/*屏幕开显示*/

void LCD_turn_on(void)
{
	LCD_write_cmd_dat(LCD_CMD,0x0C);	
}

//进入睡眠模式
void LCD_turn_off(void)
{
	LCD_write_cmd_dat(LCD_CMD,0x08);		
}


//移动光标
void Lcd_xy_12864(unsigned char x,unsigned char y)
{
  switch(x)
  {
    case 0:
      x=0x80;break;
    case 1:
      x=0x90;break;
    case 2:
      x=0x88;break;
    case 3:
      x=0x98;break;
    default:
      x=0x80;
  }
  y=y&0x07;
  LCD_write_cmd_dat(LCD_CMD,0x30);
  LCD_write_cmd_dat(LCD_CMD,y+x);
  LCD_write_cmd_dat(LCD_CMD,y+x);
}


//写入字符串
void LCD_to_TXT(uint8_t x,uint8_t y,uint8_t *str) 
{


  LCD_write_cmd_dat(LCD_CMD,0x30);
  LCD_write_cmd_dat(LCD_CMD,LCD_addr[8*x+y]);
  while(*str != '\0')
  {

		
    if(y == 8)
    {
      y = 0;
      x++;
    }
    if(x==4)
			x=0;
    LCD_write_cmd_dat(LCD_CMD,LCD_addr[8*x+y]);
    LCD_write_cmd_dat(LCD_DAT,*str);
    str++;
    if(*str != '\0')
    {
      LCD_write_cmd_dat(LCD_DAT,*str);
      str++;
      y++;
    }  
  }
}
//显示图片
void LCD_Display_Picture(uint8_t *img)
{
	uint8_t x,y,i;
	LCD_write_cmd_dat(LCD_CMD,0x34);		//切换到扩充指令
	LCD_write_cmd_dat(LCD_CMD,0x34);		//关闭图形显示
	for(i = 0; i < 2; i++)   //上下屏写入
	{
		for(y=0;y<32;y++)   //垂直Y写32次
		{  
			for(x=0;x<8;x++)   //横向X写8次
			{
				LCD_write_cmd_dat(LCD_CMD,0x80 + y);		//行地址
				LCD_write_cmd_dat(LCD_CMD,0x80 + x+i);		//列地址
				LCD_write_cmd_dat(LCD_DAT,*img ++);		//写高位字节数据 D15-D8   
				LCD_write_cmd_dat(LCD_DAT,*img ++);		//写低位字节数据 D7-D0
			}
		}
	}
	LCD_write_cmd_dat(LCD_CMD,0x36);//打开图形显示		
	LCD_write_cmd_dat(LCD_CMD,0x30);        //切换回基本指令
}	

//清除文本
void LcmClearTXT( void )
{
  unsigned char i;
  LCD_write_cmd_dat(LCD_CMD,0x30);
  LCD_write_cmd_dat(LCD_CMD,0x80);
  for(i=0;i<64;i++)
  LCD_write_cmd_dat(LCD_DAT,0x20);
  Location_xy_12864(0,0);      
}

文章来源:https://blog.csdn.net/weixin_55944697/article/details/135050911
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。