ILI9341 Library: Unterschied zwischen den Versionen

Aus ProjectWiki
Wechseln zu:Navigation, Suche
K
K
Zeile 1: Zeile 1:
 
== Overview ==
 
== Overview ==
 
ILI9341 driver library for ATXMega/ATMega with hardware/software SPI or 8/16 bit parallel mode. Includes Backlight control with a GPIO or a PWM signal generated by a timer. Supports screen rotation (4 directions). Most of the graphics routines are optimized for speed with inline Assembler.
 
ILI9341 driver library for ATXMega/ATMega with hardware/software SPI or 8/16 bit parallel mode. Includes Backlight control with a GPIO or a PWM signal generated by a timer. Supports screen rotation (4 directions). Most of the graphics routines are optimized for speed with inline Assembler.
 +
  
 
== Options ==
 
== 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
 
Enables the SPI- instead of the 8-Bit paralell interface
<pre>Const Lcd_enable_spi = False
+
<pre>Const Lcd_enable_spi = False</pre>
 +
 
  
 
Use software SPI
 
Use software SPI
Const Lcd_use_soft_spi = False
+
<pre>Const Lcd_use_soft_spi = False</pre>
 +
 
  
 
Enables the 16-Bit paralell interface
 
Enables the 16-Bit paralell interface
Const Lcd_enable_16bit = False
+
<pre>Const Lcd_enable_16bit = False</pre>
 +
 
  
 
Enable backlight control
 
Enable backlight control
Const Lcd_enable_backlight = False
+
<pre>Const Lcd_enable_backlight = False</pre>
 +
 
  
 
Use a timer to generate a PWM signal for the backlight instead of switching it on or off
 
Use a timer to generate a PWM signal for the backlight instead of switching it on or off
Const Lcd_enable_backlight_pwm = True
+
<pre>Const Lcd_enable_backlight_pwm = True</pre>
 +
 
  
 
ATMega only: select the timer to use for the PWM signal (XMega: automatic)
 
ATMega only: select the timer to use for the PWM signal (XMega: automatic)
Lcd_backlight_timer Alias Timer2
+
<pre>Lcd_backlight_timer Alias Timer2</pre>
  
invert backlight logic (1: off, 0: on)
 
Const Lcd_invert_backlight = False
 
  
Select the port of the display control pins (XMega: PortC-PortF, ATMega: for HW SPI)
+
Invert backlight logic (1: off, 0: on)
Const Lcd_ctrl_port = Portc
+
<pre>Const Lcd_invert_backlight = False</pre>
Const Lcd_ctrl_port = Portb
+
 
 +
 
 +
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)
 +
<pre>Const Lcd_ctrl_port = Portc (Portb)</pre>
 +
 
  
 
8 Bit mode data port
 
8 Bit mode data port
Const Lcd_data_port_1 = Portf
+
<pre>Const Lcd_data_port_1 = Portf (Portc)</pre>
Const Lcd_data_port_1 = Portc
+
 
  
 
16 Bit mode data port #2
 
16 Bit mode data port #2
Const Lcd_data_port_2 = Portd
+
<pre>Const Lcd_data_port_2 = Portd</pre>
 +
 
 +
 
 +
Port of the display reset signal
 +
<pre>Const Lcd_reset_port = Lcd_ctrl_port</pre>
  
Port where the display reset is connected to
 
Const Lcd_reset_port = Lcd_ctrl_port
 
  
 
Pin of the display reset signal
 
Pin of the display reset signal
Const Lcd_reset_pin = 0
+
<pre>Const Lcd_reset_pin = 0</pre>
 +
 
 +
 
 +
SPI mode pin assignments (HW SPI: fixed, SW SPI: any GPIO)
 +
<pre>Const Lcd_pin_dc = 1 (4)
 +
Const Lcd_pin_cs = 4 (0)
 +
Const Lcd_pin_sdo = 5 (2)
 +
Const Lcd_pin_clk = 7 (1)</pre>
  
SPI mode pin assignments
 
Const Lcd_pin_dc = 1
 
Const Lcd_pin_dc = 4
 
Const Lcd_pin_cs = 4
 
Const Lcd_pin_cs = 0
 
Const Lcd_pin_sdo = 5
 
Const Lcd_pin_sdo = 2
 
Const Lcd_pin_clk = 7
 
Const Lcd_pin_clk = 1
 
  
 
parallel (8/16 Bit) mode pin assignments
 
parallel (8/16 Bit) mode pin assignments
Const Lcd_pin_wr = 1
+
<pre>Const Lcd_pin_wr = 1
 
Const Lcd_pin_rd = 5
 
Const Lcd_pin_rd = 5
 
Const Lcd_pin_dc = 7
 
Const Lcd_pin_dc = 7
Const Lcd_pin_cs = 4
+
Const Lcd_pin_cs = 4</pre>
 +
 
  
 
Port of the backlight control signal
 
Port of the backlight control signal
Const Lcd_backlight_port = Lcd_ctrl_port
+
<pre>Const Lcd_backlight_port = Lcd_ctrl_port</pre>
 +
 
  
 
Pin of the backlight control signal
 
Pin of the backlight control signal
Const Lcd_pin_backlight = 0
+
<pre>Const Lcd_pin_backlight = 0 (6)</pre>
Const Lcd_pin_backlight = 6</pre>
+
 
  
 
== API ==
 
== API ==
<pre>Dim Lcd_screen_width As Word                                                    ' the actual max X and Y coordinates (after rotation)
+
the actual max X and Y coordinates (after rotation)
 +
<pre>Dim Lcd_screen_width As Word
 
Dim Lcd_screen_height As Word</pre>
 
Dim Lcd_screen_height As Word</pre>
  
<pre>Dim Lcd_digit_font As Bit                                                      'For reduced Digit font</pre>
 
  
<pre>' Initializes the control interface (paralell/serial), backlight control and the display
+
For reduced Digit font
Sub Lcd_init()</pre>
+
<pre>Dim Lcd_digit_font As Bit</pre>
  
 +
 +
Initializes the control interface (paralell/serial), backlight control and the display
 +
<pre>Sub Lcd_init()</pre>
 +
 +
 +
Indicates if the display is in sleep mode.
 
<pre>Dim Lcd_sleepmode As Bit</pre>
 
<pre>Dim Lcd_sleepmode As Bit</pre>
  
<pre>Sub Lcd_backlight(byval Value As Byte) </pre>
 
  
Sets the backlight value (0: Off, Standby On; 1-254: PWM, 255: On, Display Wakeup)   
+
Sets the backlight value (0: BL Off, Standby On; 1-254: PWM, 255: BL On, Display Wakeup)   
 +
<pre>Sub Lcd_backlight(byval Value As Byte)</pre>
 +
 
 +
 
 +
Smoothly dims the backlight (PWM only)
 
<pre>Sub Lcd_backlight_dim(byval Startvalue As Byte , Byval Endvalue As Byte , Byval Millisecs As Word)</pre>
 
<pre>Sub Lcd_backlight_dim(byval Startvalue As Byte , Byval Endvalue As Byte , Byval Millisecs As Word)</pre>
  
  
 +
Indicates the current rotation
 
<pre>Dim Lcd_rotation As Byte</pre>
 
<pre>Dim Lcd_rotation As Byte</pre>
  
  
 +
Sets the display rotation (0: 0° Portrait, 1: 90° Landscape, 2: 180° Portrait, 3: 270° Landscape, 4: 0° ...)
 
<pre>Sub Lcd_set_rotation(byval Rotation As Byte)</pre>
 
<pre>Sub Lcd_set_rotation(byval Rotation As Byte)</pre>
  
  
 +
Draws a filled rectangle, checks for the display boundaries
 
<pre>Sub Lcd_fill_rect(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color As Word)</pre>
 
<pre>Sub Lcd_fill_rect(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color As Word)</pre>
  
  
 +
Sets a single pixel.
 
<pre>Sub Lcd_set_pixel(byval X As Word , Byval Y As Word , Byval Color As Word)</pre>
 
<pre>Sub Lcd_set_pixel(byval X As Word , Byval Y As Word , Byval Color As Word)</pre>
  
  
 +
Draws a BIN picture from the internal program flash memory. Image has to be loaded with ''Restore'' before.
 
<pre>Sub Lcd_pic_flash(byval Xs As Word , Byval Ys As Word , Byval Width As Byte , Byval Height As Word)</pre>
 
<pre>Sub Lcd_pic_flash(byval Xs As Word , Byval Ys As Word , Byval Width As Byte , Byval Height As Word)</pre>
  
  
 +
Draws a BIN picture stored on an external SPI DataFlash [http://mat.midlight.eu/wiki/index.php/SPI_DataFlash_Library]
 
<pre>Sub Lcd_pic_spi(byval Xs As Word , Byval Ys As Word , Byval Width As Word , Byval Height As Word , Byval Address As Dword)</pre>
 
<pre>Sub Lcd_pic_spi(byval Xs As Word , Byval Ys As Word , Byval Width As Word , Byval Height As Word , Byval Address As Dword)</pre>
  
  
 +
Set to the start address of the free SRAM memory section, where BIN pics should be loaded to
 
<pre>Dim Lcd_ram_pics_free_ptr As Dword</pre>
 
<pre>Dim Lcd_ram_pics_free_ptr As Dword</pre>
  
  
 +
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.
 
<pre>Function Lcd_load_pic_flash2ram(byval Width As Word , Byval Height As Word) As Word</pre>
 
<pre>Function Lcd_load_pic_flash2ram(byval Width As Word , Byval Height As Word) As Word</pre>
  
  
 +
Draws a BIN picture from the SRAM memory.
 
<pre>Sub Lcd_pic_ram(byval Xs As Word , Byval Ys As Word , Byval Width As Word , Byval Height As Word , Byval Address As Dword)</pre>
 
<pre>Sub Lcd_pic_ram(byval Xs As Word , Byval Ys As Word , Byval Width As Word , Byval Height As Word , Byval Address As Dword)</pre>
  
  
 +
Draws a BGF coded picture from the program flash memory.
 
<pre>Sub Lcd_pic_bgf(byval Xoffset As Word , Byval Yoffset As Word)</pre>
 
<pre>Sub Lcd_pic_bgf(byval Xoffset As Word , Byval Yoffset As Word)</pre>
  
  
 +
Clears the screen.
 
<pre>Sub Lcd_clear(byval Color As Word) </pre>
 
<pre>Sub Lcd_clear(byval Color As Word) </pre>
  
  
 +
Inverts the screen's colors
 
<pre>Sub Lcd_invert(byval Inverted As Byte )</pre>
 
<pre>Sub Lcd_invert(byval Inverted As Byte )</pre>
  
  
 +
Loads the font, following ''Lcd_text'' commands will use it. You need to call ''Restore [Font]'' before.
 +
<pre>Sub Lcd_loadfont()</pre>
 +
 +
 +
Draws a fixed-font text on the screen.
 
<pre>Sub Lcd_text(byval S As String , Byval Xoffset As Word , Byval Yoffset As Word , Byval Forecolor As Word , Byval Backcolor As Word)</pre>
 
<pre>Sub Lcd_text(byval S As String , Byval Xoffset As Word , Byval Yoffset As Word , Byval Forecolor As Word , Byval Backcolor As Word)</pre>
  
  
 +
Draws a line between two points
 
<pre>Sub Lcd_line(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color As Word)</pre>
 
<pre>Sub Lcd_line(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color As Word)</pre>
  
  
 +
Draws a line with color transition between two points
 
<pre>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)</pre>
 
<pre>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)</pre>
  
  
 +
Draws a circle
 
<pre>Sub Lcd_circle(byval Xcenter As Word , Byval Ycenter As Word , Byval Radius As Word , Byval Color As Word)</pre>
 
<pre>Sub Lcd_circle(byval Xcenter As Word , Byval Ycenter As Word , Byval Radius As Word , Byval Color As Word)</pre>
  
  
 +
Draws a filled circle
 
<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 a rectangle
 
<pre>Sub Lcd_rect(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color As Word)</pre>
 
<pre>Sub Lcd_rect(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Color As Word)</pre>
  
Zeile 143: Zeile 186:
 
== Electrical connection ==
 
== Electrical connection ==
 
[[File:lcd-connections.jpg|width|600px|LCD connection schematic]]
 
[[File:lcd-connections.jpg|width|600px|LCD connection schematic]]
 +
  
 
=== ATXMega-A1 Xplained connections ===
 
=== ATXMega-A1 Xplained connections ===

Version vom 16. April 2015, 09:32 Uhr

Overview

ILI9341 driver library for ATXMega/ATMega with hardware/software SPI or 8/16 bit parallel mode. Includes Backlight control with a GPIO or a PWM signal generated by a timer. Supports screen rotation (4 directions). Most of the graphics routines are optimized for speed with inline Assembler.


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)


API

the actual max X and Y coordinates (after rotation)

Dim Lcd_screen_width As Word
Dim Lcd_screen_height As Word


For reduced Digit font

Dim Lcd_digit_font As Bit


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

Sub Lcd_init()


Indicates if the display is in sleep mode.

Dim Lcd_sleepmode As Bit


Sets the backlight value (0: BL Off, Standby On; 1-254: PWM, 255: BL On, Display Wakeup)

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)


Indicates the current rotation

Dim Lcd_rotation As Byte


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)


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 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)


Clears the screen.

Sub Lcd_clear(byval Color As Word) 


Inverts the screen's colors

Sub Lcd_invert(byval Inverted As Byte )


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)


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 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)


Sample

Sample project from the video

Electrical connection

LCD connection schematic


ATXMega-A1 Xplained connections

This Software is Donationware. <paypal>1</paypal> See here for more informations


Download