本帖最后由 jinglixixi 于 2020-8-16 10:46 编辑
OLED屏是一种小巧的显示器件,特别是I2C接口的OLED 屏更能节省I/O口资源。本次使用的是一款0.91'的单色OLED屏,它比常规的OLED屏要长且窄,故更适于显示信息和参数,也更适于用在便携装置上。 若采用AutoChips7801x开发板来驱动它可使用开发板上的JP9接口来连接,其中SCLK连接PB13,而SDIN连接PC4,所产生的显示效果如图所示。 定义相关引脚输出高低电平的语句为: #defineOLED_SCLK_Set() GPIO_SetPinLevel(GPIOB,GPIO_PIN13, GPIO_LEVEL_HIGH); #define OLED_SCLK_Clr() GPIO_SetPinLevel(GPIOB, GPIO_PIN13,GPIO_LEVEL_LOW);
#defineOLED_SDIN_Set() GPIO_SetPinLevel(GPIOC, GPIO_PIN4,GPIO_LEVEL_HIGH); #defineOLED_SDIN_Clr() GPIO_SetPinLevel(GPIOC,GPIO_PIN4, GPIO_LEVEL_LOW);
显示效果图
引脚的功能配置函数为: void LCD_GPIO_Cogfig(void)
{
GPIO_SetFunc(GPIOC, GPIO_PIN4, GPIO_FUN0);
GPIO_SetFunc(GPIOB, GPIO_PIN13, GPIO_FUN0);
GPIO_SetDir(GPIOC, GPIO_PIN4, GPIO_OUT);
GPIO_SetDir(GPIOB, GPIO_PIN13, GPIO_OUT);
}
OLED屏初始化函数为: void OLED_Init(void)
{
LCD_GPIO_Cogfig();
OLED_SCLK_Set();
OLED_SDIN_Set();
mdelay(800);
OLED_WR_Byte(0xAE,OLED_CMD);//--display off
OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
OLED_WR_Byte(0x81,OLED_CMD); // contract control
OLED_WR_Byte(0xFF,OLED_CMD);//--128
OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
OLED_WR_Byte(0x1F,OLED_CMD);//--1/32 duty
OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
OLED_WR_Byte(0x00,OLED_CMD);//
OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
OLED_WR_Byte(0xf0,OLED_CMD);//
OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
OLED_WR_Byte(0x22,OLED_CMD);//
OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
OLED_WR_Byte(0x02,OLED_CMD);//
OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
OLED_WR_Byte(0x49,OLED_CMD);//
OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
OLED_WR_Byte(0x14,OLED_CMD);//
OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
OLED_Clear();
}
字符串显示函数为: void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size)
{
unsigned char j=0;
while (chr[j]!='\0')
{ OLED_ShowChar(x,y,chr[j],Char_Size);
x+=8;
if(x>120){x=0;y+=2;}
j++;
}
}
汉字显示函数为: void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no)
{
uint8_t t;
OLED_Set_Pos(x,y);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[no][t],OLED_DATA);
}
OLED_Set_Pos(x,y+1);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[no][16+t],OLED_DATA);
}
}
|