本帖最后由 jinglixixi 于 2020-8-17 10:01 编辑
OLED 屏有多种形式,既有单色、双色屏,也有彩色屏;既有I2C接口的,也有SPI接口的。 本次使用的是SPI接口的彩色屏,其分辨率是160*80点像素,16位色彩。 OLED 屏与AC7811的连接关系如下: SCLK --- PA4 SDIN --- PA5 RST --- PA6 DC --- PA2 CS --- PA3 BLK --- PA7
定义相关引脚输出高低电平的语句为: #define OLED_BLK_Set() GPIO_SetPinBits(7); // PA7
#define OLED_CS_Set() GPIO_SetPinBits(3); // PA3 #define OLED_CS_Clr() GPIO_ResetPinBits(3); // PA3
#define OLED_SCLK_Set() GPIO_SetPinBits(4); // PA4 #define OLED_SCLK_Clr() GPIO_ResetPinBits(4); // PA4
#define OLED_SDIN_Set() GPIO_SetPinBits(5); // PA5 #define OLED_SDIN_Clr() GPIO_ResetPinBits(5); // PA5
#define OLED_DC_Set() GPIO_SetPinBits(2); // PA2 #define OLED_DC_Clr() GPIO_ResetPinBits(2); //PA2
#define OLED_RST_Set() GPIO_SetPinBits(6); // PA6 #define OLED_RST_Clr() GPIO_ResetPinBits(6); // PA6
引脚配置的函数为: void GPIO_Configuration(void)
{
GPIO_SetDir(GPIO_PA1, 1);
GPIO_SetDir(GPIO_PA2, 1);
GPIO_SetDir(GPIO_PA3, 1);
GPIO_SetDir(GPIO_PA4, 1);
GPIO_SetDir(GPIO_PA5, 1);
GPIO_SetDir(GPIO_PA6, 1);
GPIO_SetDir(GPIO_PA7, 1);
}
OLED屏的初始化函数为: void Lcd_Init(void)
{
OLED_RST_Clr();
mdelay(20);
OLED_RST_Set();
mdelay(20);
OLED_BLK_Set();
LCD_WR_REG(0x11);
mdelay(100);
LCD_WR_REG(0x21);
LCD_WR_REG(0xB1);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_REG(0xB2);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_REG(0xB3);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x3A);
LCD_WR_DATA8(0x3A);
LCD_WR_REG(0xB4);
LCD_WR_DATA8(0x03);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x62);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x04);
LCD_WR_REG(0xC1);
LCD_WR_DATA8(0xC0);
LCD_WR_REG(0xC2);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x00);
LCD_WR_REG(0xC3);
LCD_WR_DATA8(0x8D);
LCD_WR_DATA8(0x6A);
LCD_WR_REG(0xC4);
LCD_WR_DATA8(0x8D);
LCD_WR_DATA8(0xEE);
LCD_WR_REG(0xC5); /*VCOM*/
LCD_WR_DATA8(0x0E);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0x10);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x0A);
LCD_WR_DATA8(0x12);
LCD_WR_DATA8(0x27);
LCD_WR_DATA8(0x37);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x10);
LCD_WR_REG(0xE1);
LCD_WR_DATA8(0x10);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x03);
LCD_WR_DATA8(0x0F);
LCD_WR_DATA8(0x06);
LCD_WR_DATA8(0x02);
LCD_WR_DATA8(0x08);
LCD_WR_DATA8(0x0A);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x26);
LCD_WR_DATA8(0x36);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0E);
LCD_WR_DATA8(0x10);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_REG(0x36);
LCD_WR_DATA8(0x78);
LCD_WR_REG(0x29);
}
图片显示函数为: void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2)
{
int i;
LCD_Address_Set(x1,y1,x2,y2);
for(i=0;i<1600;i++)
{
LCD_WR_DATA8(image[i*2+1]);
LCD_WR_DATA8(image[i*2]);
}
}
实现显示测试的主程序为: int main(void)
{
u8 i;
InitDebug();
InitDelay();
GPIO_SetDir(GPIO_PA0, 1);
mdelay(200);
GPIO_Configuration();
Lcd_Init();
LCD_Clear(WHITE);
BACK_COLOR=WHITE;
LCD_Clear(WHITE);
LCD_ShowString(10,0,"LCD_W:",RED);
LCD_ShowNum(70,0,LCD_W,3,RED);
LCD_ShowString(10,20,"LCD_H:",RED);
LCD_ShowNum(70,20,LCD_H,2,RED);
for(i=0;i<4;i++)
{
LCD_ShowPicture(i*40,40,39+i*40,79);
}
while(1);
}
显示QQ图标 void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2)
{
int i;
LCD_Address_Set(x1,y1,x2,y2);
for(i=0;i<3808;i++)
{
LCD_WR_DATA8(gImage_jsj[i*2]);
LCD_WR_DATA8(gImage_jsj[i*2+1]);
}
}
LCD_ShowString(56,0,"LCD_W:",RED); LCD_ShowNum(70,0,56,3,RED);
LCD_ShowString(56,20,"LCD_H:",RED);LCD_ShowNum(70,20,68,2,RED);
for(i=0;i<4;i++)
{
LCD_ShowPicture(0,0,55,67);
}
显示计算机图标
void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2)
{
int i;
LCD_Address_Set(x1,y1,x2,y2);
for(i=0;i<12800;i++)
{
LCD_WR_DATA8(gImage_moled[i*2]);
LCD_WR_DATA8(gImage_moled[i*2+1]);
}
}
LCD_ShowPicture(0,0,159,79);
显示彩色图片
|