尽管前面已经介绍了串行数码管模块的显示方式,但相对来讲其显示的信息量量及显示形式还相对有限,为此这里在为它添加了一种LCD屏的显示方式。
该显示屏采用SPI接口的工作发送,其显示分辨率为160*80像素点。
为驱动该显示屏,是使用图1所示的接口来连接显示屏。
图1 所用接口
其中:
SCL---GPIO2_2
DIN---GPIO2_3
RES---GPIO2_4
DC---GPIO2_5
CS---GPIO2_1
将这5个引脚设置为输出口且置为高电平输出的函数为:
为程序中输出高低电平的相应,特进行如下定义:
#define LCD__Set GPIO_WritePin(GPIO2, GPIO_PIN_02, SET) //CLK
#define LCD_SCLK_Clr GPIO_WritePin(GPIO2, GPIO_PIN_02, RESET)
#define LCD_SDIN_Set GPIO_WritePin(GPIO2, GPIO_PIN_03, SET) //DIN
#define LCD_SDIN_Clr GPIO_WritePin(GPIO2, GPIO_PIN_03, RESET)
#define LCD_RST_Set GPIO_WritePin(GPIO2, GPIO_PIN_04, SET) //RES
#define LCD_RST_Clr GPIO_WritePin(GPIO2, GPIO_PIN_04, RESET)
#define LCD_DC_Set GPIO_WritePin(GPIO2, GPIO_PIN_05, SET) //DC
#define LCD_DC_Clr GPIO_WritePin(GPIO2, GPIO_PIN_05, RESET)
#define LCD_CS_Set GPIO_WritePin(GPIO2, GPIO_PIN_01, SET) //CS
#define LCD_CS_Clr GPIO_WritePin(GPIO2, GPIO_PIN_01, RESET)
该LCD屏的初始化函数为:
static void Lcd_Init(void)
{
LCD_RST_Clr;
Delay(0x2FFFFF);
LCD_RST_Set;
Delay(0x2FFFFF);
LCD_WR_REG(0x11);
Delay(0x1FFFFF);
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);
}
该显示屏的清屏函数为:
static 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);
}
}
}
在添加字库的情况下,该显示屏的字符串显示函数为:
static 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,1,color);
x+=8;
p++;
}
}
该显示屏显示字符串的主程序为:
int main(void)
{
EVB_LEDInit();
Lcd_Init();
LCD_Clear(RED);
LCD_ShowString(10,10,"ETEB-6001DPX",YELLOW);
LCD_ShowString(10,30,"jinglixixi",YELLOW);
while (1)
{
Delay(0x5FFFFF);
LCD_Clear(YELLOW);
Delay(0x5FFFFF);
LCD_Clear(BLUE);
Delay(0x5FFFFF);
LCD_Clear(GREEN);
Delay(0x5FFFFF);
LCD_Clear(MAGENTA);
}
}
经程序的编译与运行,其显示结果如图2至图4所示,说明显示功能正常。
图2 显示紫色
图3 显示绿色
图4 显示字符串
后续在添加数值显示功能的情况下,可与A/D数据采集功能相结合来实现温度检测功能。
视频:
VID_20241025_120511
|