本次工程基于stm32vet5,LCD是ili9341,在LCD的基础驱动上改编的代码。
工作中需要实现动态背景和动态字体。直接用截图来覆盖原有的图需要flash中保存截图,占用太大空间,所以需要尽可以的用软件来处理图片实现动态。我编写了实现透明图片,移动图片,嵌入图片,截图保存(flash中的)等函数来完成动态。这里带上视频和图片。
嵌入图片是去掉黑色部分,只显示其他颜色部分,即是把黑色当做了透明色。嵌入的图片最好是简单些的方便自己PS处理的图片。
视频: https://v.youku.com/v_show/id_XMzY0NzU3NjkzMg==.html
单片机源程序如下:
- /*
- * STM32F103VET6
- * 内置flash 512K 缓存 64K
- * 已用flash 347.34K 已用缓存 34.89K
- */
- #include "led.h"
- #include "delay.h"
- #include <stdbool.h>
- #include <math.h>
- #include "sys.h"
- #include "stm32f10x.h"
- #include "Tim.h"
- #include "usart.h"
- #include "ili9341_lcd.h"
- #include "string.h"
- //图像
- extern const unsigned char Street[153600] ;
- extern const unsigned char Smoke[12][6264];
- extern const unsigned char Ear[2][1972];
- extern const unsigned char Bread[12][2310];
- extern const unsigned char Ping[12][3696];
- extern const unsigned char Fire[3][1156];
- extern const unsigned char NUM[10][560];
- extern const unsigned char Change9_8[9][560];
- extern const unsigned char Change8_7[9][560];
- extern const unsigned char BIG_CHAR[8][720];
- extern const unsigned char CubicM[720];
- extern const unsigned char FenHao[320];
- extern const unsigned char BaiFenHao[720];
- extern const unsigned char UG[720];
- extern const unsigned char SheShiDu[720];
- unsigned char save[1120];
- u8 data_wei = 0;
-
- u8 lu_wei = 0;
- u8 turnarround = 0;
- //硬盘
- #define countof(a) (sizeof(a) / sizeof(*(a)))
- #define BufferSize (countof(Tx_Buffer)-1)
- uint32_t count_i = 0;
- uint32_t count_t;
- u8 count_k = 0;
- uint8_t Tx_Buffer[480] ;
- uint8_t Rx_Buffer[100];
- uint8_t Picture_Rx_Buffer[24000] ;//6分之一张图片大小
- //uint32_t Picture_F2D_Buffer[6000];//DMA从flash读取数据
- uint8_t Receive_Buffer; //串口接收图片数据的buff
- void LCD_Test(void)
- {
- LCD_SetColors(WHITE,BLACK );
- ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH);
- Disd(0,0, 240, 320,Street);
- }
- int main(void)
- {
- delay_init();
- ILI9341_Init (); //LCD屏幕初始化
- ILI9341_GramScan ( 6 ); //LCD背景色设置
- LCD_LightDegree();
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- USART_Config();
- LCD_Test(); //LCD初始化
-
- while(1) //浮动字体&动图&字体移动
- {
- int cnt = 0,cnt2;
- for(cnt = 11,cnt2 = 0;cnt >= 0;cnt2 ++,cnt --)
- {
- Disd(58,61, 54, 58,Smoke[cnt2]);
- if(cnt2 == 5)Disd(49,127, 34, 29,Ear[1]);
- else if(cnt2== 7)Disd(49,127, 34, 29,Ear[0]);
- else;//Ear
- Disd(86,157, 33, 35,Bread[cnt2]);
- Disd(152,121, 44, 42,Ping[cnt2]);
- if(cnt2 == 11)cnt2 = 0;
- //清理上次移动显示的残影
- ScreenShots( 30, 200, 18, 20,Street, 30, 200,240,320);
- ScreenShots( 48, 200, 18, 20,Street, 48, 200,240,320);
- ScreenShots( 68, 200, 18, 20,Street, 68, 200,240,320);
- // ScreenShots( 30, 230, 18, 20,Street, 30, 230,240,320);
- // ScreenShots( 48, 230, 18, 20,Street, 48, 230,240,320);
- // ScreenShots( 68, 230, 18, 20,Street, 68, 230,240,320);
-
- ScreenShotsSave( 18, 20,Street,30+10*cnt, 200,240,320,save);//截图保存
- ScreenShots( 40+10*cnt, 200, 18, 20,Street, 40+10*cnt, 200,240,320);
- FloatPictureStatic( 30+10*cnt,200, 18, 20,CHAR_T,cnt,save);
- ScreenShotsSave( 18, 20,Street,48+10*cnt, 200,240,320,save);//截图保存
- ScreenShots( 58+10*cnt, 200, 18, 20,Street, 58+10*cnt, 200,240,320);
- FloatPictureStatic( 48+10*cnt, 200, 18, 20,CHAR_E,cnt,save);
- ScreenShotsSave( 18, 20,Street,68+10*cnt, 200,240,320,save);//截图保存
- ScreenShots( 78+10*cnt, 200, 18, 20,Street, 78+10*cnt, 200,240,320);
- FloatPictureStatic( 68+10*cnt, 200, 18, 20,CHAR_M,cnt,save);
-
-
- // ScreenShotsSave( 18, 20,Street,30+10*cnt, 230,240,320,save);//截图保存
- // ScreenShots( 40+10*cnt, 230, 18, 20,Street, 40+10*cnt, 230,240,320);
- // FloatPictureStatic( 30+10*cnt,230, 18, 20,CHAR_H,cnt,save);
- // ScreenShotsSave( 18, 20,Street,48+10*cnt, 230,240,320,save);//截图保存
- // ScreenShots( 58+10*cnt, 230, 18, 20,Street, 58+10*cnt, 230,240,320);
- // FloatPictureStatic( 48+10*cnt, 230, 18, 20,CHAR_U,cnt,save);
- // ScreenShotsSave( 18, 20,Street,68+10*cnt, 230,240,320,save);//截图保存
- // ScreenShots( 78+10*cnt, 230, 18, 20,Street, 78+10*cnt, 230,240,320);
- // FloatPictureStatic( 68+10*cnt, 230, 18, 20,CHAR_M,cnt,save);
- ScreenShotsSave(18, 20,Street,30, 230,240,320,save);//截图保存
- FloatPictureStatic( 30,230, 18, 20,CHAR_H,cnt,save);
- ScreenShotsSave( 18, 20,Street,48, 230,240,320,save);//截图保存
- FloatPictureStatic( 48, 230, 18, 20,CHAR_U,cnt,save);
- ScreenShotsSave(18, 20,Street,68, 230,240,320,save);//截图保存
- FloatPictureStatic( 68, 230, 18, 20,CHAR_M,cnt,save);
-
- delay_ms(80);
- }
- for(cnt = 11,cnt2 = 0;cnt >= 0;cnt2 ++,cnt --)
- {
- Disd(58,61, 54, 58,Smoke[cnt2]);
- if(cnt2 == 5)Disd(49,127, 34, 29,Ear[1]);
- else if(cnt2 == 7)Disd(49,127, 34, 29,Ear[0]);
- else;//Ear
- Disd(86,157, 33, 35,Bread[cnt2]);
- Disd(152,121, 44, 42,Ping[cnt2]);
- if(cnt2 == 11)cnt2 = 0;
-
- ScreenShotsSave( 18, 20,Street,30, 200,240,320,save);//截图保存
- FloatPicture( 30,200, 18, 20,save,cnt);
- ScreenShotsSave( 18, 20,Street,48, 200,240,320,save);//截图保存
- FloatPicture( 48, 200, 18, 20,save,cnt);
- ScreenShotsSave( 18, 20,Street,68, 200,240,320,save);//截图保存
- FloatPicture( 68, 200, 18, 20,save,cnt);
-
- ScreenShotsSave( 18, 20,Street,30, 230,240,320,save);//截图保存
- FloatPicture( 30,230, 18, 20,save,cnt);
- ScreenShotsSave( 18, 20,Street,48, 230,240,320,save);//截图保存
- FloatPicture( 48, 230, 18, 20,save,cnt);
- ScreenShotsSave( 18, 20,Street,68, 230,240,320,save);//截图保存
- FloatPicture( 68, 230, 18, 20,save,cnt);
-
- delay_ms(80);
- }
- }
- while(1) //浮动字体&动图
- {
- int cnt = 0;
- for(cnt = 11;cnt >= 0;cnt --)
- {
- Disd(58,61, 54, 58,Smoke[cnt]);
- if(cnt == 5)Disd(49,127, 34, 29,Ear[1]);
- else if(cnt== 7)Disd(49,127, 34, 29,Ear[0]);
- else;//Ear
- Disd(86,157, 33, 35,Bread[cnt]);
- Disd(152,121, 44, 42,Ping[cnt]);
-
- ScreenShotsSave( 18, 20,Street,30, 200,240,320,save);//截图保存
- FloatPictureStatic( 30,200, 18, 20,CHAR_T,cnt,save);
- ScreenShotsSave(18, 20,Street,48, 200,240,320,save);//截图保存
- FloatPictureStatic( 48, 200, 18, 20,CHAR_E,cnt,save);
- ScreenShotsSave( 18, 20,Street,68, 200,240,320,save);//截图保存
- FloatPictureStatic( 68, 200, 18, 20,CHAR_M,cnt,save);
-
- ScreenShotsSave(18, 20,Street,30, 230,240,320,save);//截图保存
- FloatPictureStatic( 30,230, 18, 20,CHAR_H,cnt,save);
- ScreenShotsSave( 18, 20,Street,48, 230,240,320,save);//截图保存
- FloatPictureStatic( 48, 230, 18, 20,CHAR_U,cnt,save);
- ScreenShotsSave(18, 20,Street,68, 230,240,320,save);//截图保存
- FloatPictureStatic( 68, 230, 18, 20,CHAR_M,cnt,save);
-
- delay_ms(100);
- }
- for(cnt = 11;cnt >= 0;cnt --)
- {
- Disd(58,61, 54, 58,Smoke[cnt]);
- if(cnt == 5)Disd(49,127, 34, 29,Ear[1]);
- else if(cnt == 7)Disd(49,127, 34, 29,Ear[0]);
- else;//Ear
- Disd(86,157, 33, 35,Bread[cnt]);
- Disd(152,121, 44, 42,Ping[cnt]);
-
- ScreenShotsSave( 18, 20,Street,30, 200,240,320,save);//截图保存
- FloatPicture( 30,200, 18, 20,save,cnt);
- ScreenShotsSave( 18, 20,Street,48, 200,240,320,save);//截图保存
- FloatPicture( 48, 200, 18, 20,save,cnt);
- ScreenShotsSave( 218, 20,Street,68, 200,240,320,save);//截图保存
- FloatPicture( 68, 200, 18, 20,save,cnt);
-
- ScreenShotsSave( 18, 20,Street,30, 230,240,320,save);//截图保存
- FloatPicture( 30,230, 18, 20,save,cnt);
- ScreenShotsSave( 18, 20,Street,48, 230,240,320,save);//截图保存
- FloatPicture( 48, 230, 18, 20,save,cnt);
- ScreenShotsSave( 18, 20,Street,68, 230,240,320,save);//截图保存
- FloatPicture( 68, 230, 18, 20,save,cnt);
-
- delay_ms(100);
- }
- }
- while(1)//动图
- {
- u8 j = 0;
- for(count_i = 0;count_i < 12;count_i ++)
- {
- delay_ms(100);
- Disd(58,61, 54, 58,Smoke[count_i]);
- if(count_i == 5)Disd(49,127, 34, 29,Ear[1]);
- else if(count_i == 7)Disd(49,127, 34, 29,Ear[0]);
- else;//Ear
- Disd(86,157, 33, 35,Bread[count_i]);
- Disd(152,121, 44, 42,Ping[count_i]);
- // if(count_i == 1 || count_i == 8 )Disd(70,208, 17, 34,Fire[1]);
- // else if(count_i == 3 || count_i == 5 || count_i == 10)Disd(70,208, 17, 34,Fire[2]);
- // else Disd(70,208, 17, 34,Fire[0]);//Fire
- }
- }
- }//main函数
复制代码
所有资料51hei提供下载:
自己的函数 LCD嵌入透明截图合成单图等函数.rar
(2.91 MB, 下载次数: 61)
|