[开发板] 【CW32L031CxTx StartKit评估板测评】+LCD 5110屏显示驱动

[复制链接]
 楼主| jinglixixi 发表于 2023-10-25 15:36 | 显示全部楼层 |阅读模式
CD, LCD, cw
CW32L031是一款面向低功耗的产品,为它配置一个以前用于诺基亚手机的LCD5110显示屏是较为适宜的。
该显示屏以SPI接口的方式工作,它与开发板的连接关系为:
SCL---PB6
SDA---PB7
RST---PA10
DC ---PA11
CS ---PA15
BL ---PA12
对相关引脚的工作模式配置函数为:
  1. void LCD5510_CONFIG(void)
  2. {
  3.     GPIO_InitTypeDef GPIO_InitStruct = {0};  
  4.         __RCC_GPIOC_CLK_ENABLE();
  5.     GPIO_InitStruct.IT = GPIO_IT_NONE;
  6.     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  7.     GPIO_InitStruct.Pins = GPIO_PIN_6 | GPIO_PIN_7;
  8.     GPIO_Init(CW_GPIOB, &GPIO_InitStruct);
  9.         GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  10.         GPIO_InitStruct.Pins = GPIO_PIN_10 | GPIO_PIN_11| GPIO_PIN_12| GPIO_PIN_15;
  11.     GPIO_Init(CW_GPIOA, &GPIO_InitStruct);
  12. }
为输出高低电平,所作的语句定义为:
#define SCLK_SetHigh()   GPIO_WritePin(CW_GPIOB, GPIO_PIN_6,GPIO_Pin_SET)    //CLK
#define SCLK_SetLow()    GPIO_WritePin(CW_GPIOB, GPIO_PIN_6,GPIO_Pin_RESET)
#define SDIN_SetHigh()   GPIO_WritePin(CW_GPIOB, GPIO_PIN_7,GPIO_Pin_SET)    //DIN
#define SDIN_SetLow()    GPIO_WritePin(CW_GPIOB, GPIO_PIN_7,GPIO_Pin_RESET)
#define RST_SetHigh()    GPIO_WritePin(CW_GPIOA, GPIO_PIN_10,GPIO_Pin_SET)   //RES
#define RST_SetLow()     GPIO_WritePin(CW_GPIOA, GPIO_PIN_10,GPIO_Pin_RESET)
#define DC_SetHigh()     GPIO_WritePin(CW_GPIOA, GPIO_PIN_11,GPIO_Pin_SET)   //DC
#define DC_SetLow()      GPIO_WritePin(CW_GPIOA, GPIO_PIN_11, GPIO_Pin_RESET)         
#define CS_SetHigh()     GPIO_WritePin(CW_GPIOA, GPIO_PIN_15,GPIO_Pin_SET)   //CS
#define CS_SetLow()      GPIO_WritePin(CW_GPIOA, GPIO_PIN_15,GPIO_Pin_RESET)
#define LED_SetHigh()    GPIO_WritePin(CW_GPIOA, GPIO_PIN_12,GPIO_Pin_SET)   //BLK
实现串行发送字节数据的函数为:
  1. void LCD_write_byte(unsigned char wbyte, unsigned char dat_cmd)
  2. {
  3.   unsigned char i;
  4.   if(dat_cmd)
  5.   {
  6.     DC_SetHigh();
  7.   }
  8.   else
  9.   {
  10.     DC_SetLow();
  11.   }
  12.   for(i = 8; i; i--)
  13.   {
  14.     if(wbyte & 0x80)
  15.     {
  16.        SDIN_SetHigh();
  17.     }
  18.     else
  19.     {
  20.        SDIN_SetLow();
  21.     }
  22.     SCLK_SetLow();
  23.     wbyte <<= 1;
  24.     delay_1us(1);
  25.     SCLK_SetHigh();
  26.   }
  27. }
对LCD5110显示屏初始化的函数为:
  1. void LCD5110_Init(void)
  2. {
  3.   delay_1ms(800);
  4.   RST_SetLow();
  5.   delay_1us(2);
  6.   RST_SetHigh();
  7.   LCD_write_cmd(0x21);
  8.   LCD_write_cmd(0x06);
  9.   LCD_write_cmd(0x13);
  10.   LCD_write_cmd(0xc8);
  11.   LCD_write_cmd(0x20);
  12.   LCD_write_cmd(0x0c);
  13.   LCD_write_cmd(Y_Page_Addr);
  14.   LCD_write_cmd(X_Col_Addr);
  15.   LCD_clr_scr();
  16. }
相应的清屏函数为:
  1. void LCD_clr_scr(void)
  2. {
  3.   unsigned int i;
  4.   LCD_write_cmd(X_Col_Addr);
  5.   LCD_write_cmd(Y_Page_Addr);
  6.   for(i = 504; i; i--) LCD_write_dat(0x00);
  7. }
实现字符串显示的函数为:
  1. void LCD_prints(unsigned char x, unsigned char y, unsigned char *s_dat)
  2. {
  3.   while(*s_dat && x < 10)
  4.   {
  5.      LCD_printc(x++, y, *s_dat);
  6.      s_dat++;
  7.   }
  8. }
用于驱动测试的主程序为:
  1. int32_t main(void)
  2. {
  3.     GPIO_InitTypeDef GPIO_InitStruct = {0};
  4.     RCC_HSI_Enable(RCC_HSIOSC_DIV6);
  5.         LCD5510_CONFIG();
  6.     LED_SetHigh();
  7.     CS_SetLow();
  8.     LCD5510_Init();
  9.     LCD_prints(0,0,"CW32L031");
  10.     LCD_prints(0,1,"LCD5110 ");
  11.     LCD_prints(0,2,"jinglixixi");
  12.     while (1);
  13. }
经程序的编译和下载,其显示效果如下图所示。
1.jpg
显示效果图  
您需要登录后才可以回帖 登录 | 注册

本版积分规则

518

主题

2933

帖子

39

粉丝
快速回复 在线客服 返回列表 返回顶部

518

主题

2933

帖子

39

粉丝
快速回复 在线客服 返回列表 返回顶部