[活动专区] 【AT-START-L021测评】+LCD5110屏显示驱动

[复制链接]
1899|0
 楼主| jinglixixi 发表于 2024-12-4 17:08 | 显示全部楼层 |阅读模式
本帖最后由 jinglixixi 于 2024-12-5 00:01 编辑

在AT-START-L021开发板上配有ArduinoTM Uno R3扩展接口,合理地所用它可起到事半功倍的效果。这里以一款SPI接口的显示屏为例加以驱动测试,该显示屏早期曾用在诺基亚手机上,为Nokia5110。为了借用图1所示的扩展接口而免去接线的问题,故显示屏与开发板的连接关系为:
SCL---PB7
SDA---PA15
RST---PA6
DC ---PA7
CS ---PA5
BLK---PA9

1  所用接口



所用引脚输出高低电平的语句定义为:
#define LCD_SCLK_Set   gpio_bits_write(GPIOB,GPIO_PINS_7,TRUE)  //CLK
#define LCD_SCLK_Clr   gpio_bits_write(GPIOB,GPIO_PINS_7,FALSE)

#define LCD_SDIN_Set   gpio_bits_write(GPIOA,GPIO_PINS_15,TRUE)  //DIN
#define LCD_SDIN_Clr   gpio_bits_write(GPIOA,GPIO_PINS_15,FALSE)

#define LCD_RST_Set    gpio_bits_write(GPIOA,GPIO_PINS_6,TRUE)  //RES
#define LCD_RST_Clr    gpio_bits_write(GPIOA,GPIO_PINS_6,FALSE)

#define LCD_DC_Set     gpio_bits_write(GPIOA,GPIO_PINS_7,TRUE)  //DC
#define LCD_DC_Clr     gpio_bits_write(GPIOA,GPIO_PINS_7,FALSE)

#define LCD_CS_Set     gpio_bits_write(GPIOA,GPIO_PINS_5,TRUE)  //CS
#define LCD_CS_Clr     gpio_bits_write(GPIOA,GPIO_PINS_5,FALSE)

#define LCD_BLK_Set    gpio_bits_write(GPIOA,GPIO_PINS_9,TRUE)  //BLK  
#define LCD_BLK_Clr    gpio_bits_write(GPIOA,GPIO_PINS_9,FALSE)


配置所用引脚为输出功能的函数为:
  1. void LCD_config(void)
  2. {
  3.   gpio_init_type gpio_init_struct;
  4.   crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
  5.   gpio_default_para_init(&gpio_init_struct);
  6.   gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
  7.   gpio_init_struct.gpio_out_type  = GPIO_OUTPUT_PUSH_PULL;
  8.   gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
  9.   gpio_init_struct.gpio_pins = GPIO_PINS_5|GPIO_PINS_6|GPIO_PINS_7|GPIO_PINS_9|GPIO_PINS_15;
  10.   gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
  11.   gpio_init(GPIOA, &gpio_init_struct);
  12.   crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
  13.   gpio_init_struct.gpio_pins = GPIO_PINS_7;
  14.   gpio_init(GPIOB, &gpio_init_struct);
  15. }

该显示屏的初始化函数为:
  1. void LCD_init(void)
  2. {
  3.    LCD_RST_Clr;
  4.    delay_us(1);
  5.    LCD_RST_Set;
  6.    LCD_CS_Clr;
  7.    delay_us(1);
  8.    LCD_CS_Set;
  9.    delay_us(1);
  10.    LCD_write_byte(0x21, 0);
  11.    LCD_write_byte(0xc8, 0);
  12.    LCD_write_byte(0x06, 0);
  13.    LCD_write_byte(0x13, 0);
  14.    LCD_write_byte(0x20, 0);
  15.    LCD_clear();
  16.    LCD_write_byte(0x0c, 0);
  17.    LCD_CS_Clr;
  18.    LCD_ BLK_Set;
  19. }

实现清屏处理的函数为:
  1. void LCD_clear(void)
  2. {
  3.     unsigned int i;
  4.     LCD_write_byte(0x0c, 0);                        
  5.     LCD_write_byte(0x80, 0);                        
  6.     for (i=0; i<504; i++)
  7.       LCD_write_byte(0, 1);                        
  8. }

实现字符显示功能的函数为:
  1. void LCD_write_char(unsigned char c)
  2. {
  3.     unsigned char line;
  4.     c -= 32;
  5.     for (line=0; line<6; line++)
  6.       LCD_write_byte(font6x8[c][line], 1);
  7. }

实现字符串显示功能的函数为:
  1. void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
  2. {
  3.     LCD_set_XY(X,Y);
  4.     while (*s)
  5.     {
  6.              LCD_write_char(*s);
  7.              s++;
  8.     }
  9. }

显示显示功能测试的主程序为:
  1. int main(void)
  2. {
  3.   system_clock_config();
  4.   at32_board_init();
  5.   LCD_config();
  6.   LCD_init();
  7.   LCD_clear();
  8.   LCD_write_english_string(16,0,"AT32L021");
  9.   LCD_write_english_string(16,2,"Nokia_5110");
  10.   LCD_write_english_string(16,4,"jingliixi");
  11.   while(1)
  12.   {
  13.     at32_led_toggle(LED2);
  14.     delay_ms(200);
  15.   }
  16. }

经程序的编译与下载,其显示效果如图2所示。
2  显示效果


您需要登录后才可以回帖 登录 | 注册

本版积分规则

521

主题

2949

帖子

39

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