SPI - Print image and text on LCD screen

If you are not familiar with SPI, please read Introduction to SPI first.
 
Preparation
  • Ameba x 1
  • ILI9341 TFT LCD with SPI interface x 1

Example

We have tested the following two models of ILI9341 TFT LCD with SPI interface:

Common pins in ILI9341 TFT LCD with SPI interface:

  • MOSI: Standard SPI Pin
  • MISO: Standard SPI Pin
  • SLK: Standard SPI Pin
  • CS: Standard SPI Pin
  • RESET: Used to reboot LCD.
  • D/C: Data/Command. When it is at Low, the signal transmitted are commands, otherwise the data transmitted are data.
  • LED (or BL): Adapt the screen backlight. Usually controled by PWM, or can be connected to VCC (100% light).
  • VCC: Connected to 3V or 5V, depends on its spec.
  • GND: Connected to GND.

Wiring example of QVGA TFT LCD:

1

Wiring example of adafruit 2.8 tft LCD touch shield:
Please note that this shield model enables the backlight by default and pin 8 is not for backlight. And the VCC should be connected to 5V.

2

RTL8710 Wiring Diagram:

2

Open the example, “Files” -> “Examples” -> “AmebaSPI” -> “ILI9341_LCD_basic”

3

Compile and upload to Ameba, then press the reset button.

Then you can see some display tests appear on the LCD screen, such as displaying different colors, drawing vertical and horizontal lines, drawing circles, …etc.

4

Code Reference

  •  RGB 16-bit
    ILI9341 uses RGB 16-bit to display colors. Different from RGB 24-bit, it uses 5 bits for red, 6 bits for green, 5 bits for blue. For example, the RGB 24-bit representation of sky blue is 0x87CEFF, that is in binary:
    • Red: 0x87 = B10000111
    • Green: 0xCE = B11001110
    • Blue: 0xFF = B11111111

    and converted to RGB 16-bit:

    • Red: B10000
    • Green: B110011
    • Blue: B11111

    Then concatenate them, which forms B1000011001111111 = 0x867F

  • Drawing of ILI9341
    • First you have to specify the range of the rectangle to draw, then pass the 2-byte RGB 16-bit color to ILI9341 corresponding to each pixel one by one, in this way ILI9341 fills each color to each pixel.
    • You still have to specify the drawing range even though the range covers only one pixel.
    • From the rules we mentioned above, we can conclude that drawing vertical or horizontal lines are faster than slash lines.
  • Printing text on ILI9341
    • In our API, each character is 5×7 but each character is printed to size 6×8 (its right side and below are left blank), so as to separate from next character. For example, the character “A”: 5
    • The font size represents the dot size. For example, if the font size is 2, each dot in the character is a 2×2 rectangle
  • Screen rotation
    • ILI9341 provides 0, 90, 180, 270 degrees screen rotation.
    • If the original width is 240 and original height is 320, when the screen rotates 90 degrees, the width becomes 320 and the height becomes 240.
Please confirm that QQ communication software is installed