Due to the need to use LCD screen (320 * 240) to display pictures, and the number of pictures is relatively large (hundreds of pictures), and the pictures are required to be saved in 16m SPI flash, obviously if you do not deal with 16m flash, it is obvious that you can not put it down. Later, my colleagues said that we could use the compression algorithm RLE, and made a small software for me with C # to compress the image and get the data after RLE compression.

The disadvantage of this algorithm is that it is not good if the color of the image is complex, so the color should be monotonous as far as possible.

1. The use of RLE algorithm tool

2. The difference between my RLE and the connection above (improved)

3. The method of realization in single chip microcomputer

1. The use of RLE algorithm tool Click to open the link

Here is the download address of the gadget http://download.csdn.net/detail/chen244798611/9696253

Use: it’s also very easy to use. Download rletest.exe, click to open the “compression” interface, and a button “compression” is displayed. Click to select the image to compress automatically

Prompt complete to see the build

The first one has the comparison of the file size before and after compression

The last. C file is compressed to get a data, which can be saved in SPI flash

2. The difference between my RLE and the connection above (improved)

Since the LCD screen is 16 bit data, the comparison should be based on 2 bytes of data instead of 1 byte. Therefore, improvements have been made here, and others are the same as those in the above article. And using the last improved algorithm introduced in the above article, as follows

225intRle_ Decode_ O(unsignedchar*inbuf,intinSize,unsignedchar*outbuf,intonuBufSize)

226{

227unsignedchar*src=inbuf;

228inTI;

229intdecSize=0;

230intcount=0;

two hundred and thirty-one

232while(src《(inbuf+inSize))

233{

234 unsignedcharsign=*src++;

235 intcount=sign&0x3F;

236 if ((decsize + count) “onubufsize) / * the output buffer is out of space*/

237 {

238 return-1;

239 }

240 if ((sign & 0x80) = = 0x80) / * continuous duplicate data flag*/

241 {

242 for(i=0; i

243 {

244 outbuf[decSize++]=*src;

245 }

246 src++;

247 }

248 else

249 {

250 for(i=0; i

251 {

252 outbuf[decSize++]=*src++;

253 }

254 }

255}

two hundred and fifty-six

257returndecSize;

258}

3. The method of realization in single chip microcomputer

The following is the code implemented in the MCU, but there is a problem here. Frequent reading and swiping speed is relatively slow. The test found that it needs more than 100 ms. later, the algorithm was improved, and the FatFs management SPI flash test found that 28ms can display a picture (but the color is not very complex, and the complex time will be longer)

void lcd_ display_ image(uint32_ T epromoffset) / / address saved in flsah

{

uint8_ t buf[1024] = {0};// Define buffer size

uint32_ t totlelen = 0;// Used to save the total length of data

uint32_ t index = 0;// Indexes

uint8_ t temp = 0;// Temporary storage of data

uint8_ t count = 0;// Number of continuous data

uint16_ t colour = 0;// Save colors, such as liquid crystal display

uint8_ t i = 0;

SPI_ FLASH_ ReadBuffer(buf,epromoffset, 3);// The first three bytes hold the total length of the data

epromoffset = epromoffset + 3;// Flash address offset 3

totlelen = buf[0] 《《 16 “ buf[1] 《《 8 | buf[2];// The total length is calculated

LCD_ SetWindows(0,319,0,239);// 320 240 setting LCD display area

While (index “totlelen) / / judge the exit conditions of index and total file length

{

SPI_ FLASH_ ReadBuffer(buf,epromoffset, 1);// Read data

epromoffset++;// Flash address self adding

temp = buf[0];// Get the read data

index++;// Index self adding

count = temp & 0x7f;// Get the number of continuous

If ((temp & 0x80) = = 0x80) / / judge whether it is the same or different continuous

{

SPI_ FLASH_ ReadBuffer(buf,epromoffset, 2);// Read two bytes in succession in the same way

epromoffset = epromoffset + 2;

index = index + 2;

colour = buf[0] 《《 8 | buf[1];// Combined color RGB 565

for(i = 0; i 《 count; i++)

{

LCD_ RAM = colour;// Show FSMC

}

}

Else / / not same continuous

{

//SPI_ FLASH_ ReadBuffer(buf,epromoffset, count *2);

//Read count * 2 data, 2 data form a color data, count * 2 color data

SPI_ DMA_ FLASH_ ReadBuffer_ 1(epromoffset,buf,count *2);

epromoffset = epromoffset + count * 2;// Address offset

index = index + count * 2;

for(i = 0; i 《 count * 2; i= i+2)

{

LCD_ RAM = buf[i] 《《 8 | buf[i+1];// display

}

}

}

index = 0;

}

Improved single chip microcomputer program

void SPI_ Flash_ lcd_ Fatfs_ Image (const char * file name) / / file name

{

uint8_ t buf[piece_ size] = {0};// Open up a big buffer

uint32_ t epromoffset = 0;

uint32_ t totlelen = 0;

uint32_ t index = 0;

uint8_ t temp = 0;

uint32_ t num = 0;

uint8_ t count = 0;

uint16_ t colour = 0;

uint8_ t i = 0,j = 0;

uint16_ t write_ buf = 0;

uint16_ t read_ buf = 0;

SPI_ Flash_ ReadFileData_ add(filename,buf,epromoffset,3,&num);// Fatfa is used to read the total length

epromoffset = epromoffset + 3;

totlelen = buf[0] 《《 16 | buf[1] 《《 8 | buf[2];

LCD_ SetWindows(0,319,0,239);// 320 240

while(index 《 totlelen)

{

if(totlelen – index 》 piece_ size)

{

SPI_ Flash_ ReadFileData_ add(filename,buf,epromoffset,piece_ size,&num);// The read data is saved to the buffer

epromoffset = epromoffset + piece_ size;

read_ buf = piece_ size;

index = index + piece_ size;

}

else

{

SPI_ Flash_ ReadFileData_ add(filename,buf,epromoffset,totlelen – index,&num);

epromoffset = epromoffset + totlelen – index;

read_ buf = totlelen – index;

index = totlelen;

}

while(write_ buf 《 read_ buf)

{

temp = buf[write_ buf];

write_ buf++;

count = temp & 0x7f;

if((temp & 0x80) == 0x80)

{

if((read_ buf- write_ buf) 》 2)

{

colour = buf[write_ buf] 《《 8 | buf[write_ buf+1];

write_ buf = write_ buf + 2;

}

else

{

write_ buf = write_ buf + 2;

}

for(i = 0; i 《 count; i++)

{

LCD_ RAM = colour;

}

}

else

{

count = count *2;

j = 0;

for(i = 0; i 《 count ; i= i+2)

{

if((read_ buf – write_ buf) 》 2)

{

colour = buf[write_ buf] 《《 8 | buf[write_ buf+1];

LCD_ RAM = colour;

write_ buf = write_ buf +2;

}

else

{

SPI_ Flash_ ReadFileData_ add(filename,buf,epromoffset + j,2,&num);// There is a problem here that needs to be improved. If the buffer data is read out, there will be a problem

j = j + 2;

LCD_ RAM =buf[0] 《《 8 | buf[1];

write_ buf = write_ buf +2;

}

}

}

}

write_ buf= write_ buf %piece_ size;

}

}

This program is still a little small
Source; 21ic

Leave a Reply

Your email address will not be published.