本帖最后由 jinglixixi 于 2020-8-16 11:28 编辑
常规的OLED屏多是单色显示器件,即使是双色屏也首行是一种色彩,其它行是一种色彩。本次使用的是一款16位色的彩色屏,因此其色彩表现力十分丰富,适于为小型便携式装置的显示器。 1. OLED屏字符显示 1)OLED屏与NV32F100的连接关系如下: SCLK --- PE0 SDIN ---PE1 RST --- PE2 DC --- PE3 CS --- PE5 BLK --- PE6 2)为进行显示定义引脚输出高低电平的语句为: #defineOLED_SCLK_Clr() GPIO_PinClear(GPIO_PTE0); // clr PE1 #defineOLED_SCLK_Set() GPIO_PinSet(GPIO_PTE0);
#defineOLED_SDIN_Clr() GPIO_PinClear(GPIO_PTE1); // din PE0 #defineOLED_SDIN_Set() GPIO_PinSet(GPIO_PTE1);
#defineOLED_RST_Set() GPIO_PinSet(GPIO_PTE2); // rst PE2 #defineOLED_RST_Clr() GPIO_PinClear(GPIO_PTE2);
#defineOLED_DC_Set() GPIO_PinSet(GPIO_PTE3); // dc PE 3 #defineOLED_DC_Clr() GPIO_PinClear(GPIO_PTE3);
#defineOLED_CS_Set() GPIO_PinSet(GPIO_PTE5); // dc PE5 #defineOLED_CS_Clr() GPIO_PinClear(GPIO_PTE5);
#defineOLED_BLK_Set() GPIO_PinSet(GPIO_PTE6); // dc PE6 #defineOLED_BLK_Clr() GPIO_PinClear(GPIO_PTE6);
3)OLED屏初始化函数为: void Lcd_Init(void)
{
OLED_RST_Clr();
delay_ms(20);
OLED_RST_Set();
delay_ms(20);
OLED_BLK_Set();
LCD_WR_REG(0x11);
delay_ms(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);
}
4)汉字显示函数为: void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size1,u16 color)
{
u8 i,j;
u8 *temp,size11;
if(size1==16)
{
temp = Hzk16;
}
if(size1==32)
{
temp = Hzk32;
}
LCD_Address_Set(x,y,x+size1-1,y+size1-1);
size11=size1*size1/8;
temp+=index*size11;
for(j=0;j<size11;j++)
{
for(i=0;i<8;i++)
{
if((*temp&(1<<i))!=0)
{
LCD_WR_DATA(color);
}
else
{
LCD_WR_DATA(BACK_COLOR);
}
}
temp++;
}
}
2. OLED屏图片显示 1)图片显示函数 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]);
}
}
2)显示主程序 int main (void)
{
u8 i;
float t=0;
sysinit();
cpu_identify();
RTC_ConfigType sRTCConfig;
RTC_ConfigType *pRTCConfig = &sRTCConfig;
pRTCConfig->u16ModuloValue = 9;
pRTCConfig->bInterruptEn = RTC_INTERRUPT_ENABLE;
pRTCConfig->bClockSource = RTC_CLKSRC_1KHZ;
pRTCConfig->bClockPresaler = RTC_CLK_PRESCALER_100;
RTC_SetCallback(RTC_Task);
RTC_Init(pRTCConfig);
GPIO_Init(GPIOB, GPIO_PTE7_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE0_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE1_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE2_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE3_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE5_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE6_MASK, GPIO_PinOutput);
Lcd_Init();
LCD_Clear(WHITE);
BACK_COLOR=WHITE;
delay_ms(100);
while(1)
{
LCD_ShowChinese(28,0,0,32,RED);
LCD_ShowChinese(60,0,1,32,RED);
LCD_ShowChinese(92,0,2,32,RED);
LCD_ShowChinese(20,40,0,16,RED);
LCD_ShowChinese(36,40,1,16,RED);
LCD_ShowChinese(52,40,2,16,RED);
LCD_ShowChinese(68,40,3,16,RED);
LCD_ShowChinese(84,40,4,16,RED);
LCD_ShowChinese(100,40,5,16,RED);
LCD_ShowChinese(116,40,6,16,RED);
LCD_ShowString(0,60,"1.44 TFT SPI",RED);
LCD_ShowNum1(104,60,t,5,RED);//ÏÔʾСÊý
t+=0.01;
delay_ms(1000);
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);
}
delay_ms(1000);
LCD_Clear(WHITE);
}
}
3)运行效果 运行效果图
|