【沁恒 CH32V208 开发板免费试用】+SPI_LCD - RISC-V MCU技术社区 - 电子技术论坛 - 广受欢迎的专业电子论坛
分享 收藏 返回

574246365 关注 私信
[文章]

【沁恒 CH32V208 开发板免费试用】+SPI_LCD

【沁恒 CH32V208 开发板免费试用】+SPI_LCD

上一篇测评报告为开箱检测,本片主要测评SPI_LCD,查看其他网友的报告时也有类似的测评,是针对模拟SPI来测试的。我这里呢是基于硬件SPI进行移植测试。

  1. 硬件资源介绍

主控还是CH32V208开发板,下载仿真用WCH-LINK-R1就不多介绍了。

LCD模块采用4线制SPI通讯方式,驱动IC为ILI9341,分辨率为240*320。

1682526486138b2bp6jmodt

1682526486881wis0l0w9x9

本次实验引脚对应为:

1682526487647p5reor2e52

  1. 驱动部分

以下是实物连接图

c68f74d5db64814977071059d2cc415

接线方式参考实验引脚对应部分

  1. 项目结构:

1682526488330se4gj33l4q

主要移植了SPI,LCD,GUI等驱动

  1. SPI驱动:

u8 SPI1_ReadWriteByte (u8 TxData)//SPI读写


{

u8 i = 0;
__while__\\(SPI\\_I2S\\_GetFlagStatus\\(SPI1, SPI\\_I2S\\_FLAG\\_TXE\\) == *RESET*\\)
\\{
i\\+\\+;
__if__\\(i > 200\\)
__return__ 0;
\\}

SPI\\_I2S\\_SendData\\(SPI1, TxData\\);
i = 0;
__while__\\(SPI\\_I2S\\_GetFlagStatus\\(SPI1, SPI\\_I2S\\_FLAG\\_RXNE\\) == *RESET*\\)

\\{

i\\+\\+;
__if__\\(i > 200\\)
__return__ 0;
\\}
__return__ SPI\\_I2S\\_ReceiveData\\(SPI1\\);
}

**void**  **SPI1_Init** ( **void** )
{
GPIO\\_InitTypeDef GPIO\\_InitStructure=\\{0\\};
SPI\\_InitTypeDef SPI\\_InitStructure=\\{0\\};
RCC\\_APB2PeriphClockCmd\\( RCC\\_APB2Periph\\_GPIOA | RCC\\_APB2Periph\\_SPI1, *ENABLE* \\);
GPIO\\_InitStructure\\.GPIO\\_Pin = GPIO\\_Pin\\_5;
GPIO\\_InitStructure\\.GPIO\\_Mode = *GPIO\\_Mode\\_AF\\_PP*;
GPIO\\_InitStructure\\.GPIO\\_Speed = *GPIO\\_Speed\\_50MHz*;
GPIO\\_Init\\( GPIOA, &GPIO\\_InitStructure \\);
GPIO\\_InitStructure\\.GPIO\\_Pin = GPIO\\_Pin\\_6;
GPIO\\_InitStructure\\.GPIO\\_Mode = *GPIO\\_Mode\\_IN\\_FLOATING*;
GPIO\\_Init\\( GPIOA, &GPIO\\_InitStructure \\);
GPIO\\_InitStructure\\.GPIO\\_Pin = GPIO\\_Pin\\_7;
GPIO\\_InitStructure\\.GPIO\\_Mode = *GPIO\\_Mode\\_AF\\_PP*;
GPIO\\_InitStructure\\.GPIO\\_Speed = *GPIO\\_Speed\\_50MHz*;
GPIO\\_Init\\( GPIOA, &GPIO\\_InitStructure \\);
SPI\\_InitStructure\\.SPI\\_Direction = SPI\\_Direction\\_2Lines\\_FullDuplex;
SPI\\_InitStructure\\.SPI\\_Mode = SPI\\_Mode\\_Master;
SPI\\_InitStructure\\.SPI\\_DataSize = SPI\\_DataSize\\_8b;
SPI\\_InitStructure\\.SPI\\_CPOL = SPI\\_CPOL\\_Low;
SPI\\_InitStructure\\.SPI\\_CPHA = SPI\\_CPHA\\_1Edge;
SPI\\_InitStructure\\.SPI\\_NSS = SPI\\_NSS\\_Soft;
SPI\\_InitStructure\\.SPI\\_BaudRatePrescaler = SPI\\_BaudRatePrescaler\\_2;
SPI\\_InitStructure\\.SPI\\_FirstBit = SPI\\_FirstBit\\_MSB;
SPI\\_InitStructure\\.SPI\\_CRCPolynomial = 7;
SPI\\_Init\\( SPI1, &SPI\\_InitStructure \\);
SPI\\_Cmd\\( SPI1, *ENABLE* \\);
}

  1. LCD驱动:

void LCD_WR_REG(u8 data)

{
LCD_CS_CLR;
LCD\\_RS\\_CLR;
SPI1_ReadWriteByte(data);
LCD_CS_SET;
}

void LCD_WR_DATA(u8 data)
{
LCD_CS_CLR;
LCD\\_RS\\_SET;

SPI1_ReadWriteByte(data);

LCD_CS_SET;

}

void LCD_Clear(u16 Color)

{

unsigned int i,m;
LCD\\_SetWindows\\(0,0,lcddev\\.width\\-1,lcddev\\.height\\-1\\);
LCD\\_CS\\_CLR;
LCD\\_RS\\_SET;
for\\(i=0;i<lcddev\\.height;i\\+\\+\\)
\\{
for\\(m=0;m<lcddev\\.width;m\\+\\+\\)
\\{
Lcd\\_WriteData\\_16Bit\\(Color\\);
\\}

\\}

LCD\\_CS\\_SET;

}

void LCD_GPIOInit(void)

{
GPIO\\_InitTypeDef  GPIO\\_InitStructure;
RCC\\_APB2PeriphClockCmd\\( RCC\\_APB2Periph\\_GPIOA ,ENABLE\\);	//使能GPIOB时钟
GPIO\\_InitStructure\\.GPIO\\_Pin = GPIO\\_Pin\\_1|GPIO\\_Pin\\_0|GPIO\\_Pin\\_2| GPIO\\_Pin\\_3| GPIO\\_Pin\\_4; //GPIOA2,3,4,5
GPIO\\_InitStructure\\.GPIO\\_Speed = GPIO\\_Speed\\_50MHz;
GPIO\\_InitStructure\\.GPIO\\_Mode = GPIO\\_Mode\\_Out\\_PP;   //推挽输出
GPIO\\_Init\\(GPIOA, &GPIO\\_InitStructure\\);//初始化
}

void LCD_RESET(void)

{
LCD\\_RST\\_CLR;
Delay\\_Ms\\(100\\);
LCD\\_RST\\_SET;
Delay\\_Ms\\(50\\);

}

**void**  **LCD_Init** ( **void** )

{
SPI1\\_Init\\(\\); //硬件SPI1初始化
LCD\\_GPIOInit\\(\\);//LCD GPIO初始化
LCD\\_RESET\\(\\); //LCD 复位

//*************2.8inch ILI9341初始化**********//
LCD\\_WR\\_REG\\(0xCF\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0xC9\\); //C1
LCD\\_WR\\_DATA\\(0X30\\);
LCD\\_WR\\_REG\\(0xED\\);
LCD\\_WR\\_DATA\\(0x64\\);
LCD\\_WR\\_DATA\\(0x03\\);
LCD\\_WR\\_DATA\\(0X12\\);
LCD\\_WR\\_DATA\\(0X81\\);
LCD\\_WR\\_REG\\(0xE8\\);
LCD\\_WR\\_DATA\\(0x85\\);
LCD\\_WR\\_DATA\\(0x10\\);
LCD\\_WR\\_DATA\\(0x7A\\);
LCD\\_WR\\_REG\\(0xCB\\);
LCD\\_WR\\_DATA\\(0x39\\);
LCD\\_WR\\_DATA\\(0x2C\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x34\\);
LCD\\_WR\\_DATA\\(0x02\\);
LCD\\_WR\\_REG\\(0xF7\\);
LCD\\_WR\\_DATA\\(0x20\\);
LCD\\_WR\\_REG\\(0xEA\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_REG\\(0xC0\\);    //Power control
LCD\\_WR\\_DATA\\(0x1B\\);   //VRH\\[5:0\\]
LCD\\_WR\\_REG\\(0xC1\\);    //Power control
LCD\\_WR\\_DATA\\(0x00\\);   //SAP\\[2:0\\];BT\\[3:0\\] 01
LCD\\_WR\\_REG\\(0xC5\\);    //VCM control
LCD\\_WR\\_DATA\\(0x30\\); 	 //3F
LCD\\_WR\\_DATA\\(0x30\\); 	 //3C
LCD\\_WR\\_REG\\(0xC7\\);    //VCM control2
LCD\\_WR\\_DATA\\(0XB7\\);
LCD\\_WR\\_REG\\(0x36\\);    // Memory Access Control
LCD\\_WR\\_DATA\\(0x08\\);
LCD\\_WR\\_REG\\(0x3A\\);
LCD\\_WR\\_DATA\\(0x55\\);
LCD\\_WR\\_REG\\(0xB1\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x1A\\);
LCD\\_WR\\_REG\\(0xB6\\);    // Display Function Control
LCD\\_WR\\_DATA\\(0x0A\\);
LCD\\_WR\\_DATA\\(0xA2\\);
LCD\\_WR\\_REG\\(0xF2\\);    // 3Gamma Function Disable
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_REG\\(0x26\\);    //Gamma curve selected
LCD\\_WR\\_DATA\\(0x01\\);
LCD\\_WR\\_REG\\(0xE0\\);    //Set Gamma
LCD\\_WR\\_DATA\\(0x0F\\);
LCD\\_WR\\_DATA\\(0x2A\\);
LCD\\_WR\\_DATA\\(0x28\\);
LCD\\_WR\\_DATA\\(0x08\\);
LCD\\_WR\\_DATA\\(0x0E\\);
LCD\\_WR\\_DATA\\(0x08\\);
LCD\\_WR\\_DATA\\(0x54\\);
LCD\\_WR\\_DATA\\(0XA9\\);
LCD\\_WR\\_DATA\\(0x43\\);
LCD\\_WR\\_DATA\\(0x0A\\);
LCD\\_WR\\_DATA\\(0x0F\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_REG\\(0XE1\\);    //Set Gamma
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x15\\);
LCD\\_WR\\_DATA\\(0x17\\);
LCD\\_WR\\_DATA\\(0x07\\);
LCD\\_WR\\_DATA\\(0x11\\);
LCD\\_WR\\_DATA\\(0x06\\);
LCD\\_WR\\_DATA\\(0x2B\\);
LCD\\_WR\\_DATA\\(0x56\\);
LCD\\_WR\\_DATA\\(0x3C\\);
LCD\\_WR\\_DATA\\(0x05\\);
LCD\\_WR\\_DATA\\(0x10\\);
LCD\\_WR\\_DATA\\(0x0F\\);
LCD\\_WR\\_DATA\\(0x3F\\);
LCD\\_WR\\_DATA\\(0x3F\\);
LCD\\_WR\\_DATA\\(0x0F\\);
LCD\\_WR\\_REG\\(0x2B\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x01\\);
LCD\\_WR\\_DATA\\(0x3f\\);
LCD\\_WR\\_REG\\(0x2A\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0x00\\);
LCD\\_WR\\_DATA\\(0xef\\);
LCD\\_WR\\_REG\\(0x11\\); //Exit Sleep
Delay\\_Ms\\(120\\);
LCD\\_WR\\_REG\\(0x29\\); //display on
LCD_direction(USE_HORIZONTAL);//设置LCD显示方向
LCD_LED_SET;//点亮背光
LCD\\_Clear\\(WHITE\\);//清全屏白色

}

  1. 项目实验:
**int**  **main** ( **void** )

{

u8 i=0;
u8 j=0;
u8 value;
Delay\\_Init\\(\\);
USART\\_Printf\\_Init\\(115200\\);
__printf__\\("SystemClk:%d\\\\r\\\\n",SystemCoreClock\\);
LCD\\_Init\\(\\);
LCD\\_LED\\_SET;
Delay\\_Ms\\(1500\\);
LCD\\_LED\\_CLR;
__while__\\(1\\)
\\{

DrawTestPage\\("CH32V208\\_LCD\\_DEMO"\\);
if(1s_task_sta == 1)
{
DIS_flow();//主要显示流量信息等
Led();//LED闪烁
}
\\}
}

aeedba500a3222e8df90e846d4329f2

  1. 结束

此次硬件SPI测试结束,下次对RTT或网络进行测试。

  1. 附件

*附件:SPI-2Lines_FullDuplex - lcd.zip

更多回帖

×
发帖