introduction
At present, the research on picture decoder is mainly for the PC environment. The design work is only an upgrade on the original basis. There are few considerations for the system and hardware, and it cannot be directly implemented in the embedded system. This paper designs an embedded picture decoder. The format of the picture file is recognized by the FatFs file system, and the corresponding format decoding unit is called to realize image reconstruction and display on the TFT liquid crystal display.
1 system hardware design
The system's core CPU uses LM3S8962, with a rich peripheral interface and a variety of on-chip hardware interface functions (such as UART, SPI, I2C, PWM, etc.). The hardware circuit of the whole system includes an SD card circuit, a TFT liquid crystal display circuit, and an independent key circuit.
1.1 SD card circuit
The SD card has two modes of operation, SD and SPI modes. Since the LM3S8962 has an SPI interface, the embedded system uses the SPI mode. The SD card circuit is shown in Figure 1. The signal detection line CARD_INSERT of the SD card is connected to the PG0 port of the CPU, and the CARD_WP detection card is write protected to the PE2 of the CPU. The power supply circuit of the SD card adopts the controllable circuit of the P-type MOS tube 2SJ355, and is controlled by the CARD_POWER jumper PG1 pin of the CPU. The chip select line CARD_CS is connected to the PA3 of the CPU. The clock signal CARD_SCK is connected to the PA2 of the CPU. The SPI master output slave input CARD_MOSI and the master input slave output CARD_MISO are respectively connected to the CPU's PA5 and PA4.
Figure 1 SD card circuit
1.2 TFT liquid crystal display circuit and independent button circuit
In the TFT liquid crystal display circuit, the data lines D0~D7 of the display are connected to PB0~PB7 of the CPU, and the address lines A0~A7 are connected to PC0~PC7 of the CPU. The TFT back panel LED+ and TFT driver power supplies are all powered by 3.3 V. The independent button is the PD0~PD3 port of the CPU. When the button is pressed, the pin detected by the CPU is low.
2 software design
In order for the entire system to properly read the data files and directories of the SD card, it is necessary to create a file system that can be recognized by the Windows operating system. Considering compatibility and convenience, this design ported a small embedded file system FatFs based on the μC/OSII operating system. The file system is characterized by support for multiple operating systems, ease of portability, and fast storage.
2.1 SD card driver design
The SD card driver not only needs to complete the setting of the corresponding register in the SD card controller and send commands to the SD card, but also realizes the initialization, reading and writing operations of the SD card. The purpose is to provide the corresponding function function for its upper layer, shielding the specific operation directly to the hardware. The SD card driver uses the ZLG/SD MMC/SD package. Some common API functions are provided in the package. You can access the SD card by calling the relevant API functions, including SD_Initialize (initialize SD card), SD_ReadBlock (read one block of SD card), SD_WriteBlock (write SD card). One block), SD_EraseBlock (erasing multiple blocks of the SD card), and so on.
2.2 FatFs file system design
FatFs is an open source file management system commonly used in small embedded systems to implement file systems, support FAT12, FAT16, FAT32, ANSI C standards, and does not depend on the hardware platform. For the transplantation of FatFs, you first need to define the data type and match the data type of CPU.H. Secondly, let the underlying function in FatFs directly call the function of ZLG/SD package. E.g:
DRESULT disk_read (BYTE drv, BYTE *buff, DWORD sector, BYTE count){
If(count==1){
SD_ReadBlock (sector, buff); / / read a block of the SD card, call SD_ReadBlock
}
Else{
SD_ReadMultiBlock (sector, count, buff); / / read multiple blocks of the SD card, call SD_ReadMultiBlock
}
Return FALSE;
}
Due to the limited space, the functions of the underlying function calling the SD package are not listed one by one. Through these operations, you can call f_open, f_read, f_write and other functions to create, read, and write files.
3 picture decoding analysis
3.1 Analysis of JPG format
The JPEG expert group developed two basic compression algorithms, two data encoding methods, and four encoding modes. In practical applications, most JPG images use DCT (Discrete Cosine Transform), Huffman (Huffman) encoding, and sequential mode. The JPG encoding process mainly includes color conversion, DCT transform, quantization, entropy coding and Huffman coding.
The process of software image decoding is the inverse of image encoding. The programming steps are as follows:
1 Initialize the FatFs file system, and use the f_open function to open the jpg format file, and use f_read to read the image encoding related information from the JPG format file, such as image size, quantization table, Huffman table, and so on.
2 Read the minimum coding unit data, perform entropy decoding, inverse quantization, inverse discrete cosine transform, YCrCb mode to RGB mode conversion, etc., and save the final decoded data to the Buffer or directly output to the display.
3 Repeat the second step until the entire picture is decoded.
3.2 Analysis of BMP format
BMP (Bitmap) is an image file format used by Windows. A bitmap file consists of four parts: a bitmapfile header, a bitmapinformation header, a color table, and a byte array that defines the bitmap. The color depth of BMP images is usually 1, 4, 8, 16, 24, and 32 bits, corresponding to monochrome, 16 colors, 256 colors, 16-bit high color, 24-bit true color, and 32-bit enhanced true color. This requires the creation of a corresponding color table to achieve the display of the bitmap. The steps to programmatically implement the bitmap display are as follows:
1 Initialize the FatFs file system, and read the information related to the picture encoding in the BMP format file, such as image pixel data, image bit number, RGB value, and so on.
2 Position the corresponding color in the color table based on the pixel index. The file is positioned to the corresponding color item, and the color corresponding to the index is taken out.
3 The RGB data read from the file is converted to the format supported by the TFT (the TFT selected in this system supports the RGB565 format). Draw the pixel on the liquid crystal until the entire image is drawn.
3.3 Analysis of GIF format
The structure of a GIF file can be divided into three parts: a file header, a GIF data stream, and a file terminator. The GIF file format uses variable length LZW compression encoding. LZW compression has three important objects: data stream (CharStream), code stream (CodeStream) and compiled table (String Table). At the time of encoding, the data stream is an input object (a raster data sequence of an image), and the encoded stream is an output object (image data stored in a GIF file). The process of decoding software implementation is similar to JPG and BMP. It is first called GIF format file and then created for GIF_LZW decoding, and finally displayed on TFT. It should be noted that in the decoding process, the encoded stream is the input object, and the data stream is the output object. A compiled table is an object that needs to be used for both encoding and decoding.
4 modular testing
The entire system is modular in design and uses the μC/OSII operating system for task management. Take the task Task_BMP as an example to test the display of 24-bit true color BMP bitmaps. The program is as follows:
Task_BMP{
F_mount(0, &fs);
Res = f_open(&fsrc, "ab.BMP", FA_OPEN_EXISTING | FA_READ);
Res = f_read(&fsrc, &bmp, sizeof(bmp), &br);
If((bmp.pic_head[0]=='B')&&(bmp.pic_head[1]=='M')){//Use the file header to determine whether it is a BMP file.
Res= f_lseek(&fsrc,((bmp.pic_data_address_h<<16)|bmp.pic_data_address_l));//Using Windows BMP format, BMP origin is in the lower left corner
For(tx= bmp.pic_h_l;tx>0;tx--){
F_read(&fsrc, buffer, (bmp.pic_w_l)*3, &br);
For(ty=0;ty
G_data = *(ty*3 +1+buffer);
B_data = *(ty*3 +0+buffer);
If(tx
Point.y = ty;
Point.r = r_data;
Point.g = g_data;
Point.b = b_data;
pixelDraw(point.y , point.x, RGB888ToRGB565(point.r, point.g, point.b)); // 24 bits converted to 16 bits supported by TFT and displayed
}
}
}
}
F_close(&fsrc);
}
Conclusion
This paper proposes an embedded picture browser design idea, completes the design process in a modular way, and can easily improve the design of the decoding library according to the application requirements, so that it can run well on the actual platform. This design has basically achieved the expected effect, although it can not be used as a general picture browser solution, but it still has certain reference value in the design of GPS, handheld PDA and remote monitoring system that need to use picture decoder.
This article refers to the address: http://
The main circuit of the equipment is the full bridge controlled circuit and the trigger circuit is the programmable integrated circuit. The phase-shifting, fixed width and modulation of the pulse are all digitized, and it does not need any adjustment for the section of the trigger. It has the features of high reliability, high pulse symmetry, strong anti-interference ability, quick reaction, as well as the advantages of no heat-generating, constant current, energy-saving which is compared with the discharge with the electrical resistance.
AGV Battery Maintenance System
48 Volt Battery Charger,Low Maintenance Agv Battery Charger,Agv Portable Charger Discharger,Agv Battery Maintenance System
Xinxiang Taihang Jiaxin Electric Tech Co., Ltd , http://www.chargers.be