CURRENT ISSUE

Contests

bottom corner

Feature Article



Issue #209 December 2007

SD Card Display Controller
Honorable Mention Luminary Micro DesignStellaris2006 contest
by Sylvain Davaine

Start | System Overview | SD Memory Cards | Hardware | SHT11 Sensor | FAT File System | Graphic Files | Library | Host | Ideas | Sources & PDF

GRAPHIC FILES

Temperature information is stored in the form of graphics. Because I could easily write the raw data, I chose the Windows bitmap file format for its simplicity. The 24-bit true color BMP format was used to further reduce the complexity because it avoids the need for color palette storage and management, such as the 8-bit format. The increase in size introduced by the 3 × 8 bit red, green, and blue information of the 24-bit format in the BMP file is unimportant because you have plenty of space in the SDMC. The resolution is 640 × 480 pixels.

The BMP format is easy to implement in software. The header of the file consists of some information about the file, including its size, height, and width followed by the little Endian organized data.

For reasons unknown to me, data in a BMP file are organized from the bottom up and from the left to the right! I see no reason why there are no television sets or computer screens that would benefit from this organization. Besides, it can’t be changed and you have to cope with it. In order to facilitate the drawings, I wrote a small Cartesian (x, y) conversion routine to defeat the reverse BMP pixels encoding. In fact, the routine even calculates a BMP file offset:

    [1]

That is:

   [2]

And finally:

   [3]

It is a lot easier to use line, circle, rectangle, and any other graphic functions to draw whatever is needed on the bitmap.

In the project’s BMP file, a horizontal thermometer shows the actual temperature and a history of the last 480 measurements on the left side of the BMP (see Photo 4). The code can be found in the main.c file.

Photo 1
Photo 4—This is the BMP file drawn by the circuit. The history is represented on the left from top to bottom. The thermometer shows the last temperature measurement.


The thermometer is drawn horizontally to take advantage of the data organization within the BMP file and to reduce the time taken to write in the SDMC.

Writing in the SDMC requires you to write full sectors. Therefore, each series of data written in the SDMC is limited to 512 bytes (the size of one sector), which is the maximum width of the colored bars and nearly corresponds to the full temperature resolution. Note that 510 (i.e., 3 RGB × 170) is enough to code 164°C resolution (i.e., –40° to 124°C).

Only a few file functions are needed to write the BMP. To be more precise, just the open/close/write and lseek functions were used. The lseek function is used to move the file pointer anywhere in the file before writing it. This is exactly why I converted the (x, y) coordinates into a file offset. This is extremely powerful because you don’t need to store the entire file in memory or write it each time. A template BMP file is first transferred in the SDMC. Then the software has to update the evolving part of the BMP file (i.e., the thermometer and the history part). The thermometer is completely filled with white pixels before drawing a new temperature value. The file pointer is then positioned at the start of the thermometer and one line of color is drawn. The operation is repeated for several lines to achieve the thermometer height of colored lines. Remember that everything is reversed in the BMP file compared to the BMP file when viewed in a picture viewing program. That means that the first line drawn in the source code is located at the bottom of the thermometer. When the file pointer is added to the next call of the lseek function in the source code, it is made to reach the next line, which is the second line of the thermometer starting from the bottom. On the contrary, the size of the colored bars is subtracted from the offset as the pixels are coded from left to right. This is also why the blue colors are located in the lower index of the colored bar buffer so that they appear on the left. Indeed, the write function that takes the colored bar buffer as input writes it with incrementing offsets in the file.

I tested the thermometer drawing on a PC first using a simple C program for simplicity. It was then trivial to convert the code into the LM3S811 Keil project.

Previous | Next

 


bottom corner