前面介绍了双色OLED屏的驱动,这次以一种0.96寸LCD屏的显示驱动,其显示分辨率为160*80。 该显示屏以SPI方式,本打算以最经济的方式利用Arduio接口来连接,无奈在SPI接口部位并没有提供VCC,只好以飞线的方式来连接,具体形式如下图所示。
LCD屏连接及显示效果
除电源引脚外,LCD屏与开发板的连接关系如下: OLED_SCLK ---- P43 OLED_SDIN ---- P45 OLED_RST ---- P44 OLED_DC ---- P42 OLED_CS ---- P53 OLED_BLK ---- P06
为此,以GPIO口模拟SPI发送字节数据的函数为:
void LCD_Writ_Bus(u8 dat)
{
u8 i;
OLED_CS=0;
for(i=0;i<8;i++)
{
OLED_SCLK=0;
if(dat&0x80)
OLED_SDIN=1;
else
OLED_SDIN=0;
OLED_SCLK=1;
dat<<=1;
}
OLED_CS=1;
}
LCD屏的初始化函数为: void Lcd_Init(void)
{
OLED_RST=0;
Delay(200);
OLED_RST=1;
Delay(200);
LCD_WR_REG(0x11);
Delay(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);
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);
OLED_BLK=1;
}
LCD屏以指定色彩清除屏幕的函数为:
void LCD_Clear(u16 Color)
{
u16 i,j;
LCD_Address_Set(0,0,LCD_W-1,LCD_H-1);
for(i=0;i<LCD_W;i++)
{
for (j=0;j<LCD_H;j++)
{
LCD_WR_DATA(Color);
}
}
}
显示字符及字符串显示的函数为: void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode,u16 color)
{
u8 temp;
u8 pos,t;
u16 x0=x;
if(x>LCD_W-16||y>LCD_H-16) return;
num=num-' ';
LCD_Address_Set(x,y,x+8-1,y+16-1);
if(!mode)
{
for(pos=0;pos<16;pos++)
{
temp=asc2_1608[(u16)num*16+pos];
for(t=0;t<8;t++)
{
if(temp&0x01)LCD_WR_DATA(color);
else LCD_WR_DATA(BACK_COLOR);
temp>>=1;
x++;
}
x=x0;
y++;
}
}
else
{
for(pos=0;pos<16;pos++)
{
temp=asc2_1608[(u16)num*16+pos];
for(t=0;t<8;t++)
{
if(temp&0x01) LCD_DrawPoint(x+t,y+pos,color);
temp>>=1;
}
}
}
}
void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color)
{
while(*p!='\0')
{
if(x>LCD_W-16){x=0;y+=16;}
if(y>LCD_H-16){y=x=0;LCD_Clear(RED);}
LCD_ShowChar(x,y,*p,0,color);
x+=8;
p++;
}
}
实现图示效果的主程序为: void main(void)
{
Delay(50);
P0CON = 0xFF;
P0PH = 0x00;
P4CON = 0xFF;
P4PH = 0x01;
P5CON = 0xFF;
P5PH = 0x00;
GPIO_Init(GPIO0, GPIO_PIN_6, GPIO_MODE_OUT_PP);
GPIO_Init(GPIO5, GPIO_PIN_3, GPIO_MODE_OUT_PP);
GPIO_Init(GPIO4, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5, GPIO_MODE_OUT_PP);
Delay(100);
Lcd_Init();
LCD_Clear(RED);
BACK_COLOR=RED;
LCD_ShowString(20,10,"NBK-RD8x3x TEST",YELLOW);
LCD_ShowString(20,30,"Redfine",YELLOW);
while(1);
}
本打算以该显示来完成图像的显示,可惜的是在编译程序时才发现程序的存储较为有限,以致无法存放下160*80像素图片的显示。
|