[RVB2601 creative application development] + OLED screen display driver
[Copy link]
This post was last edited by jinglixixi on 2022-5-10 21:51
The development board is equipped with an LCD display, but from the example program it seems that it only provides a monochrome image display mode and does not provide character display function, which brings some inconvenience to use.
In order to verify the usage of the GPIO port that we have mastered previously, we first use the GPIO port to simulate I2C to drive a two-color OLED display for easy testing and verification.
For ease of use, the display is directly connected to the corresponding pins of the Arduino interface on the development board, as shown in Figure 1.
Figure 1 Arduino interface
To do this, the function that configures the pin as an output is as follows:
void oled_pinmux_init()
{
csi_pin_set_mux(PA8, PIN_FUNC_GPIO);
csi_pin_set_mux(PA9, PIN_FUNC_GPIO);
csi_gpio_pin_init(&scl, PA8);
csi_gpio_pin_dir(&scl, GPIO_DIRECTION_OUTPUT);
csi_gpio_pin_init(&sda, PA9);
csi_gpio_pin_dir(&sda, GPIO_DIRECTION_OUTPUT);
}
The statements for outputting high and low levels of the relevant pins are defined as:
#define OLED_SCLK_Set() csi_gpio_pin_write(&scl, GPIO_PIN_HIGH)
#define OLED_SCLK_Clr() csi_gpio_pin_write(&scl, GPIO_PIN_LOW)
#define OLED_SDIN_Set() csi_gpio_pin_write(&sda, GPIO_PIN_HIGH)
#define OLED_SDIN_Clr() csi_gpio_pin_write(&sda, GPIO_PIN_LOW)
The function to simulate byte data sending is:
void Write_IIC_Byte(unsigned char IIC_Byte)
{
unsigned char i;
unsigned char m,da;
da=IIC_Byte;
OLED_SCLK_Clr();
for(i=0;i<8;i++)
{
m=da;
m=m&0x80;
if(m==0x80)
{
OLED_SDIN_Set();
}
else
{
OLED_SDIN_Clr();
}
udelay (2);
da=da<<1;
OLED_SCLK_Set();
udelay (2);
OLED_SCLK_Clr();
udelay (2);
}
}
The function to implement the screen clearing process is:
void OLED_Clear(void)
{
uint8_t i,n;
for(i=0;i<8;i++)
{
OLED_WR_Byte(0xb0+i,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0x10,OLED_CMD);
for(n=0;n<128;n++) OLED_WR_Byte(0,OLED_DATA);
}
}
The function to implement character display is:
void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t Char_Size)
{
unsigned char c=0,i=0;
c=chr-' ';
if(x>Max_Column-1)
{
x=0;
y=y+2;
}
if(Char_Size ==16)
{
OLED_Set_Pos(x,y);
for(i=0;i<8;i++) OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++) OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
}
else
{
OLED_Set_Pos(x,y);
for(i=0;i<6;i++) OLED_WR_Byte(F6x8[c],OLED_DATA);
}
}
The main program to achieve the display effect of Figure 2 is:
int main(void)
{
board_yoc_init();
LOGD(TAG, "%s\n", aos_get_app_version());
oled_init();
led_pinmux_init();
key_init();
oled_pinmux_init();
OLED_Init();
OLED_Clear();
OLED_ShowString(20,0,"CH2601",16);
OLED_ShowString(20,2,"OLED test",16);
while (1) {
led_refresh();
udelay(1000 * 500);
}
return 0;
}
Figure 2 Display effect
In this way, while solving the display needs, the effect of dual-screen display is also achieved. Later, we will strive to expand the display function of the LCD screen to realize the character display function.
|