本次工程基于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)
2018-7-15 16:31 上傳
點擊文件名下載附件
|