2122 views|0 replies

1452

Posts

1

Resources
The OP
 

[ESK32-360 Review] + OLED screen driver [Copy link]

 This post was last edited by jinglixixi on 2020-8-8 00:07

The ESK32-360 development board is a development board with rich peripheral resources, so it is very difficult to find a free pin. I have a 0.91' OLED display and plan to realize its driving display on the development board. In desperation, I have to use the method of using the GPIO ports of LED1 and LED2 to drive the 0.91' OLED screen.

The LED interface circuit is shown in Figure 1. LED1 can be used to connect SCLK, and LED2 can be used to connect SDIN.

Figure 1 LED interface circuit

The definition statements for LED1 and LED2 to output high and low levels are:

#define OLED_SCLK_Clr() GPIO_WriteOutBits(HTCFG_LED0, HTCFG_OUTPUT_LED0_GPIO_PIN, RESET);

#define OLED_SCLK_Set() GPIO_WriteOutBits(HTCFG_LED0, HTCFG_OUTPUT_LED0_GPIO_PIN, SET);

#define OLED_SDIN_Clr() GPIO_WriteOutBits(HTCFG_LED1, HTCFG_OUTPUT_LED1_GPIO_PIN, RESET);

#define OLED_SDIN_Set() GPIO_WriteOutBits(HTCFG_LED1, HTCFG_OUTPUT_LED1_GPIO_PIN, SET);

The main program to implement the content shown in Figure 2 is as follows:

int main(void)         
{
  FlagStatus TmpStatus = RESET;
  CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
  HTCFG_OUTPUT_LED0_CLK(CKCUClock)    = 1;
  HTCFG_OUTPUT_LED1_CLK(CKCUClock)    = 1;
  HTCFG_OUTPUT_LED2_CLK(CKCUClock)    = 1;
  HTCFG_INPUT_WAKE_CLK(CKCUClock)     = 1;
  HTCFG_INPUT_KEY1_CLK(CKCUClock)     = 1;
  HTCFG_INPUT_KEY2_CLK(CKCUClock)     = 1;
  CKCUClock.Bit.AFIO                  = 1;
  CKCUClock.Bit.BKP                   = 1;
  CKCU_PeripClockConfig(CKCUClock, ENABLE);
  
  if (PWRCU_CheckReadyAccessed() != PWRCU_OK)
  {
    while (1);
  }

  AFIO_GPxConfig(HTCFG_INPUT_WAKE_ID, HTCFG_INPUT_WAKE_AFIO_PIN, AFIO_MODE_1);
  AFIO_GPxConfig(HTCFG_INPUT_KEY1_ID, HTCFG_INPUT_KEY1_AFIO_PIN, AFIO_MODE_DEFAULT);
  AFIO_GPxConfig(HTCFG_INPUT_KEY2_ID, HTCFG_INPUT_KEY2_AFIO_PIN, AFIO_MODE_DEFAULT);

  GPIO_DirectionConfig(HTCFG_WAKE, HTCFG_INPUT_WAKE_GPIO_PIN, GPIO_DIR_IN);
  GPIO_DirectionConfig(HTCFG_KEY1, HTCFG_INPUT_KEY1_GPIO_PIN, GPIO_DIR_IN);
  GPIO_DirectionConfig(HTCFG_KEY2, HTCFG_INPUT_KEY2_GPIO_PIN, GPIO_DIR_IN);

  GPIO_PullResistorConfig(HTCFG_WAKE, HTCFG_INPUT_WAKE_GPIO_PIN, GPIO_PR_DOWN);
  GPIO_PullResistorConfig(HTCFG_KEY1, HTCFG_INPUT_KEY1_GPIO_PIN, GPIO_PR_UP);
  GPIO_PullResistorConfig(HTCFG_KEY2, HTCFG_INPUT_KEY2_GPIO_PIN, GPIO_PR_UP);

  GPIO_InputConfig(HTCFG_WAKE, HTCFG_INPUT_WAKE_GPIO_PIN, ENABLE);
  GPIO_InputConfig(HTCFG_KEY1, HTCFG_INPUT_KEY1_GPIO_PIN, ENABLE);
  GPIO_InputConfig(HTCFG_KEY2, HTCFG_INPUT_KEY2_GPIO_PIN, ENABLE);


  AFIO_GPxConfig(HTCFG_OUTPUT_LED0_ID, HTCFG_OUTPUT_LED0_AFIO_PIN, AFIO_MODE_DEFAULT);
  AFIO_GPxConfig(HTCFG_OUTPUT_LED1_ID, HTCFG_OUTPUT_LED1_AFIO_PIN, AFIO_MODE_DEFAULT);
  AFIO_GPxConfig(HTCFG_OUTPUT_LED2_ID, HTCFG_OUTPUT_LED2_AFIO_PIN, AFIO_MODE_DEFAULT);
  
  GPIO_DirectionConfig(HTCFG_LED0, HTCFG_OUTPUT_LED0_GPIO_PIN, GPIO_DIR_OUT);
  GPIO_DirectionConfig(HTCFG_LED1, HTCFG_OUTPUT_LED1_GPIO_PIN, GPIO_DIR_OUT);
  GPIO_DirectionConfig(HTCFG_LED2, HTCFG_OUTPUT_LED2_GPIO_PIN, GPIO_DIR_OUT);
  
  OLED_Init();	 
  OLED_Clear(); 
  OLED_ShowString(16,0, "HT32F1654",16);
  OLED_ShowString(16,2, "OLED TEST",16);
  while(1);

}

Figure 2 OLED screen display effect

When the Chinese character library and display function are added, the display effect is shown in Figure 3.

Figure 3 OLED screen menu effect

The statements that produce the display effect are:

OLED_Clear();

OLED_ShowCHinese(0,0,0); //Penghu Bay

OLED_ShowCHinese(18,0,1);

OLED_ShowCHinese(36,0,2);

OLED_ShowString(0,2, "Player NO",16);

The corresponding display function is:

void OLED_ShowCHinese(u8 x,u8 y,u8 no)
{  
    u8 t,adder=0;
    OLED_Set_Pos(x,y);
    for(t=0;t<16;t++)
    {
 OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
                  adder+=1;
    }
    OLED_Set_Pos(x,y+1);
     for(t=0;t<16;t++)
     {
 OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
 adder+=1;
   }
}

This post is from Domestic Chip Exchange
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list