【AT32WB415测评】TFT屏的显示驱动
<div class='showpostmsg'><p>在显示器件中有多种类型,其中以TFT屏较适于做图片显示。</p><p style="">这里选用的是一款基于ILI9341的2.2寸TFT屏,其分辨率为240x320像素点,并以SPI方式工作。</p>
<p style="">为实现下图所示的显示效果,其引脚与开发板的连接如下:</p>
<p style="">BLK-------PA5</p>
<p style="">SCL-------PA0</p>
<p style="">SDA-------PA1</p>
<p style="">DC--------PA3</p>
<p style="">RESET-----PA2</p>
<p style="">CS--------PA4</p>
<p style=""> </p>
<p style="">使用GPIO口来模拟SPI方式工作,其输出高低电平的引脚为:</p>
<p style="">#define LCD_SCK_Low() GPIOA->clr = GPIO_PINS_0</p>
<p style="">#define LCD_SCK_High() GPIOA->scr = GPIO_PINS_0</p>
<p style="">#define LCD_SDI_Low() GPIOA->clr = GPIO_PINS_1</p>
<p style="">#define LCD_SDI_High() GPIOA->scr = GPIO_PINS_1</p>
<p style="">#define LCD_REST_Low() GPIOA->clr = GPIO_PINS_2</p>
<p style="">#define LCD_REST_High() GPIOA->scr = GPIO_PINS_2</p>
<p style="">#define LCD_DC_Low() GPIOA->clr = GPIO_PINS_3</p>
<p style="">#define LCD_DC_High() GPIOA->scr = GPIO_PINS_3</p>
<p style="">#define LCD_CS_Low() GPIOA->clr = GPIO_PINS_4</p>
<p style="">#define LCD_CS_High() GPIOA->scr = GPIO_PINS_4</p>
<p style="">#define LCD_LED_Low() GPIOA->clr = GPIO_PINS_5</p>
<p style="">#define LCD_LED_High() GPIOA->scr = GPIO_PINS_5</p>
<p style="">配置相关引脚的函数为:</p>
<pre>
<code class="language-cpp">void app_tft_init(void)
{
gpio_init_type gpio_init_struct;
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
gpio_default_para_init(&gpio_init_struct);
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_PINS_3|GPIO_PINS_4|GPIO_PINS_5;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct);
LCD_LED_High();
}</code></pre>
<p style="">模拟SPI方式方式字节数据的函数如下:</p>
<pre>
<code class="language-cpp">void LCD_Writ_Bus(unsigned char com)
{
unsigned char uci;
for(uci=0;uci<8;uci++)
{
if(com & 0x80)
{
LCD_SDI_High();
}
else
{
LCD_SDI_Low();
}
com = com << 1;
LCD_SCK_Low();
delay_us(8);
LCD_SCK_High();
delay_us(8);
}
}</code></pre>
<p style="">实现以指定色彩擦除屏幕的函数为:</p>
<pre>
<code class="language-cpp">void LCD_Clear(unsigned int Color)
{
char VH,VL;
unsigned int i,j;
VH=Color>>8;
VL=Color;
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_DATA8(VH);
LCD_WR_DATA8(VL);
}
}
}</code></pre>
<p style="">以屏幕擦除函数为基础,实现50*50像素点图标显示的函数为:</p>
<pre>
<code class="language-cpp">void show_tb(unsigned int x,unsigned int y,unsigned int n)
{
unsigned int i,j,k;
unsigned int da;
k=0;
for(i=0;i<50;i++)
{
for(j=0;j<50;j++)
{
if(n==0) da=gImage_tb;
da<<=8;
if(n==0) da|=gImage_tb;
POINT_COLOR=da;
LCD_DrawPoint(x-j,y+i);
k++;
}
}
}</code></pre>
<p style="">在配合汉字显示功能的情况下,实现图示效果的主程序为:</p>
<pre>
<code class="language-cpp">int main(void)
{
system_clock_config();
at32_board_init();
app_tft_init();
tft_Init();
LCD_Clear(RED);
LCD_Fill(0,0,239,50,WHITE);
show_tb(60,0,0);
delay_ms(1000);
BACK_COLOR=WHITE;
POINT_COLOR=RED;
LCD_ShowChar(80,16,'M',1);
LCD_ShowChar(90,16,'P',1);
LCD_ShowChar(100,16,'3',1);
showhanzi16(115,16,32);
showhanzi16(135,16,33);
showhanzi16(155,16,34);
showhanzi16(175,16,35);
showhanzi16(195,16,36);
BACK_COLOR=RED;
POINT_COLOR=YELLOW;
showhanzi16(60,75,0);
showhanzi16(80,75,1);
showhanzi16(100,75,2);
showhanzi16(30,75,37);
showhanzi16(60,105,3);
showhanzi16(80,105,4);
showhanzi16(100,105,5);
showhanzi16(120,105,6);
showhanzi16(60,135,7);
showhanzi16(80,135,8);
showhanzi16(60,165,9);
showhanzi16(80,165,10);
showhanzi16(60,195,11);
showhanzi16(80,195,12);
showhanzi16(100,195,13);
showhanzi16(120,195,14);
showhanzi16(60,225,15);
showhanzi16(80,225,16);
showhanzi16(100,225,17);
showhanzi16(120,225,18);
showhanzi16(140,225,19);
showhanzi16(60,255,20);
showhanzi16(80,255,21);
showhanzi16(100,255,22);
showhanzi16(120,255,23);
showhanzi16(140,255,24);
showhanzi16(160,255,25);
showhanzi16(180,255,26);
LCD_Fill(0,287,239,319,WHITE);
BACK_COLOR=WHITE;
POINT_COLOR=RED;
LCD_ShowString(60,294,"BY: jinglixixi");
while(1)
{
at32_led_toggle(LED2);
delay_ms(200);
at32_led_toggle(LED3);
delay_ms(200);
at32_led_toggle(LED4);
delay_ms(200);
}
}</code></pre>
<p>有了TFT屏显示图片的功能,就为后续的打下了一个基础。</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>大佬的帖子都是非常的给力,谢谢分享。</p>
lugl4313820 发表于 2022-8-5 20:29
大佬的帖子都是非常的给力,谢谢分享。
<p>感谢支持!!!</p>
页:
[1]