图2显示效果
CLK ---PB0
DIN ---PB1
DC ---PB2
RST ---PB3
CS ---PB4
为驱动的方便,这里仍使用GPIO口来模拟SPI接口来实现,其输出高低电平的语句定义为:
#define LCD_CLK_L GPIO_Write(GPIOB,PIN0,GPIO_RESET)
#define LCD_CLK_H GPIO_Write(GPIOB,PIN0,GPIO_SET)
#define LCD_DIN_L GPIO_Write(GPIOB,PIN1,GPIO_RESET)
#define LCD_DIN_H GPIO_Write(GPIOB,PIN1,GPIO_SET)
#define LCD_DC_L GPIO_Write(GPIOB,PIN2,GPIO_RESET)
#define LCD_DC_H GPIO_Write(GPIOB,PIN2,GPIO_SET)
#define LCD_RST_L GPIO_Write(GPIOB,PIN3,GPIO_RESET)
#define LCD_RST_H GPIO_Write(GPIOB,PIN3,GPIO_SET)
#define LCD_CS_L GPIO_Write(GPIOB,PIN4,GPIO_RESET)
#define LCD_CS_H GPIO_Write(GPIOB,PIN4,GPIO_SET)
对LCD5110的初始化函数为:
-
void LCD5110_Init(void)
-
{
-
Delay32M_ms(800);
-
LCD_reset_hard;
-
LCD_write_cmd(0x21);
-
LCD_write_cmd(0x06);
-
LCD_write_cmd(0x13);
-
LCD_write_cmd(0xc8);
-
LCD_write_cmd(0x20);
-
LCD_write_cmd(0x0c);
-
LCD_write_cmd(Y_Page_Addr);
-
LCD_write_cmd(X_Col_Addr);
-
LCD_clr_scr();
-
}
复制代码
实现字节数据发送的函数为:
-
void LCD_write_byte(unsigned char wbyte, unsigned char dat_cmd)
-
{
-
unsigned char i;
-
LCD_CS_L;
-
if(dat_cmd)
-
{
-
LCD_DC_H;
-
}
-
else
-
{
-
LCD_DC_L;
-
}
-
for(i = 8; i; i--)
-
{
-
if(wbyte & 0x80)
-
{
-
LCD_DIN_H;
-
}
-
else
-
{
-
LCD_DIN_L;
-
}
-
Delay_us(2);
-
LCD_CLK_L;
-
wbyte <<= 1;
-
Delay_us(2);
-
LCD_CLK_H;
-
}
-
LCD_CS_H;
-
}
复制代码
清除显示屏的函数为:
-
void LCD_clr_scr(void)
-
{
-
unsigned int i;
-
LCD_write_cmd(X_Col_Addr);
-
LCD_write_cmd(Y_Page_Addr);
-
for(i = 504; i; i--) LCD_write_dat(0x00);
-
}
复制代码
实现图示效果的主程序为:
-
int main(void)
-
{
-
int16_t i;
-
CLIC_Init();
-
System_Clock_Init();
-
GPIO_MODE_Init(GPIOB,PIN0,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOB,PIN1,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOB,PIN2,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOB,PIN3,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOB,PIN4,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOA,PIN8,GPIO_MODE_OUTPUT);
-
GPIO_Write(GPIOA,PIN8,GPIO_SET);
-
LCD5110_Init();
-
LCD_prints(0,0,"CSM32RV20");
-
LCD_prints(0,1,"LCD5110 ");
-
LCD_prints(0,2,"jinglixixi");
-
while(1)
-
{
-
GPIO_Toggle(GPIOA,PIN8);
-
for(i=0;i<10;i++)
-
{
-
Delay32M_us(50000);
-
}
-
}
-
}
复制代码
对于另一款0.96寸的彩色LCD屏,它也是使用SPI接口工作。相较于LCD5110显示屏,该显示屏可以显示彩色的图片。
该显示屏的初始化函数为:
-
void OLED_Init(void)
-
{
-
OLED_SCLK_Set();
-
OLED_SDIN_Set();
-
Delay32M_ms(800);
-
OLED_WR_Byte(0xAE,OLED_CMD);
-
OLED_WR_Byte(0x02,OLED_CMD);
-
OLED_WR_Byte(0x10,OLED_CMD);
-
OLED_WR_Byte(0x40,OLED_CMD);
-
OLED_WR_Byte(0x81,OLED_CMD);
-
OLED_WR_Byte(0xff,OLED_CMD);
-
OLED_WR_Byte(0xA1,OLED_CMD);
-
OLED_WR_Byte(0xC8,OLED_CMD);
-
OLED_WR_Byte(0xA6,OLED_CMD);
-
OLED_WR_Byte(0xA8,OLED_CMD);
-
OLED_WR_Byte(0x3f,OLED_CMD);
-
OLED_WR_Byte(0xD3,OLED_CMD);
-
OLED_WR_Byte(0x00,OLED_CMD);
-
OLED_WR_Byte(0xd5,OLED_CMD);
-
OLED_WR_Byte(0x80,OLED_CMD);
-
OLED_WR_Byte(0xD9,OLED_CMD);
-
OLED_WR_Byte(0xF1,OLED_CMD);
-
OLED_WR_Byte(0xDA,OLED_CMD);
-
OLED_WR_Byte(0x12,OLED_CMD);
-
OLED_WR_Byte(0xDB,OLED_CMD);
-
OLED_WR_Byte(0x40,OLED_CMD);
-
OLED_WR_Byte(0x20,OLED_CMD);
-
OLED_WR_Byte(0x02,OLED_CMD);
-
OLED_WR_Byte(0x8D,OLED_CMD);
-
OLED_WR_Byte(0x14,OLED_CMD);
-
OLED_WR_Byte(0xA4,OLED_CMD);
-
OLED_WR_Byte(0xA6,OLED_CMD);
-
OLED_WR_Byte(0xAF,OLED_CMD);
-
OLED_WR_Byte(0xAF,OLED_CMD);
-
}
复制代码
其图片显示函数为:
-
void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
-
{
-
unsigned int j=0;
-
unsigned char x,y;
-
if(y1%8==0) y=y1/8;
-
else y=y1/8+1;
-
for(y=y0;y;y++)
-
{
-
OLED_Set_Pos(x0,y);
-
for(x=x0;x;x++)
-
{
-
OLED_WR_Byte(BMP[j++],OLED_DATA);
-
}
-
}
-
}
复制代码
相应的显示主程序为:
-
int main(void)
-
{
-
CLIC_Init();
-
System_Clock_Init();
-
GPIO_MODE_Init(GPIOB,PIN0,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOB,PIN1,GPIO_MODE_OUTPUT);
-
OLED_ShowString(20,0,"CSM32RV20",16);
-
OLED_ShowString(20,2,"OLED TEST",16);
-
Delay32M_ms(2000);
-
OLED_DrawBMP(0,0,128,8,BMP1);
-
while(1);
-
}
复制代码
经编译与下载,其显示效果如图3和图4所示。
图3显示字符串
图4显示图像
对于TFT显示屏,它相较于0.96寸LCD显示屏其显示尺寸要更大,故显示的内容也更多。
该显示屏的初始化函数为:
-
void LCD_Init(void)
-
{
-
LCD_REST_Low();
-
Delay32M_ms(20);
-
LCD_REST_High();
-
Delay32M_ms(20);
-
LCD_CS_Low();
-
LCD_WR_REG(0xCB);
-
LCD_WR_DATA8(0x39);
-
LCD_WR_DATA8(0x2C);
-
LCD_WR_DATA8(0x00);
-
LCD_WR_DATA8(0x34);
-
LCD_WR_DATA8(0x02);
-
LCD_WR_REG(0xCF);
-
LCD_WR_DATA8(0x00);
-
LCD_WR_DATA8(0XC1);
-
LCD_WR_DATA8(0X30);
-
LCD_WR_REG(0xE8);
-
LCD_WR_DATA8(0x85);
-
LCD_WR_DATA8(0x00);
-
LCD_WR_DATA8(0x78);
-
LCD_WR_REG(0xEA);
-
LCD_WR_DATA8(0x00);
-
LCD_WR_DATA8(0x00);
-
LCD_WR_REG(0xED);
-
LCD_WR_DATA8(0x64);
-
LCD_WR_DATA8(0x03);
-
LCD_WR_DATA8(0X12);
-
LCD_WR_DATA8(0X81);
-
LCD_WR_REG(0xF7);
-
LCD_WR_DATA8(0x20);
-
LCD_WR_REG(0xC0);
-
LCD_WR_DATA8(0x23);
-
LCD_WR_REG(0xC1);
-
LCD_WR_DATA8(0x10);
-
LCD_WR_REG(0xC5);
-
LCD_WR_DATA8(0x3e);
-
LCD_WR_DATA8(0x28);
-
LCD_WR_REG(0xC7);
-
LCD_WR_DATA8(0x86);
-
LCD_WR_REG(0x36);
-
LCD_WR_DATA8(0x48);
-
LCD_WR_REG(0x3A);
-
LCD_WR_DATA8(0x55);
-
LCD_WR_REG(0xB1);
-
LCD_WR_DATA8(0x00);
-
LCD_WR_DATA8(0x18);
-
LCD_WR_REG(0xB6);
-
LCD_WR_DATA8(0x08);
-
LCD_WR_DATA8(0x82);
-
LCD_WR_DATA8(0x27);
-
LCD_WR_REG(0xF2);
-
LCD_WR_DATA8(0x00);
-
LCD_WR_REG(0x26);
-
LCD_WR_DATA8(0x01);
-
LCD_WR_REG(0xE0);
-
LCD_WR_DATA8(0x0F);
-
LCD_WR_DATA8(0x31);
-
LCD_WR_DATA8(0x2B);
-
LCD_WR_DATA8(0x0C);
-
LCD_WR_DATA8(0x0E);
-
LCD_WR_DATA8(0x08);
-
LCD_WR_DATA8(0x4E);
-
LCD_WR_DATA8(0xF1);
-
LCD_WR_DATA8(0x37);
-
LCD_WR_DATA8(0x07);
-
LCD_WR_DATA8(0x10);
-
LCD_WR_DATA8(0x03);
-
LCD_WR_DATA8(0x0E);
-
LCD_WR_DATA8(0x09);
-
LCD_WR_DATA8(0x00);
-
LCD_WR_REG(0XE1);
-
LCD_WR_DATA8(0x00);
-
LCD_WR_DATA8(0x0E);
-
LCD_WR_DATA8(0x14);
-
LCD_WR_DATA8(0x03);
-
LCD_WR_DATA8(0x11);
-
LCD_WR_DATA8(0x07);
-
LCD_WR_DATA8(0x31);
-
LCD_WR_DATA8(0xC1);
-
LCD_WR_DATA8(0x48);
-
LCD_WR_DATA8(0x08);
-
LCD_WR_DATA8(0x0F);
-
LCD_WR_DATA8(0x0C);
-
LCD_WR_DATA8(0x31);
-
LCD_WR_DATA8(0x36);
-
LCD_WR_DATA8(0x0F);
-
LCD_WR_REG(0x11);
-
Delay32M_ms(120);
-
LCD_WR_REG(0x29);
-
LCD_WR_REG(0x2c);
-
}
复制代码
其字符界面显示函数为:
-
void xianshi()
-
{
-
LCD_Clear(RED);
-
BACK_COLOR=RED;
-
POINT_COLOR=WHITE;
-
LCD_ShowString(20,80,160,16,16,"CSM32RV20");
-
LCD_ShowString(20,120,200,16,16,"2.4 SPI_TFT 240*320");
-
LCD_ShowString(20,240,160,16,16,"jinglxixi ");
-
LCD_ShowString(20,280,200,16,16,"2022.1.16 ");
-
}
复制代码
相应的图片显示函数为:
-
void show_image(void)
-
{
-
int i,j,k;
-
unsigned char picH,picL;
-
Address_set(0,0,79,79);
-
k=0;
-
for(i=0;i<80;i++)
-
{
-
for(j=0;j<80;j++)
-
{
-
picH=gImage_cgq[k*2];
-
picL=gImage_cgq[k*2+1];
-
LCD_WR_DATA8(picH);
-
LCD_WR_DATA8(picL);
-
k++;
-
}
-
}
-
}
复制代码
实现显示效果的主程序为:
-
int main(void)
-
{
-
int16_t i;
-
CLIC_Init();
-
System_Clock_Init();
-
GPIO_MODE_Init(GPIOB,PIN0,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOB,PIN1,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOB,PIN2,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOB,PIN3,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOB,PIN4,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOA,PIN8,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOA,PIN10,GPIO_MODE_OUTPUT);
-
GPIO_MODE_Init(GPIOA,PIN12,GPIO_MODE_OUTPUT);
-
GPIO_Write(GPIOB,PIN0,GPIO_SET);
-
GPIO_Write(GPIOB,PIN1,GPIO_SET);
-
GPIO_Write(GPIOA,PIN8,GPIO_SET);
-
GPIO_Write(GPIOA,PIN10,GPIO_SET);
-
GPIO_Write(GPIOA,PIN12,GPIO_SET);
-
LCD_Init();
-
LCD_Clear(RED);
-
xianshi();
-
Delay32M_ms(2000);
-
LCD_Clear(BLACK);
-
show_image();
-
while(1)
-
{
-
GPIO_Toggle(GPIOA,PIN8);
-
for(i=0;i<10;i++)
-
{
-
Delay32M_us(50000);
-
}
-
}
-
return 0;
-
}
复制代码
经编译与下载,其显示效果如图5和图6所示。
图5显示字符串
图6显示字符串