图2 引脚位置及名称
将所用引脚配置为输出模式的函数为:
-
voidapp_init_oled_pins(void)
-
{
-
gpio_enable_pin_output(HPM_GPIO0,GPIO_DI_GPIOB, 13);
-
gpio_enable_pin_output(HPM_GPIO0,GPIO_DI_GPIOB, 14);
-
}
复制代码
在使用GPIO口模拟I2C通讯的情况下,实现高低电平输出的语句定义为:
-
#define OLED_SCLK_Set() gpio_write_pin(HPM_GPIO0, GPIO_DI_GPIOB, 13,1);
-
#define OLED_SCLK_Clr() gpio_write_pin(HPM_GPIO0, GPIO_DI_GPIOB, 13,0);
-
#define OLED_SDIN_Set() gpio_write_pin(HPM_GPIO0, GPIO_DI_GPIOB, 14,1);
-
#define OLED_SDIN_Clr() gpio_write_pin(HPM_GPIO0, GPIO_DI_GPIOB, 14,0);
复制代码
以GPIO口模拟I2C发送字节数据的函数如下:
-
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();
-
Delay_Us(2);
-
da=da<<1;
-
OLED_SCLK_Set();
-
Delay_Us(2);
-
OLED_SCLK_Clr();
-
Delay_Us(2);
-
}
-
}
复制代码
由于开发板的工作主频高达816MHz,因此在引脚输出信号时,一定要加适当的延时,否则会影响显示输出。
两种显示字模的结构如下:
-
unsignedchar F6x8[][6] =
-
{
-
0x00,0x00, 0x00, 0x00, 0x00, 0x00,// sp
-
0x00,0x00, 0x00, 0x2f, 0x00, 0x00,// !
-
0x00,0x00, 0x07, 0x00, 0x07, 0x00,// "
-
...
-
}
复制代码
-
unsignedchar F8X16[]=
-
{
-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//0
-
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//!1
-
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"2
-
...
-
}
复制代码
在以上字库的支持下,实现字符显示的函数为:
-
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][i],OLED_DATA);
-
}
-
}
复制代码
实现字符串显示的函数为:
-
void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size)
-
{
-
unsigned char j=0;
-
while (chr[j]!='')
-
{
-
OLED_ShowChar(x,y,chr[j],Char_Size);
-
x+=8;
-
if(x>120)
-
{
-
x=0;
-
y+=2;
-
}
-
j++;
-
}
-
}
复制代码
为实现汉字的显示,需要自行构建一个小型的字库,见图3所示。
图3 提取字模
配合该字库的汉字显示函数为:
-
void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no)
-
{
-
uint8_t 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;
-
}
-
}
复制代码
实现他显示效果的主程序为:
-
int main(void)
-
{
-
app_init_oled_pins();
-
OLED_Init();
-
OLED_Clear();
-
OLED_ShowString(0,2,"HPM6750 EVKMINI",16);
-
OLED_ShowString(20,4,"OLED test",16);
-
OLED_ShowString(20,6,"jennyzhaojie",8);
-
OLED_ShowCHinese(20,0,0);
-
OLED_ShowCHinese(40,0,1);
-
OLED_ShowCHinese(60,0,2);
-
OLED_ShowCHinese(80,0,3);
-
OLED_ShowCHinese(100,0,4);
-
while(1);
-
return 0;
-
}
复制代码
有了OLED屏的显示功能,进行人机交互就方便了许多。