【GD32L233C-START测评】 LCD5110屏的显示驱动
[复制链接]
前面介绍过I2C接口的OLED屏显示驱动,这次介绍的是SPI接口的显示屏驱动,该显示屏是一款用用于诺基亚手机的显示屏LCD5110,该显示屏的显示效果如图1和图2所示。
图1显示效果
图2显示效果
该显示屏与开发板的连接关系为:
CLK--- PB10
DIN ---PB11
DC --- PB13
RST ---PB14
CS ---PB15
其引脚输出高低电平的语句定义为:
#define LCD_CLK_L gpio_bit_resset(GPIOB, GPIO_PIN_10)
#define LCD_CLK_H gpio_bit_set(GPIOB, GPIO_PIN_10)
#define LCD_DIN_L gpio_bit_reset(GPIOB, GPIO_PIN_11)
#define LCD_DIN_H gpio_bit_set(GPIOB, GPIO_PIN_11)
#define LCD_DC_L gpio_bit_reset(GPIOB, GPIO_PIN_13)
#define LCD_DC_H gpio_bit_set(GPIOB, GPIO_PIN_13)
#define LCD_RST_L gpio_bit_reset(GPIOB, GPIO_PIN_14)
#define LCD_RST_H gpio_bit_set(GPIOB, GPIO_PIN_14)
#define LCD_CS_L gpio_bit_reset(GPIOB, GPIO_PIN_15)
#define LCD_CS_H gpio_bit_set(GPIOB, GPIO_PIN_15)
显示屏的初始化函数为:
void LCD5110_Init(void)
{
delay_1ms(800);
LCD_reset_hard;
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_write_byte(unsigned char wbyte, unsigned char dat_cmd)
{
unsigned char i;
LCD_CS_L;
if(dat_cmd)
{
LCD_DC_H;
}
else
{
LCD_DC_L;
}
for(i = 8; i; i--)
{
if(wbyte & 0x80)
{
LCD_DIN_H;
}
else
{
LCD_DIN_L;
}
Delay_us(2);
LCD_CLK_L;
wbyte <<= 1;
Delay_us(2);
LCD_CLK_H;
}
LCD_CS_H;
}
清除显示屏的函数为:
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_printc(unsigned char x, unsigned char y, unsigned char c_dat)
{
unsigned char i, j;
c_dat -= 32;
x <<= 3;
y <<= 1;
for(j = 0; j < 2; j++)
{
LCD_pos_byte(x, (y + j));
for(i = 0; i < 8; i++)
LCD_write_dat(Font_code[c_dat][8 * j + i]);
}
}
字符串的显示函数为:
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++;
}
}
实现图示效果的主程序为:
int main(void)
{
rcu_periph_clock_enable(RCU_GPIOB);
gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_10 | GPIO_PIN_11| GPIO_PIN_13| GPIO_PIN_14| GPIO_PIN_15);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10 | GPIO_PIN_11| GPIO_PIN_13| GPIO_PIN_14| GPIO_PIN_15);
delay_1ms(500);
LCD5110_Init();
LCD_prints(0,0,"GD32L233C");
LCD_prints(0,1,"LCD5110 ");
LCD_prints(0,2,"jinglixixi");
while(1);
}
|