[活动专区] 【AT-START-F435测评】F435 OLED显示驱动

[复制链接]
 楼主| hanter 发表于 2023-1-4 17:24 | 显示全部楼层 |阅读模式
本帖最后由 hanter 于 2023-1-5 09:11 编辑

分享一个我在项目中使用到的oled显示驱动,拓扑微CUG-2864ASWPG14  128*64的oled,使用IO口模拟实现并口驱动。
  1. #define E_H()                        (gpio_bits_set(LCD_RD_GPIO_Port,LCD_RD_Pin)) //(LCD_RD_GPIO_Port->BSRRL = LCD_RD_Pin )//RD
  2. #define E_L()                        (gpio_bits_reset(LCD_RD_GPIO_Port,LCD_RD_Pin)) //(LCD_RD_GPIO_Port->BSRRH = LCD_RD_Pin )
  3. #define A0_H()                        (gpio_bits_set(LCD_RS_GPIO_Port,LCD_RS_Pin)) //(LCD_RS_GPIO_Port->BSRRL = LCD_RS_Pin ) //H数据/L指令 RS
  4. #define A0_L()                        (gpio_bits_reset(LCD_RS_GPIO_Port,LCD_RS_Pin)) //(LCD_RS_GPIO_Port->BSRRH = LCD_RS_Pin )
  5. #define RW_H()                        (gpio_bits_set(LCD_WR_GPIO_Port,LCD_WR_Pin)) //(LCD_WR_GPIO_Port->BSRRL = LCD_WR_Pin ) //RW
  6. #define RW_L()                        (gpio_bits_reset(LCD_WR_GPIO_Port,LCD_WR_Pin)) //(LCD_WR_GPIO_Port->BSRRH = LCD_WR_Pin )
  7. #define CS_H()                        (gpio_bits_set(LCD_CSE1_GPIO_Port,LCD_CSE1_Pin)) //(LCD_CSE1_GPIO_Port->BSRRL = LCD_CSE1_Pin ) //CSE1
  8. #define CS_L()                        (gpio_bits_reset(LCD_CSE1_GPIO_Port,LCD_CSE1_Pin)) //(LCD_CSE1_GPIO_Port->BSRRH = LCD_CSE1_Pin )
  9. #define RST_H()                        (gpio_bits_set(LCD_RST_GPIO_Port,LCD_RST_Pin)) //(LCD_RST_GPIO_Port->BSRRL = LCD_RST_Pin ) //RST
  10. #define RST_L()                        (gpio_bits_reset(LCD_RST_GPIO_Port,LCD_RST_Pin)) //(LCD_RST_GPIO_Port->BSRRH = LCD_RST_Pin )
  11. #define BLA_H()                        (gpio_bits_set(LCD_LED_GPIO_Port,LCD_LED_Pin)) //(LCD_LED_GPIO_Port->BSRRL = LCD_LED_Pin ) //LCDLED
  12. #define BLA_L()                        (gpio_bits_reset(LCD_LED_GPIO_Port,LCD_LED_Pin)) //(LCD_LED_GPIO_Port->BSRRH = LCD_LED_Pin )

  13. #define ADC_L()                        //(GPIOA->BRR  = GPIO_Pin_7 )

  1. void DBOUT(BYTE data)
  2. {
  3.         if (data & 0x80)
  4.                 (gpio_bits_set(LCD_DB7_GPIO_Port, LCD_DB7_Pin)); //LCD_DB7_GPIO_Port->BSRRL = LCD_DB7_Pin;
  5.         else
  6.                 (gpio_bits_reset(LCD_DB7_GPIO_Port, LCD_DB7_Pin)); //LCD_DB7_GPIO_Port->BSRRH = LCD_DB7_Pin;

  7.         if (data & 0x40)
  8.                 (gpio_bits_set(LCD_DB6_GPIO_Port, LCD_DB6_Pin)); //LCD_DB6_GPIO_Port->BSRRL = LCD_DB6_Pin;
  9.         else
  10.                 (gpio_bits_reset(LCD_DB6_GPIO_Port, LCD_DB6_Pin)); //LCD_DB6_GPIO_Port->BSRRH = LCD_DB6_Pin;

  11.         if (data & 0x20)
  12.                 (gpio_bits_set(LCD_DB5_GPIO_Port, LCD_DB5_Pin)); //LCD_DB5_GPIO_Port->BSRRL = LCD_DB5_Pin;
  13.         else
  14.                 (gpio_bits_reset(LCD_DB5_GPIO_Port, LCD_DB5_Pin)); //LCD_DB5_GPIO_Port->BSRRH = LCD_DB5_Pin;

  15.         if (data & 0x10)
  16.                 (gpio_bits_set(LCD_DB4_GPIO_Port, LCD_DB4_Pin)); //LCD_DB4_GPIO_Port->BSRRL = LCD_DB4_Pin;
  17.         else
  18.                 (gpio_bits_reset(LCD_DB4_GPIO_Port, LCD_DB4_Pin)); //LCD_DB4_GPIO_Port->BSRRH = LCD_DB4_Pin;

  19.         if (data & 0x08)
  20.                 (gpio_bits_set(LCD_DB3_GPIO_Port, LCD_DB3_Pin)); //LCD_DB3_GPIO_Port->BSRRL = LCD_DB3_Pin;
  21.         else
  22.                 (gpio_bits_reset(LCD_DB3_GPIO_Port, LCD_DB3_Pin)); //LCD_DB3_GPIO_Port->BSRRH = LCD_DB3_Pin;

  23.         if (data & 0x04)
  24.                 (gpio_bits_set(LCD_DB2_GPIO_Port, LCD_DB2_Pin)); //LCD_DB2_GPIO_Port->BSRRL = LCD_DB2_Pin;
  25.         else
  26.                 (gpio_bits_reset(LCD_DB2_GPIO_Port, LCD_DB2_Pin)); //LCD_DB2_GPIO_Port->BSRRH = LCD_DB2_Pin;

  27.         if (data & 0x02)
  28.                 (gpio_bits_set(LCD_DB1_GPIO_Port, LCD_DB1_Pin)); //LCD_DB1_GPIO_Port->BSRRL = LCD_DB1_Pin;
  29.         else
  30.                 (gpio_bits_reset(LCD_DB1_GPIO_Port, LCD_DB1_Pin)); //LCD_DB1_GPIO_Port->BSRRH = LCD_DB1_Pin;

  31.         if (data & 0x01)
  32.                 (gpio_bits_set(LCD_DB0_GPIO_Port, LCD_DB0_Pin)); //LCD_DB0_GPIO_Port->BSRRL = LCD_DB0_Pin;
  33.         else
  34.                 (gpio_bits_reset(LCD_DB0_GPIO_Port, LCD_DB0_Pin)); //LCD_DB0_GPIO_Port->BSRRH = LCD_DB0_Pin;
  35. }


  36. static void delay(int16 n)
  37. {
  38.         int8 i;

  39.         for(; n>0; n--)
  40.         {
  41.                 for(i=3; i>0; i--);
  42.         }
  43. }

  1. static void WriteData(unsigned char DATA)
  2. {
  3.         //CheckBusy();
  4.         CS_L();        
  5.         E_H();
  6.         A0_H();
  7.         DBOUT(DATA);        
  8.         RW_L();        
  9.         delay(1);
  10.         RW_H();
  11.         CS_H();
  12. }

  13. static void WriteCommand(unsigned char command)
  14. {
  15.         //CheckBusy();
  16.         CS_L();        
  17.         E_H();        
  18.         A0_L();
  19.         DBOUT(command);
  20.         RW_L();        
  21.         delay(1);
  22.         RW_H();        
  23.         CS_H();
  24. }

  1. void Lcd_Init_RST(void)
  2. {
  3.         //WriteCommand(0xae); /* set  display off */
  4.         WriteCommand(0x00); /* set  lower column start address */
  5.         WriteCommand(0x10); /* set  higher column start address */
  6.         WriteCommand(0xD5); /* set  display clock divide/oscillator frequency */
  7.         WriteCommand(0xA0);
  8.         WriteCommand(0xA8); /* set  multiplex ratio */
  9.         WriteCommand(0x3F);
  10.         //         WriteCommand(0xD3);  /* set  display offset  */
  11.         //         WriteCommand(0x00);   
  12.         WriteCommand(0x40);  /* set  display start line */
  13.         WriteCommand(0x00);
  14.         WriteCommand(0x20); /* set  Memory  Addressing Mode  */
  15.         WriteCommand(0x02);
  16.         WriteCommand(0xa0); /* set  segment remap  */
  17.         WriteCommand(0xC8); /* Set COM Output Scan Direction */
  18.         WriteCommand(0xDA); /* Set COM Pins Hardware Configuration */
  19.         WriteCommand(0x12);
  20.         WriteCommand(0xc0); /* set  com scan direction */
  21.         WriteCommand(0xd3); /* set  display offset  */
  22.         WriteCommand(0x40);
  23.         WriteCommand(0x81); /* set contrast control */
  24.         WriteCommand(0xBF);
  25.         WriteCommand(0xD9); /* set Pre-charge Period */
  26.         WriteCommand(0x25);
  27.         WriteCommand(0xA4); /* entire display on */
  28.         WriteCommand(0xA6); /* set normal/inverse display */
  29.         WriteCommand(0xaf); /* set  display on */
  30. }





微信图片_20230105085824.jpg
微信图片_20230105085830.jpg



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

本版积分规则

4

主题

23

帖子

0

粉丝
快速回复 返回顶部 返回列表