ILI9341 TFT-Display mit MSP430

ILI9341_00Bis jetzt finden sich hier auf der Seite nur Beispielprogramme für monochrome Displays bzw. LCDs. Da ich schon länger mal mal mit einem “richtigen” Display arbeiten wollte, also etwas in Farbe programmieren, habe ich mir auf Ebay ein kleines 2.2″ TFT-Display, mit einem ILI9341 Controller, bestellt. Das Display hat zu dem Kaufzeitpunkt mal gerade nur 5,69€ gekostet. Der aktuelle Preis von 6,00€ ist narülich auch noch super billig. Die Ansteuerung des Displays hat sich als ziemlich einfach gestaltet. Es kann direkt per SPI angesteuert werden und es gibt ein vernünftiges Datenblatt mit allen Informationen zur Initialisierung etc. In den letzten Tagen habe ich eine kleine Demo für das ILI9341 Display geschrieben (in Verbindung mit einem MSP430G2553).

Video

Display-Infos

Aus den Ebay-Angaben:

  • Maße: 2.2″
  • Punkt Matrix: QVGA 240 x 320 Punkte 
  • Schnittstelle: 4-Draht SPI
  • Farbtiefe: 262K/65K (24bit/16bit)
  • Display: 67mm(L)*40mm(B)*4mm(D)
  • Aktivbereich: 47.5mm(L)x36.5mm(B)
  • 4 LEDs

Download ILI9341 Documentation

Bilder

ILI9341_01ILI9341_02ILI9341_03ILI9341_04

Schaltplan

Alle 4 LEDs sind parallel geschaltet. Für eine LED gilt: If=15mA, Vf=3,2V. Somit beträgt der gesamte Strom 60mA. Da ich nicht die genauen Widerstandswerte auf Lager hatte, habe ich einfach einen 150ohm Vorwiderstand genommen, somit fließt ein Gesamtstrom von etwa 14,22mA (5V -> 150ohm -> LEDs). Die Helligkeit war für meine Zwecke ausreichend. Da sich ein richtiger Schaltplan hier nicht wirklich lohnt, gibt es also nur die Pinbelegung aus dem Code:

#define CS              0x0010        // chip select at P1.4
#define SDIN            0x0080        // data in at P1.7
#define SCLK            0x0020        // clk at P1.5
#define DC              0x0040        // Data/Cmd at P1.6
#define RES             0x0001        // reset at P1.0

Source-Code

Kompletter Source-Code (07.12.2014): SOURCE-CODE

Ein Ausschnitt der Initialisierung:

init_display.c

/*******************************
 *          __                   
 *         /\ \                  
 *  __  _  \_\ \     __    ___   
 * /\ \/'\ /'_' \  /'__'\ /'___\ 
 * \/>  <//\ \ \ \/\  __//\ \__/ 
 *  /\_/\_\ \___,_\ \____\ \____\
 *  \//\/_/\/__,_ /\/____/\/____/
 * 
 *  Author: declis (xdec.de)
 ********************************/ 

#include <msp430g2553.h>
#include "typedef.h"
#include "lib_lcd.h"
#include "delay.h"

// see init_display.h for command description
const uchar init_cmd[]={0xCB,0xCF,0xE8,0xEA,0xED,0xF7,0xC0,0xC1,0xC5,0xC7,0x36,0x3A,0xB1,0xB6,0xF2,0x26,0xE0,0xE1};
const uchar init_data_count[]={5,3,3,2,4,1,1,1,2,1,1,1,2,3,1,1,15,15};
const uchar init_data[]={0x39,0x2C,0x00,0x34,0x02,
						0x00,0xC1,0x30,
						0x85,0x00,0x78,
						0x00,0x00,
						0x64,0x03,0x12,0x81,
						0x20,
						0x23,
						0x10,
						0x3E,0x28,
						0x86,
						0x88,
						0x55,
						0x00,0x18,
						0x08,0x82,0x27,
						0x00,
						0x01,
						0x0F,0x31,0x2B,0x0C,0x0E,0x08,0x4E,0xF1,0x37,0x07,0x10,0x03,0x0E,0x09,0x00,
						0x00,0x0E,0x14,0x03,0x11,0x07,0x31,0xC1,0x48,0x08,0x0F,0x0C,0x31,0x36,0x0F};
						
void init_LCD(uint b_color)
{
	uchar byte=0,bit_num=0,h_index=0,w_index=0;

	P1OUT|=RES;
	wait_ms(10);
	P1OUT&=~RES;
	wait_ms(10);
	P1OUT|=RES;
	wait_ms(100);
	
	while(byte<sizeof(init_cmd))						// byte is init_cmd index
	{
		set_instruction(0,init_cmd[byte++]);			
		while(h_index<init_data_count[bit_num])			// h_index is size of init_data command part counter
		{												// bit_num is init_data_count index
			set_instruction(1,init_data[w_index++]);	// w_index is init_data index
			h_index++;
		}
		bit_num++;
		h_index=0;
	}
    
	set_instruction(0,0x11); 	// SLEEP OUT
	wait_ms(120);				// 120ms needed (see description of sleep-out-cmd)
	
	MEM_WRITE;
    fill_display(lcd_width,lcd_height,b_color);
    DISPLAY_ON;
    MEM_WRITE;
}

void init_USCI(void)
{
	P1DIR|=RES+DC+CS;
	P1OUT&=~RES+DC+CS;
	
	P1SEL|=SDIN+SCLK;
	P1SEL2|=SDIN+SCLK;
	
  	UCB0CTL1|=UCSWRST;					// USCI in reset state
  	// SPI Master, 8bit, MSB first, synchronous mode
  	UCB0CTL0|=UCMST+UCSYNC+UCCKPH+UCMSB;		
  	UCB0CTL1|=UCSSEL_2;					// USCI CLK-SRC=SMCLK=~8MHz
  	UCB0CTL1&=~UCSWRST;					// USCI released for operation
  	IE2|=UCB0TXIE;						// enable TX interrupt
  	IFG2&=~UCB0TXIFG;
  	_EINT();							// enable interrupts
}

#pragma INTERRUPT (USCI)
#pragma vector=USCIAB0TX_VECTOR
void USCI(void)
{
	P1OUT|=CS;				// transmission done
	IFG2&=~UCB0TXIFG;		// clear TXIFG
}	

init_display.h

/*******************************
 *          __                   
 *         /\ \                  
 *  __  _  \_\ \     __    ___   
 * /\ \/'\ /'_' \  /'__'\ /'___\ 
 * \/>  <//\ \ \ \/\  __//\ \__/ 
 *  /\_/\_\ \___,_\ \____\ \____\
 *  \//\/_/\/__,_ /\/____/\/____/
 * 
 *  Author: declis (xdec.de)
 ********************************/ 

#ifndef INIT_DISPLAY_H_
#define INIT_DISPLAY_H_

void init_LCD(uint);
void init_USCI(void);

/*
	set_instruction(0,0xCB);	// POWER CONTROL A
	set_instruction(1,0x39);	// 1. (default)
	set_instruction(1,0x2C);	// 2. (default)
	set_instruction(1,0x00);	// 3. (default)
	set_instruction(1,0x34);	// 4. (Vcore Controll: 1.55V, default)
	set_instruction(1,0x02);	// 5. (DDVDH: 5.8V, default)
    
	set_instruction(0,0xCF);	// POWER CONTROL B
	set_instruction(1,0x00);	// 1. (default)
	set_instruction(1,0xC1);	// 2. (PC&EQ operation for power saving enabled), 0x81 def.
	set_instruction(1,0x30);	// 3. (default)
    
	set_instruction(0,0xE8);	// DRIVER TIMING CONTROL A
	set_instruction(1,0x85);	// 1. (gate driver non-overlap timing control), 0x84 def.
	set_instruction(1,0x00);	// 2. (EQ timing control), 0x11 def.
	set_instruction(1,0x78);	// 3. (pre-charge timing control), 0x7A def.
    
	set_instruction(0,0xEA);	// DRIVER TIMING CONTROL A
	set_instruction(1,0x00);	// 1. (gate driver timing control), 0x66 def.
	set_instruction(1,0x00);	// 2. (default)
    
	set_instruction(0,0xED);	// POWER ON SEQUENCE CONTROL
	set_instruction(1,0x64);	// 1. (soft start control), 0x55 def.
	set_instruction(1,0x03);	// 2. (power on sequence control), 0x01 def.
	set_instruction(1,0x12);	// 3. (power on sequence control), 0x23 def.
	set_instruction(1,0x81);	// 4. (DDVDH enhance mode(only for 8 external capacitors)), enabled, 0x01 def.
    
	set_instruction(0,0xF7);	// PUMP RATION CONTROL
	set_instruction(1,0x20);	// 1. (ratio control)
    
	set_instruction(0,0xC0); 	// POWER CONTROL 1
	set_instruction(1,0x23); 	// 1. (set the GVDD level, 4.6V), 0x21 def.
    
	set_instruction(0,0xC1); 	// POWER CONTROL 2
	set_instruction(1,0x10); 	// 1. (sets the factor used in the step-up circuits) default
    
	set_instruction(0,0xC5); 	// VCOM CONTROL 1
	set_instruction(1,0x3e); 	// 1. (VCOMH voltage = 5.85V), 0x31 def.
	set_instruction(1,0x28);	// 2. (VCOML voltage = -1.50V), 0x3C def.
    
	set_instruction(0,0xC7); 	// VCOM CONTROL 2
	set_instruction(1,0x86); 	// 1. (VCOM offset voltage), 0xC0 def.
    
	set_instruction(0,0x36); 	// MEMORY ACCESS CONTROL
	set_instruction(1,0x80); 	// 1. ( ), 0x00 def.
    
	set_instruction(0,0x3A);	// COLMOD: PIXEL FORMAT SET
	set_instruction(1,0x55);	// 1. (sets the pixel format for the RGB image data used by the interface, 16bits/pixel)
    
	set_instruction(0,0xB1);	// FRAME RATE CONTROL (IN NORMAL MODE / FULL COLORS)
	set_instruction(1,0x00);	// 1. (division ratio for internal clocks when Normal mode), default
	set_instruction(1,0x18);	// 2. (frame frequency, 79Hz), 0x1B def. (70Hz)
    
	set_instruction(0,0xB6); 	// DISPLAY FUNCTION CONTROL
	set_instruction(1,0x08);	// 1. (), 0x0A def.
	set_instruction(1,0x82);	// 2. (default)
	set_instruction(1,0x27);	// 3. (default)
    
	set_instruction(0,0xF2); 	// 3GAMMA CONTROL
	set_instruction(1,0x00);	// 1. (disabled), 0x02 def.
    
	set_instruction(0,0x26);	// GAMMA SET
	set_instruction(1,0x01);	// 1. (default)
    
	set_instruction(0,0xE0); 	// POSITIVE GAMMA CORRECTION
	set_instruction(1,0x0F);	// 1.
	set_instruction(1,0x31);	// 2.
	set_instruction(1,0x2B);	// 3.
	set_instruction(1,0x0C);	// 4.
	set_instruction(1,0x0E);	// 5.
	set_instruction(1,0x08);	// 6.
	set_instruction(1,0x4E);	// 7.
	set_instruction(1,0xF1);	// 8.
	set_instruction(1,0x37);	// 9.
	set_instruction(1,0x07);	// 10.
	set_instruction(1,0x10);	// 11.
	set_instruction(1,0x03);	// 12.
	set_instruction(1,0x0E);	// 13.
	set_instruction(1,0x09);	// 14.
	set_instruction(1,0x00);	// 15.
    
	set_instruction(0,0xE1); 	// NEGATIVE GAMMA CORRECTION
	set_instruction(1,0x00);	// 1.
	set_instruction(1,0x0E);	// 2.
	set_instruction(1,0x14);	// 3.
	set_instruction(1,0x03);	// 4.
	set_instruction(1,0x11);	// 5.
	set_instruction(1,0x07);	// 6.
	set_instruction(1,0x31);	// 7.
	set_instruction(1,0xC1);	// 8.
	set_instruction(1,0x48);	// 9.
	set_instruction(1,0x08);	// 10.
	set_instruction(1,0x0F);	// 11.
	set_instruction(1,0x0C);	// 12.
	set_instruction(1,0x31);	// 13.
	set_instruction(1,0x36);	// 14.
	set_instruction(1,0x0F);	// 15.
*/

#endif /*INIT_DISPLAY_H_*/

 

2 thoughts on “ILI9341 TFT-Display mit MSP430

  1. Shivaji S Nawatake

    Ver 14 Worked very well on custom built MSP430G2553 28 pin board. I must appreciate your contribution, very much thankful to you all those contributed. Was looking for couple of weeks and and for some reason many other did not work well.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

This site uses Akismet to reduce spam. Learn how your comment data is processed.