这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 企业专区 » GD32 » GD32105R_START初体验之LCD液晶屏

共4条 1/1 1 跳转至

GD32105R_START初体验之LCD液晶屏

高工
2015-04-24 21:24:22     打赏

    液晶屏是之前参加活动申请的,正好这次拿来跟大家分享一下,将之前在STM32上的例程扒过来,在GD32 105RStar上很轻松的就实现了,不得不赞一下GD32与STM32强大的兼容性了,楼主这次采用的是ST的3.5版本的库函数,开发环境为IAR6.3,硬件CPU为GD32105RStar,LCD驱动为PCA8538,下面就将其驱动程序分享给大家。

void main(void)
{ 
  SystemInit();        /*初始化系统时钟*/
  delay_init( 72 );
  Pca8538_Init();
  Timerx_Init(0,0);
  SysDOInit( ) ;       /*系统开关量输出初始化函数  */
  Nvic_Init( );	       /*中断向量初始化函数 */
  uint8 GD32[] = 
  {
    0x00,0x00,0x00,0x00,0x00,0x00,
    0x7f,0x49,0x49,0x49,0x41,0x00,//E
    0x00,0x00,0x00,0x00,0x00,0x00,
    0x7f,0x49,0x49,0x49,0x41,0x00,//E
    0x00,0x00,0x00,0x00,0x00,0x00,
    0x7f,0x09,0x09,0x09,0x06,0x00,//P
    0x00,0x00,0x00,0x00,0x00,0x00,
    0x3f,0x40,0x38,0x40,0x3f,0x00,//W
    0x00,0x00,0x00,0x00,0x00,0x00,
    
    0x3e,0x41,0x49,0x49,0x7a,0x00,//G
    0x00,0x00,0x00,0x00,0x00,0x00,
    0x7f,0x41,0x41,0x22,0x1c,0x00,//D
    0x00,0x00,0x00,0x00,0x00,0x00,
    0x21,0x41,0x45,0x4b,0x31,0x00,//3
    0x00,0x00,0x00,0x00,0x00,0x00,
    0x42,0x61,0x51,0x49,0x46,0x00,//2
  };
  for(int8 i=0;i<96;i++)
 {
   Temp_Buf[i]=GD32[95-i];
 }
  while(1)   
  { 
    PCA8538_SET_DATA(Temp_Buf);
  }         
} 

 SPI驱动PCA8538初始化:

void Pca8538_Init(void)
{
  u8 i=0;
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOA, ENABLE);
  /*PA4 SPI1_CS */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;  //SPI CS
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //复用推挽输出
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  GPIO_SetBits(GPIOA,GPIO_Pin_4);
  /* PC0 /RST */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;  //LCD_RST
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //复用推挽输出
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  GPIO_SetBits(GPIOC,GPIO_Pin_0);	
  SPIx_Init();		   //初始化SPI1
  GPIO_ResetBits(GPIOC,GPIO_Pin_0);/*RST=0*/
  Delay_ms(50);
  GPIO_SetBits(GPIOC,GPIO_Pin_0);/*RST=1*/
  GPIO_ResetBits(GPIOA,GPIO_Pin_4); /* CS=0 */
  SPIx_ReadWriteByte(0x20); /* Write to DDRAM  最后一个RAM控制命令 */
  SPIx_ReadWriteByte(0x80); // control byte
  SPIx_ReadWriteByte(0x3a); // Initialize  初始化寄存器到默认值
  Delay_ms(50);
  SPIx_ReadWriteByte(0x80);   
  SPIx_ReadWriteByte(0xd8); // OTP refresh 刷新 一次性可编程 one time programable 对设备进行参数校准
  SPIx_ReadWriteByte(0x80);  
  SPIx_ReadWriteByte(0x18); // Device Select 0 在级联应用中的设备地址,与A0A1有关  在此配置为主设备(A0A1=00)
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0xd4); // CLKOUT disabled 单设备时禁止时钟输出
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0xc9); // Charge pump enabled, Vlcd = 3*Vdd2 使能内部LCD电源管理,设置电源倍增器增益为3
  SPIx_ReadWriteByte(0x80);
  SPIx_ReadWriteByte(0x45); // set VLCD, MSB
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0x73); // set VLCD, LSB. VLCD = 6.4 V  设置VLCD的电压值
  Delay_ms(50);
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0x00); // Temp. comp. and measurement disabled
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0xd0); // Set 1/4 bias  设置偏置电压值
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0xb3); // Driving scheme C, 3-line inversion  使能DC正弦波形矢量输出 
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0x01); /* I2C licheng 不存在 */
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0x39); // Display enable  使能液晶屏显示
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0x80); // Set Data pointer x-MSB = 0
  SPIx_ReadWriteByte(0x80); 
  SPIx_ReadWriteByte(0x90); // Set Data pointer x-LSB = 0
  SPIx_ReadWriteByte(0x80); //连续的控制命令
  SPIx_ReadWriteByte(0xa0); // Set Data pointer y = 0
  SPIx_ReadWriteByte(0x20); // Write to DDRAM  最后一个RAM控制命令
  for(i=0;i<204;i++)
  {
    SPIx_ReadWriteByte(0xFF);		
  }
  GPIO_SetBits(GPIOA,GPIO_Pin_4);/*CS=1*/	
}

 




关键词: GD32105R_STAR     STTM32     PCA8    

专家
2015-04-26 12:14:29     打赏
2楼
帅呆了!

高工
2015-12-16 14:59:44     打赏
3楼
谢谢分享                          

助工
2024-08-29 17:03:26     打赏
4楼

谢谢楼主分享。


共4条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]