【CW32L052测评】+彩色LCD屏驱动显示
[复制链接]
尽管开发板已配置了液晶显示屏,但在图像的表现力上还是离不开彩色LCD屏的使用。
这里所用的是一种0.96寸的彩色屏,并采用SPI接口工作。
显示屏与开发板的连接关系为:
CLK--- PB08
DIN--- PB09
RST--- PF04
DC--- PF05
CS --- PF06
BLK --- PF07
所用引脚输出高低电平的语句定义为:
#define OLED_SCLK_Set() PB08_SETHIGH()
#define OLED_SCLK_Clr() PB08_SETLOW()
#define OLED_SDIN_Set() PB09_SETHIGH()
#define OLED_SDIN_Clr() PB09_SETLOW()
#define OLED_RST_Set() PF04_SETHIGH()
#define OLED_RST_Clr() PF04_SETLOW()
#define OLED_DC_Set() PF05_SETHIGH()
#define OLED_DC_Clr() PF05_SETLOW()
#define OLED_CS_Set() PF06_SETHIGH()
#define OLED_CS_Clr() PF06_SETLOW()
#define OLED_BLK_Set() PF07_SETHIGH()
#define OLED_BLK_Clr() PF07_SETLOW()
所用引脚的配置函数为:
void test_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pins = GPIO_PIN_8;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_Init(CW_GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.Pins = GPIO_PIN_9;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_Init(CW_GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.Pins = GPIO_PIN_4;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_Init(CW_GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.Pins = GPIO_PIN_5;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_Init(CW_GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.Pins = GPIO_PIN_6;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_Init(CW_GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.Pins = GPIO_PIN_7;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_Init(CW_GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.Pins = GPIO_PIN_13;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_Init(CW_GPIOC, &GPIO_InitStructure);
}
以GPIO口模拟SPI发送字节数据的函数为:
void LCD_Writ_Bus(u8 dat)
{
u8 i;
OLED_CS_Clr();
for(i=0;i<8;i++)
{
OLED_SCLK_Clr();
if(dat&0x80)
OLED_SDIN_Set();
else
OLED_SDIN_Clr();
OLED_SCLK_Set();
dat<<=1;
}
OLED_CS_Set();
}
实现色彩清屏的函数为:
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_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 LCD_ShowPictureb(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_RW[i*2]);
LCD_WR_DATA8(gImage_RW[i*2+1]);
}
}
进行测试的主程序为:
int32_t main(void)
{
RCC_Configuration();
InitTick( 24000000 );
test_Configuration();
SysTickDelay(200);
Lcd_Init();
LCD_Clear(BLACK);
LCD_ShowPictureb(0,0,159,79);
BACK_COLOR=RED;
SysTickDelay(5000);
LCD_Clear(RED);
LCD_ShowString(20,10,"CW32L052 TEST",YELLOW);
LCD_ShowString(20,30,"jinglixixi",YELLOW);
while (1);
}
经程序的编译和下载,其测试结果如图1至图3所示,说明功能正确。
图1 LCD屏显示效果
图2 图片显示效果
图3 显示细节
|