ILI9341 Library: Unterschied zwischen den Versionen

Aus ProjectWiki
Wechseln zu:Navigation, Suche
K (Overview)
K (Overview)
 
(6 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
== Overview ==
 
== Overview ==
 +
New version - 1.1 (Aug. 2017)
 +
 
[http://www.youtube.com/watch?v=eGcUwT6J5nE Demo Video]
 
[http://www.youtube.com/watch?v=eGcUwT6J5nE Demo Video]
  
Zeile 12: Zeile 14:
 
* Basic graphics, pictures (fast SRAM-pictures), text
 
* Basic graphics, pictures (fast SRAM-pictures), text
  
The library has been developed and tested using an XMega-A1 Xplained board with a Spansion S25FL032P (32Mbit) dataflash mounted on it. Credits go to Hkipnik for the fixed font text/BGF picture routines from his ILI9321 library.
+
The library has been developed and tested using an XMega-A1 Xplained board with a Spansion S25FL032P (32Mbit) dataflash mounted on it. Credits go to Hkipnik for the fixed font text/BGF picture routines and the alternative init sequence from his ILI9341 lib (in V1.1).
  
 
== Options ==
 
== Options ==
Zeile 85: Zeile 87:
 
Pin of the backlight control signal
 
Pin of the backlight control signal
 
<pre>Const Lcd_pin_backlight = 0 (6)</pre>
 
<pre>Const Lcd_pin_backlight = 0 (6)</pre>
 +
 +
 +
In case the display shows scanlines, you can try an alternative init sequence:
 +
<pre>Const Lcd_alternative_init = False</pre>
  
  
Zeile 106: Zeile 112:
  
 
=== Backlight ===
 
=== Backlight ===
Sets the backlight value (0: BL Off, Standby On; 1-254: PWM, 255: BL On, Display Wakeup)
+
Sets the backlight value (0: BL Off; 1-254: PWM; 255: BL On. 0 puts the display also in standby mode, any other value reenables it)
 
<pre>Sub Lcd_backlight(byval Value As Byte)</pre>
 
<pre>Sub Lcd_backlight(byval Value As Byte)</pre>
  
Zeile 160: Zeile 166:
 
<pre>Sub Lcd_fill_circle(byval X As Word , Byval Y As Word , Byval Radius As Word , Byval Color As Word)</pre>
 
<pre>Sub Lcd_fill_circle(byval X As Word , Byval Y As Word , Byval Radius As Word , Byval Color As Word)</pre>
  
 +
 +
Draws an ellipse
 +
<pre>Sub Lcd_ellipse(byval X_center As Word , Byval Y_center As Word , Byval X_radius As Word , Byval Y_radius As Word , Byval Color As Word)</pre>
  
 
=== Pictures ===
 
=== Pictures ===
Zeile 189: Zeile 198:
 
For reduced Digit font
 
For reduced Digit font
 
<pre>Dim Lcd_digit_font As Bit</pre>
 
<pre>Dim Lcd_digit_font As Bit</pre>
 +
 +
 +
Normal/Color font format
 +
<pre>Dim Lcd_color_font As Bit</pre>
  
  
Zeile 238: Zeile 251:
  
 
Restore Color8x8
 
Restore Color8x8
 +
Lcd_color_font = True
 
Lcd_loadfont
 
Lcd_loadfont
  
Zeile 447: Zeile 461:
 
[[File:TFT-XPlained-Backside.jpg|width|600px|XPlained-A1 connection overview (Back side, only for 16 Bit mode)]]
 
[[File:TFT-XPlained-Backside.jpg|width|600px|XPlained-A1 connection overview (Back side, only for 16 Bit mode)]]
  
For the 16-Bit mode, two additional connections on the back side the the XPlained have to be added to get an additional 8-bit output port. A drop of instant adhesive holds the connector in place.
+
For 16-Bit mode, two additional connections on the back side the the XPlained have to be added to get an additional 8-bit output port. A drop of instant adhesive holds the connector in place.
  
  
Zeile 453: Zeile 467:
  
 
Stripboard example
 
Stripboard example
 +
  
 
== Electrical connection ==
 
== Electrical connection ==
Zeile 458: Zeile 473:
  
  
== Donate ==
+
== Change log ==
This Software is [http://en.wikipedia.org/wiki/Donationware Donationware].
+
'''1.1:'''
<paypal>1</paypal>
+
* ''Lcd_color_font'' toggles between normal/color font format, fixes wrong displayed fixed fonts
[[About|See here]] for more informations
+
* Compatibility bug fixes
 +
* Added alternative init sequence for displays showing scanlines, enabled by ''Lcd_alternative_init''
 +
* Fixed bug in HW SPI waitloops
 +
* Updated for Bascom 2.0.8.0
 +
* Added bresenham ellipse function
  
 +
== Download ==
  
== Download ==
+
* [http://www.braunecker.at/downloads/ili9341/ili9341.zip ILI9341 TFT Display Driver Library 1.1]
* [http://www.braunecker.at/downloads/ili9341/ili9341.zip ILI9341 TFT Display Driver Library 1.0]
+
 
 +
 
 +
Old versions:
 +
* [http://www.braunecker.at/downloads/ili9341/ili9341-1-0.zip ILI9341 TFT Display Driver Library 1.0]

Aktuelle Version vom 30. August 2017, 21:50 Uhr

Overview

New version - 1.1 (Aug. 2017)

Demo Video

Forum thread

Features:

  • SPI (Soft-/Hardware), 8/16 Bit parallel interface
  • ATMega/ATXmega
  • Fast assembler-optimized routines
  • Backlight control (Digital IO or PWM)
  • Screen rotation (4 directions), Standby, Color inversion
  • Basic graphics, pictures (fast SRAM-pictures), text

The library has been developed and tested using an XMega-A1 Xplained board with a Spansion S25FL032P (32Mbit) dataflash mounted on it. Credits go to Hkipnik for the fixed font text/BGF picture routines and the alternative init sequence from his ILI9341 lib (in V1.1).

Options

Options and settings need to be set before the $include-statement, every setting has a default value that will be used if not specified otherwise. (in the list below the default values for the ATXMega are shown, values for ATMega are written in brackets () if applicable).

Enables the SPI- instead of the 8-Bit paralell interface

Const Lcd_enable_spi = False


Use software SPI

Const Lcd_use_soft_spi = False


Enables the 16-Bit paralell interface

Const Lcd_enable_16bit = False


Enable backlight control

Const Lcd_enable_backlight = False


Use a timer to generate a PWM signal for the backlight instead of switching it on or off

Const Lcd_enable_backlight_pwm = True


ATMega only: select the timer to use for the PWM signal (XMega: automatic)

Lcd_backlight_timer Alias Timer2


Invert backlight logic (1: off, 0: on)

Const Lcd_invert_backlight = False


Select the port of the display control pins (XMega: HW-SPI & PWM Timer fixed on PortC-PortF, ATMega: HW SPI on PortB, for SW SPI or parallel modes any GPIO will work)

Const Lcd_ctrl_port = Portc (Portb)


8 Bit mode data port

Const Lcd_data_port_1 = Portf (Portc)


16 Bit mode data port #2

Const Lcd_data_port_2 = Portd


Port of the display reset signal

Const Lcd_reset_port = Lcd_ctrl_port


Pin of the display reset signal

Const Lcd_reset_pin = 0


SPI mode pin assignments (HW SPI: fixed, SW SPI: any GPIO)

Const Lcd_pin_dc = 1 (4)
Const Lcd_pin_cs = 4 (0)
Const Lcd_pin_sdo = 5 (2)
Const Lcd_pin_clk = 7 (1)


parallel (8/16 Bit) mode pin assignments

Const Lcd_pin_wr = 1
Const Lcd_pin_rd = 5
Const Lcd_pin_dc = 7
Const Lcd_pin_cs = 4


Port of the backlight control signal

Const Lcd_backlight_port = Lcd_ctrl_port


Pin of the backlight control signal

Const Lcd_pin_backlight = 0 (6)


In case the display shows scanlines, you can try an alternative init sequence:

Const Lcd_alternative_init = False


API

Initializes the control interface (paralell/serial), backlight control and the display

Sub Lcd_init()


Inverts the screen's colors

Sub Lcd_invert(byval Inverted As Byte )


Sleep mode

Indicates if the display is in sleep mode.

Dim Lcd_sleepmode As Bit


Set display in sleep mode / wake up

Sub Lcd_sleep(byval Value As Byte)


Backlight

Sets the backlight value (0: BL Off; 1-254: PWM; 255: BL On. 0 puts the display also in standby mode, any other value reenables it)

Sub Lcd_backlight(byval Value As Byte)


Smoothly dims the backlight (PWM only)

Sub Lcd_backlight_dim(byval Startvalue As Byte , Byval Endvalue As Byte , Byval Millisecs As Word)


Screen rotation

Indicates the current rotation

Dim Lcd_rotation As Byte


the actual max X and Y coordinates (after rotation)

Dim Lcd_screen_width As Word
Dim Lcd_screen_height As Word


Sets the display rotation (0: 0° Portrait, 1: 90° Landscape, 2: 180° Portrait, 3: 270° Landscape, 4: 0° ...)

Sub Lcd_set_rotation(byval Rotation As Byte)


Basic graphics

Clears the screen.

Sub Lcd_clear(byval Color As Word) 


Draws a rectangle

Sub Lcd_rect(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color As Word)


Draws a filled rectangle, checks for the display boundaries

Sub Lcd_fill_rect(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color As Word)


Sets a single pixel.

Sub Lcd_set_pixel(byval X As Word , Byval Y As Word , Byval Color As Word)


Draws a line between two points

Sub Lcd_line(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color As Word)


Draws a line with color transition between two points

Sub Lcd_line_gradient(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color1 As Word , Byval Color2 As Word)


Draws a circle

Sub Lcd_circle(byval Xcenter As Word , Byval Ycenter As Word , Byval Radius As Word , Byval Color As Word)


Draws a filled circle

Sub Lcd_fill_circle(byval X As Word , Byval Y As Word , Byval Radius As Word , Byval Color As Word)


Draws an ellipse

Sub Lcd_ellipse(byval X_center As Word , Byval Y_center As Word , Byval X_radius As Word , Byval Y_radius As Word , Byval Color As Word)

Pictures

Draws a BIN picture from the internal program flash memory. Image has to be loaded with Restore before.

Sub Lcd_pic_flash(byval Xs As Word , Byval Ys As Word , Byval Width As Byte , Byval Height As Word)


Draws a BIN picture stored on an external SPI DataFlash [1]

Sub Lcd_pic_spi(byval Xs As Word , Byval Ys As Word , Byval Width As Word , Byval Height As Word , Byval Address As Dword)


Set to the start address of the free SRAM memory section, where BIN pics should be loaded to

Dim Lcd_ram_pics_free_ptr As Dword


Loads a BIN picture from the program flash into the SRAM for faster access. Data will be loaded starting at Lcd_ram_pics_free_ptr, the function returns the start address of the actual picture.

Function Lcd_load_pic_flash2ram(byval Width As Word , Byval Height As Word) As Word


Draws a BIN picture from the SRAM memory.

Sub Lcd_pic_ram(byval Xs As Word , Byval Ys As Word , Byval Width As Word , Byval Height As Word , Byval Address As Dword)


Draws a BGF coded picture from the program flash memory.

Sub Lcd_pic_bgf(byval Xoffset As Word , Byval Yoffset As Word)


Text

For reduced Digit font

Dim Lcd_digit_font As Bit


Normal/Color font format

Dim Lcd_color_font As Bit


Loads the font, following Lcd_text commands will use it. You need to call Restore [Font] before.

Sub Lcd_loadfont()


Draws a fixed-font text on the screen.

Sub Lcd_text(byval S As String , Byval Xoffset As Word , Byval Yoffset As Word , Byval Forecolor As Word , Byval Backcolor As Word)


Sample

$regfile = "m128def.dat"
'$regfile = "xm128a1def.dat"
$hwstack = 64
$swstack = 64
$framesize = 64

Config Submode = New
Const False = 0
Const True = 1

#if _xmega = True
   $crystal = 32000000
   $include "XMegaPLL.inc"
#else
   $crystal = 16000000
#endif

'Const Lcd_enable_spi = True
'Const Lcd_use_soft_spi = True
Const Lcd_enable_16bit = True
$include "ILI9341.inc"

$include "ProportionalFont.inc"

Sub Random_color()
   R = Rnd(255)
   G = Rnd(255)
   B = Rnd(255)
   Color = Color24to16(r , G , B)
End Sub

Dim Pixels As Word
Dim R As Byte , G As Byte , B As Byte
Dim X As Word , Y As Word , Color As Word
Dim X2 As Word , Y2 As Word , Radius As Word
Dim Statustext As String * 30

Restore Color8x8
Lcd_color_font = True
Lcd_loadfont

Restore Timesnewroman_10pt
Lcd_tt_loadfont

Enable Interrupts

Lcd_init

Do
   ' =========== Clear Screen ============
   For Pixels = 1 To 99
      Random_color
      Lcd_clear Color
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Gradient Fill (Color16 functions) ============
   R = 0
   G = 0
   B = 0
   X2 = 0
   Color = 0
   Y = 0
   For Pixels = 0 To 512
      Radius = Color
      Random_color
      For G = 0 To 32
         X2 = Color16alpha(color , Radius , G)
         Lcd_fill_rect 0 , Y , Lcd_screen_width , Y , X2
         Y = Y + 1
         If Y = Lcd_height Then Y = 0
      Next
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Pixels ============
   For Pixels = 1 To 65535
      Random_color
      X = Rnd(lcd_screen_width)
      Y = Rnd(lcd_screen_height)
      Lcd_set_pixel X , Y , Color
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Lines ============
   For Pixels = 1 To 3000
      Random_color
      X = Rnd(lcd_screen_width)
      Y = Rnd(lcd_screen_height)
      X2 = Rnd(lcd_screen_width)
      Y2 = Rnd(lcd_screen_height)
      Lcd_line X , Y , X2 , Y2 , Color
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Boxes ============
   For Pixels = 1 To 10000
      Random_color
      X = Rnd(lcd_screen_width)
      Y = Rnd(lcd_screen_height)
      X2 = Rnd(lcd_screen_width)
      Y2 = Rnd(lcd_screen_height)
      Lcd_rect X , Y , X2 , Y2 , Color
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Circles ============
   For Pixels = 1 To 1000
      Random_color
      Y = Rnd(lcd_screen_width)
      Y2 = Rnd(lcd_screen_height)
      Radius = Rnd(200)
      Lcd_circle Y , Y2 , Radius , Color
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Filled Circles ============
   For Pixels = 1 To 50
      Random_color
      Y = Rnd(lcd_screen_width)
      Y2 = Rnd(lcd_screen_height)
      Radius = Rnd(80)
      Lcd_fill_circle Y , Y2 , Radius , Color
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Flash BIN Pics ============
   For Pixels = 1 To 50
      X = Rnd(80)
      Y = Rnd(200)
      Restore Coffee
      Lcd_pic_flash X , Y , 160 , 120
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Flash BGF Pics ============
   For Pixels = 1 To 50
      X = Rnd(108)
      Y = Rnd(188)
      Restore Animals
      Lcd_pic_bgf X , Y
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Fixed Font Text ============
   For Pixels = 1 To 1000
      Random_color
      X = Rnd(220)
      Y = Rnd(310)
      Lcd_text "Text" , X , Y , Color , Color_black
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Proportional Font Text ============
   For Pixels = 1 To 1000
      Random_color
      X = Rnd(220)
      Y = Rnd(310)
      Lcd_tt_text "Text" , X , Y , Color
   Next
   Waitms 3000
   Lcd_clear &H0000

   ' =========== Rotation ============
   For Pixels = 0 To 4
      Lcd_set_rotation Pixels
      Lcd_clear Color_white
      Y = Lcd_screen_height - 20
      Lcd_fill_rect 0 , Y , Lcd_screen_width , Lcd_screen_height , Color_black
      Y = Y + 4
      Statustext = "Rotation " + Str(lcd_rotation)
      Lcd_tt_text Statustext , 10 , Y , Color_white
      X = Lcd_screen_width - 80
      X = X / 2
      Y = Lcd_screen_height - 155
      Y = Y / 2
      Restore Hand
      Lcd_pic_flash X , Y , 80 , 155
      Waitms 1500
   Next

   ' =========== Backlight Dimming ============
   X = 0
   Lcd_clear Color_white
   Y = Lcd_screen_height - 20
   Lcd_fill_rect X , Y , X2 , Y2 , Color_black
   Y = Y + 4
   Lcd_tt_text "Backlight dimming" , 10 , Y , Color_white
   Lcd_backlight_dim 255 , 1 , 1500                                          ' dim to 0 would enable the screen's standby mode
   Waitms 200
   Lcd_backlight_dim 1 , 255 , 1500

   ' =========== Screen Standby ============
   Lcd_clear Color_black
   Y = Lcd_screen_height - 16
   Lcd_tt_text "Standby" , 10 , Y , Color_white
   Waitms 2000
   Lcd_backlight 0
   Waitms 1000
   Lcd_backlight 255
   Waitms 1000

   ' =========== Invert ============
   Y = Lcd_screen_height - 20
   Lcd_fill_rect X , Y , X2 , Y2 , Color_black
   Y = Y + 4
   Lcd_tt_text "Invert" , 10 , Y , Color_white
   Waitms 1000
   Lcd_invert True
   Waitms 3000
   Lcd_invert False
   Waitms 1000
Loop
End

$include "data\color8x8.font"

$include "data\TimesNewRoman_10pt.inc"

$inc Coffee , Nosize , "data\Coffee.bin"
$inc Hand , Nosize , "data\Hand.bin"

Animals:
$bgf "data\Animals.bgc"


Sample project from the video

The complete project, from which the video has been made, is included in the download. It is based on a XMega XPlained-A1 development board with a Spansion S25FL032P 4Mb DataFlash mounted. The TFT display (MikroE TFT Proto) is mounted on a strip board together with the backlight and touch screen components.


XPlained-A1 connection overview (Front side)

The connections on the front side of the XPlained. On J4 all control signals are connected, the parallel data lines are located on J1 resp. J3, the touch screen is located on J2 (T1..3 are the outputs of the OpAmp).


XPlained-A1 connection overview (Back side, only for 16 Bit mode)

For 16-Bit mode, two additional connections on the back side the the XPlained have to be added to get an additional 8-bit output port. A drop of instant adhesive holds the connector in place.


XPlained-A1 TFT-Dev board

Stripboard example


Electrical connection

LCD connection schematic


Change log

1.1:

  • Lcd_color_font toggles between normal/color font format, fixes wrong displayed fixed fonts
  • Compatibility bug fixes
  • Added alternative init sequence for displays showing scanlines, enabled by Lcd_alternative_init
  • Fixed bug in HW SPI waitloops
  • Updated for Bascom 2.0.8.0
  • Added bresenham ellipse function

Download


Old versions: