【AT-START-F425测评】+软硬件SPI驱动(ST7735)1.8吋TFT LCD
<p><font size="5"><font style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial">1、硬件连接</font></font><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" /><span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">GND GND</span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">3.3V VCC </span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">PA5 SCL</span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">PA7 SDA</span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">PB0 ERS(复位)</span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">PB1 DC(命令数据选择)</span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">PA4 CS(片选) </span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">PB2 BL(背光) </span></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<font size="5"><font style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial">2、字库取摸方式</font></font><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">取模方式:阴码、逆向、列行式</span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">使用PCtoLCD2002软件取摸。</span></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p> </p>
<p><font size="5"><font style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial">3、图片取摸</font></font><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">水平扫描,16位真彩色 </span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">使用Image2Lcd取摸</span></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p></p>
<p> <font size="5"><font style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial">4、代码实现</font></font><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">(1)IO以及SPI初始化</span></span></span></span></span></span></span></span></span></span></span></span></span><br style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-size:16px; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial" />
<span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">代码兼容软件SPI和硬件SPI两种方式,通过宏</span></span></span></span></span></span></span></span></span></span></span></span></span><font size="4"><font style="overflow-wrap:break-word; word-break:break-all; color:#444444; font-family:Tahoma, "Microsoft Yahei", Simsun; font-style:normal; font-variant-ligatures:normal; font-weight:400; text-align:start; white-space:normal; background-color:#f2f9fd; text-decoration-thickness:initial; text-decoration-style:initial; text-decoration-color:initial"><strong style="overflow-wrap:break-word; word-break:break-all; font-weight:700">SOFTWARE_SPI_ENABLE</strong></font></font><span style="font-size:16px; text-align:start"><span style="color:#444444"><span style="font-family:Tahoma, "Microsoft Yahei", Simsun"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-weight:400"><span style="white-space:normal"><span style="background-color:#f2f9fd"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">选择。</span></span></span></span></span></span></span></span></span></span></span></span></span></p>
<pre>
<code class="language-cpp">void LcdIoInit(void)
{
gpio_init_type gpio_init_struct;
/* enable the led clock */
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
/* set default parameter */
gpio_default_para_init(&gpio_init_struct);
#if SOFTWARE_SPI_ENABLE
/* configure the led gpio */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type= GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_4|GPIO_PINS_5|GPIO_PINS_7;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct);
gpio_bits_set(GPIOA,GPIO_PINS_4|GPIO_PINS_5|GPIO_PINS_7);
#else
/*SPI1 :
PA4/CS
PA5/SCK
PA6/MISO
PA7/MOSI
*/
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_UP;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_pins = GPIO_PINS_4;
gpio_init(GPIOA, &gpio_init_struct);
gpio_bits_set(GPIOA,GPIO_PINS_4);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE5, GPIO_MUX_0);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE6, GPIO_MUX_0);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE7, GPIO_MUX_0);
gpio_default_para_init(&gpio_init_struct);
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_DOWN;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_pins = GPIO_PINS_5;
gpio_init(GPIOA, &gpio_init_struct);
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_UP;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_pins = GPIO_PINS_6;
gpio_init(GPIOA, &gpio_init_struct);
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_UP;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_pins = GPIO_PINS_7;
gpio_init(GPIOA, &gpio_init_struct);
spi_init_type spi_init_struct;
crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);
spi_default_para_init(&spi_init_struct);
spi_init_struct.transmission_mode = SPI_TRANSMIT_HALF_DUPLEX_TX;
spi_init_struct.master_slave_mode = SPI_MODE_MASTER;
spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_2;
spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;
spi_init_struct.frame_bit_num = SPI_FRAME_8BIT;
spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_HIGH;//SPI_CLOCK_POLARITY_HIGH
spi_init_struct.clock_phase = SPI_CLOCK_PHASE_2EDGE; //SPI_CLOCK_PHASE_2EDGE
spi_init_struct.cs_mode_selection = SPI_CS_SOFTWARE_MODE;
spi_init(SPI1, &spi_init_struct);
spi_enable(SPI1, TRUE);
#endif
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type= GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_0|GPIO_PINS_1|GPIO_PINS_2;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
gpio_bits_set(GPIOB,GPIO_PINS_0|GPIO_PINS_1|GPIO_PINS_2);
}</code></pre>
<p>(2)SPI写数据</p>
<pre>
<code class="language-cpp">void LCD_Writ_Bus(u8 dat)
{
LCD_CS_LOW();
#if SOFTWARE_SPI_ENABLE
u8 i;
for(i=0;i<8;i++)
{
LCD_SCLK_LOW();
if(dat&0x80)
{
LCD_MOSI_HIGH();
}
else
{
LCD_MOSI_LOW();
}
LCD_SCLK_HIGH();
dat<<=1;
}
#else
spi_i2s_data_transmit(SPI1, dat);
while(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) == RESET) {};
#endif
LCD_CS_HIGH();
}</code></pre>
<p>(3)测试代码</p>
<pre>
<code>void LcdTest(void)
{
LcdInit();//LCD初始化
LcdFill(0,0,LCD_W,LCD_H,BLACK);
LcdShow16x16Hz(40, 0, 4, YELLOW, BLACK);
LcdShow16x16Hz(56, 0, 5, YELLOW, BLACK);
LcdShow16x16Hz(72, 0, 6, YELLOW, BLACK);
LcdShowString(32,24,"AT32F425",BLUE, BLACK,16);
LcdShowImage (14,60, 100, 93, gImage_zan);
}</code></pre>
<p><span style="font-size:26px;">5、现象</span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>这个彩屏不错,屏幕显示应该有相应的库吧?</p>
<p> </p>
wangerxian 发表于 2022-5-23 18:52
这个彩屏不错,屏幕显示应该有相应的库吧?
<p>spi部分与具体的mcu有关,其他初始化流程之类的,参考厂家的就行</p>
页:
[1]