|
ILI9486TFT驅(qū)動(dòng)程序STM32 這個(gè)用來移植
1、該例程為JPEG圖片解碼例程。
2、使用說明
(1)工程文件路徑:SY-STM32F407 V2程序\SY-STM32F407 V2例程:JPEG圖片解碼例程\Project\Project.uvproj。
(2)請(qǐng)使用MDK 4.0以上版本打開,MDK版本過低會(huì)導(dǎo)致無法識(shí)別工程。
(3)下載調(diào)試工具為JLINK。
(4)請(qǐng)將串口線(直連串口線)插在板子COM1口上,并打開超級(jí)終端或串口助手,配置波特率115200,8位,一個(gè)停止位,無校驗(yàn)位。
(5)HEX文件下載到板子后,使用超級(jí)終端或串口調(diào)試助手可以看到調(diào)試信息,插上TFT模塊顯示一個(gè)小MM,表明例程運(yùn)行正確。
3、注意事項(xiàng)
請(qǐng)務(wù)必在下載、調(diào)試、運(yùn)行過程中,保持板子上電、JLINK連接并插在電腦上。
單片機(jī)源程序如下:
- #include "jpegdecoder.h"
- static int MaskT, MaskL, MaskR, MaskB; /* Active drawing area */
- /****************************************************************************************************************************
- *函數(shù)名稱:JpgDecoderRead()
- *參數(shù) :
- *返回值 :
- *功能描述:用于JPG解碼讀取內(nèi)存卡JPG文件數(shù)據(jù),內(nèi)部調(diào)用
- ******************************************************************************************************************************/
- static UINT JpgDecoderRead(JDEC* jd, /* Decoder object */BYTE* buff, /* Pointer to the read buffer (NULL:skip) */UINT nd /* Number of bytes to read/skip from input stream */)
- {
- UINT rb;
- FIL *fil = (FIL*)jd->device; /* Input stream of this session */
- if (buff) { /* Read nd bytes from the input strem */
- f_read(fil, buff, nd, &rb);
- return rb; /* Returns number of bytes could be read */
- } else { /* Skip nd bytes on the input stream */
- return (f_lseek(fil, f_tell(fil) + nd) == FR_OK) ? nd : 0;
- }
- }
- void SetJPGDisplayAera(uint16_t xs,uint16_t ys,uint16_t xe,uint16_t ye)
- {
- MaskL = xs;
- MaskR = xe;
- MaskT = ys;
- MaskB = ye;
- }
- /****************************************************************************************************************************
- *函數(shù)名稱:Jpg_Display()
- *參數(shù) :
- *返回值 :
- *功能描述:用于JPG解碼后將RGB數(shù)據(jù)顯示到TFT液晶屏,內(nèi)部調(diào)用
- ******************************************************************************************************************************/
- static UINT Jpg_Display (
- JDEC* jd, /* Decoder object */
- void* bitmap, /* Bitmap data to be output */
- JRECT* rect /* Rectangular region to output */
- )
- {
- int yc, xc, xl, xs;
- uint16_t *pData=(uint16_t*)bitmap;
- jd = jd; /* Suppress warning (device identifier is not needed) */
- /*將解碼數(shù)據(jù)顯示到液晶屏區(qū)域*/
- //disp_blt(rect->left, rect->right, rect->top, rect->bottom, (uint16_t*)bitmap);
-
- if (rect->left > rect->right || rect->top > rect->bottom) return 0; /* Check varidity */
- if (rect->left > MaskR || rect->right < MaskL || rect->top > MaskB || rect->bottom < MaskT) return 0; /* Check if in active area */
- yc = rect->bottom - rect->top + 1; /* Vertical size */
- xc = rect->right - rect->left + 1; xs = 0; /* Horizontal size and skip */
- if (rect->top < MaskT) { /* Clip top of source image if it is out of active area */
- pData += xc * (MaskT - rect->top);
- yc -= MaskT - rect->top;
- rect->top = MaskT;
- }
- if (rect->bottom > MaskB) { /* Clip bottom of source image if it is out of active area */
- yc -= rect->bottom - MaskB;
- rect->bottom = MaskB;
- }
- if (rect->left < MaskL) { /* Clip left of source image if it is out of active area */
- pData += MaskL - rect->left;
- xc -= MaskL - rect->left;
- xs += MaskL - rect->left;
- rect->left = MaskL;
- }
- if (rect->right > MaskR) { /* Clip right of source image it is out of active area */
- xc -= rect->right - MaskR;
- xs += rect->right - MaskR;
- rect->right = MaskR;
- }
- /*設(shè)置水平方向X開始坐標(biāo)*/
- // LCD_WriteReg(0x50, rect->left);
- // /*設(shè)置水平方向X結(jié)束坐標(biāo)*/
- // LCD_WriteReg(0x51, rect->right);
- // /*設(shè)置豎直方向Y開始坐標(biāo)*/
- // LCD_WriteReg(0x52, rect->top);
- // /*設(shè)置豎直方向Y結(jié)束坐標(biāo)*/
- // LCD_WriteReg(0x53, rect->bottom);
- LCD_SetCursor(rect->left, rect->top);
- LCD_WriteRAM_Start();
- do { /* Send image data */
- xl = xc;
- do {
- //pd = *pat++;
- LCD_WriteRAM(*pData++); //顯示像素
- } while (--xl);
- pData += xs;
- } while (--yc);
- return 1; /* Continue decompression */
- }
- /****************************************************************************************************************************
- *函數(shù)名稱:Load_Jpg()
- *參數(shù) :
- *返回值 :
- *功能描述:用于JPG解碼并顯示到TFT液晶屏,外部調(diào)用即可進(jìn)行解碼顯示
- ******************************************************************************************************************************/
- void Load_Jpg (
- FIL *fp, /* Pointer to the open file object to load */
- void *work, /* Pointer to the working buffer (must be 4-byte aligned) */
- UINT sz_work /* Size of the working buffer (must be power of 2) */
- )
- {
- JDEC jd; /* Decoder object (124 bytes) */
- JRESULT rc;
- BYTE scale;
- /*載入需要解碼的JPG數(shù)據(jù) */
- rc = jd_prepare(&jd, JpgDecoderRead, work, sz_work, fp);
- if (rc == JDR_OK)
- {
- /*判斷JPG的縮放,以適應(yīng)屏幕大小*/
- for (scale = 0; scale < 3; scale++)
- {
- if ((jd.width >> scale) <= LCD_XMAX && (jd.height >> scale) <= LCD_YMAX) break;
- }
- /* 開始解碼JPG文件并顯示到液晶屏 */
- rc = jd_decomp(&jd, Jpg_Display, scale); /* Start to decompress */
- } else {
- LCD_SetColors(RED,WHITE);
- LCD_DrawString(30,140,"prepare ERR");
- }
- }
復(fù)制代碼- /* ------------------------------------------包含的頭文件-----------------------------------------------*/
- #include "stm32f4xx.h"
- #include "delay.h"
- #include "led.h"
- #include "usart.h"
- #include "lcd.h"
- #include "adc.h"
- extern unsigned char JPGBUFF[];
- /*************************************************************************************
- * 函數(shù)名稱:main()
- * 參數(shù) :void
- * 返回值 :void
- * 描述 :程序主入口main函數(shù)
- *************************************************************************************/
- int main(void)
- {
- SystemInit(); //初始化系統(tǒng)時(shí)鐘,設(shè)置時(shí)鐘為168Mhz
- LED_GPIO_Config(); //初始化LED的GPIO配置
- SysTick_Init(); //系統(tǒng)節(jié)拍初始化
- USART1_Conf(); //串口1初始化
- LCD_Init(); //LCD初始化
- printf("\r\n歡迎使用SY-STM32F407 V2開發(fā)板!\r\n");
- printf("\r\n 山巖科技!\r\n");
- printf("\r\n -----專業(yè),值得信賴!\r\n");
- delay_nms(50); //延時(shí)
- printf("\r\n 這是一個(gè)JPG解碼例程 \r\n");
- LoadJpegFile(JPGBUFF);
- while(1)
- {
- LED1(On);
- delay_nms(300);
- LED1(Off);
- delay_nms(300);
- }
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
復(fù)制代碼
所有資料51hei提供下載:
ILI9486 JPEG圖片解碼例程.rar
(491.05 KB, 下載次數(shù): 95)
2018-11-27 03:48 上傳
點(diǎn)擊文件名下載附件
源代碼
|
|