- void LCD5510_CONFIG(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- __RCC_GPIOC_CLK_ENABLE();
- GPIO_InitStruct.IT = GPIO_IT_NONE;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pins = GPIO_PIN_6 | GPIO_PIN_7;
- GPIO_Init(CW_GPIOB, &GPIO_InitStruct);
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pins = GPIO_PIN_10 | GPIO_PIN_11| GPIO_PIN_12| GPIO_PIN_15;
- GPIO_Init(CW_GPIOA, &GPIO_InitStruct);
- }
为输出高低电平,所作的语句定义为:
#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
实现串行发送字节数据的函数为:
- void LCD_write_byte(unsigned char wbyte, unsigned char dat_cmd)
- {
- unsigned char i;
- if(dat_cmd)
- {
- DC_SetHigh();
- }
- else
- {
- DC_SetLow();
- }
- for(i = 8; i; i--)
- {
- if(wbyte & 0x80)
- {
- SDIN_SetHigh();
- }
- else
- {
- SDIN_SetLow();
- }
- SCLK_SetLow();
- wbyte <<= 1;
- delay_1us(1);
- SCLK_SetHigh();
- }
- }
对LCD5110显示屏初始化的函数为:
- void LCD5110_Init(void)
- {
- delay_1ms(800);
- RST_SetLow();
- delay_1us(2);
- RST_SetHigh();
- LCD_write_cmd(0x21);
- LCD_write_cmd(0x06);
- LCD_write_cmd(0x13);
- LCD_write_cmd(0xc8);
- LCD_write_cmd(0x20);
- LCD_write_cmd(0x0c);
- LCD_write_cmd(Y_Page_Addr);
- LCD_write_cmd(X_Col_Addr);
- LCD_clr_scr();
- }
相应的清屏函数为:
- void LCD_clr_scr(void)
- {
- unsigned int i;
- LCD_write_cmd(X_Col_Addr);
- LCD_write_cmd(Y_Page_Addr);
- for(i = 504; i; i--) LCD_write_dat(0x00);
- }
实现字符串显示的函数为:
- void LCD_prints(unsigned char x, unsigned char y, unsigned char *s_dat)
- {
- while(*s_dat && x < 10)
- {
- LCD_printc(x++, y, *s_dat);
- s_dat++;
- }
- }
用于驱动测试的主程序为:
- int32_t main(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- RCC_HSI_Enable(RCC_HSIOSC_DIV6);
- LCD5510_CONFIG();
- LED_SetHigh();
- CS_SetLow();
- LCD5510_Init();
- LCD_prints(0,0,"CW32L031");
- LCD_prints(0,1,"LCD5110 ");
- LCD_prints(0,2,"jinglixixi");
- while (1);
- }
经程序的编译和下载,其显示效果如下图所示。
显示效果图