[Original] [serialization]. Easy digital photo frame based on systems-nioii sbte part (software part)-TFT-LCD (ili9325 Controller) Drive

Source: Internet
Author: User
ArticleDirectory
    • Step 1 Add the ili9325 folder to the app path
    • Step 2. Compile the driver File
    • Step 3 test the ili9325 driver
Prepare materials

[Sorting]. ili9325 TFT driver Chinese materials

Write driver Program Step 1 Add the ili9325 folder to the app path

Step 2. Compile the driver File

Time is tight, so I will post it.Code.

Code 2.1 ili932x. h

# Ifndef ili932x_h _ # define ili932x_h _ // # include "my_types.h" # include "my_regs.h" // # define white 0 xFFFF # define black 0x0000 # define blue 0xblu001f # define E2 0x051f # define red 0xf800 # define magenta region # define green 0x07e0 # define cyan region # define yellow 0xffe0 // # define id_am 110 // # define policili_db-> direction = 0xff # define db_ I _en ili_db-> direction = 0x00 // void ili_wrdb_2x8b (u8 DH, u8 dl); void ili_wrcmd (u8 DH, u8 dl); void ili_wrdata (u8 DH, u8 dl); void ili_wrreg (u8 cmd, b2data ); void ili_wrdb_16b (2010data); // void ili_delayms (u32 N); void ili_initial (void); void ili_setcursor (u8 X, 2010y); void ili_setdisparea (2010x0, y0, u8 xlength, 162ylength, 162xoffset, 163yoffset); void ili_clearscreen (u32 bcolor); // void ili_plotpoint (u8 X, 163y, and 163color ); void ili_plotpixel, u32 fcolor, u32 bcolor); void ili_putgb_16x16, uc8 * s, u32 fcolor, u32 bcolor); // void ili_dispcolorbar (void); // # endif/* ili932x_h _*/

Note 19th ~ 20 rows. Define two macros to manipulate the direction of the Eight-bit dB bidirectional bus.

 

Code 2.2 ili_932x.c

# Include "ili932x. H "# include" unistd. H "// usleep () # include" ascii_8x16.h "// ASCII code font # include" gb16.h "// Chinese Character Font // 8-bit bus mode, two write operations are performed to write the void ili_wrdb_2x8b (u8 DH, u8 dl) {ili_db-> DATA = DH; ili_nwr = 0; ili_nwr = 1; ili_db-> DATA = dl; ili_nwr = 0; ili_nwr = 1;} // write command void ili_wrcmd (u8 DH, u8 dl) {ili_rs = 0; ili_wrdb_2x8b (DH, DL);} // write data void ili_wrdata (u8 DH, u8 dl) {ili_rs = 1; ili_wrdb_2x8b (DH, DL);} // write data to the DB bus Vo Id ili_wrdb_16b (2010data) {ili_wrdata (data> 8, data);} // write register void ili_wrreg (u8 cmd, 2010data) {ili_wrcmd (0x00, CMD); ili_wrdb_16b (data);} // delay msvoid ili_delayms (u32 N) {usleep (N * 1000);} // ili93525 initialize void ili_initial (void) {// hardware reset ili_nrst = 0; ili_delayms (1); ili_nrst = 1; // enable chip selection and output the following command: ili_ncs = 0; db_o_en; // ili_wrreg (0xe3, 0x3008); ili_wrreg (0xe7, 0x0012); ili_wrreg (0xef, 0x1231); // set the Interna L timing ili_wrreg (0x01, 0x0000); // set ss and Sm bit ili_wrreg (0x02, 0x0700 ); // set 1 line inversion // screen rotation control # If id_am = 000 ili_wrreg (0x03, 0x1000); // tri = 0, DFM = X, BGR = 0, hwm = 0, org = 0, I/D [1:0] = 00, am = 0 # Elif id_am = 001 ili_wrreg (0x03, 0x1008); // tri = 0, DFM = x, BGR = 0, hwm = 0, org = 0, I/D [1:0] = 00, AM = 0 # Elif id_am = 010 ili_wrreg (0x03, 0x1010); // tri = 0, DFM = x, BGR = 0, hwm = 0, org = 0, I/D [1:0] = 01, AM = 0 # Elif id_am = 011 ili_wrreg (0x03, 0x1018); // tri = 0, DFM = x, BGR = 0, hwm = 0, org = 0, I/D [1:0] = 01, am = 1 # Elif id_am = 100 ili_wrreg (0x03, 0x1020); // tri = 0, DFM = x, BGR = 0, hwm = 0, org = 0, I/D [1:0] = 10, am = 0 # Elif id_am = 101 ili_wrreg (0x03, 0x1028); // tri = 0, DFM = x, BGR = 0, hwm = 0, org = 0, I/D [1:0] = 10, AM = 1 # Elif id_am = 110 ili_wrreg (0x03, 0x1030); // tri = 0, DFM = x, BGR = 0, hwm = 0, org = 0, I/D [1:0] = 11, am = 0 # Elif id_a M = 111 ili_wrreg (0x03, 0x1038); // tri = 0, DFM = x, BGR = 0, hwm = 0, org = 0, i/D [1:0] = 11, am = 1 # endif ili_wrreg (0x04, 0x0000); // resize register ili_wrreg (0x08, 0x0404 ); // set the back porch and front porch ili_wrreg (0x09, 0x0000); // set non-display area refresh cycle ISC [] ili_wrreg (0x0a, 0x0000); // fmark function ili_wrreg (0x0c, 0x0000); // RGB interface setting ili_wrreg (0x0d, 0x0000); // Frame Marker position ili_wrreg (0x0f, 0x0000); // RGB interface polarity // power on sequence vghvgl ili_wrreg (0x10, 0x0000); // sap, BT [], AP, dstb, SLP, STB ili_wrreg (0x11, 0x0007); // DC1 [], dc0 [], VC [] ili_wrreg (0x12, 0x0000); // vreg1out voltage ili_wrreg (0x13, 0x1300 ); // vdv [] for vcom amplitude ili_wrreg (0x07, 0x0001); ili_delayms (50); // dis-charge capacitor power voltage ili_wrr EG (0x10, 0x1590); // sap, BT [], AP, dstb, SLP, STB ili_wrreg (0x11, 0x0227 ); // DC1 [2: 0], dc0 [2: 0], VC [2: 0] ili_delayms (50); ili_wrreg (0x12, 0x001e); // internal reference voltage = VCI; ili_delayms (50); ili_wrreg (0x13, 0x1500); // set vdv [] for vcom ampl1_ili_wrreg (0x29, 0x0026 ); // set VCM [] for vcomh ili_wrreg (0x2b, 0x000f); // set frame rate ili_delayms (50); ili_wrreg (0x20, 0x0000 ); Ili_wrreg (0x21, 0x013f); // start position of gram # If id_am = 000 ili_wrreg (0x20, 0x00ef); ili_wrreg (0x21, 0x013f ); # Elif id_am = 001 ili_wrreg (0x20, 0x00ef); ili_wrreg (0x21, 0x013f); # Elif id_am = 010 ili_wrreg (0x20, 0x0000); ili_wrreg (0x21, 0x013f); # Elif id_am = 011 ili_wrreg (0x20, 0x0000); ili_wrreg (0x21, 0x013f ); # Elif id_am = 100 ili_wrreg (0x20, 0x00ef); ili_wrreg (0x21, 0x0000); # Elif id_am = 101 ili_wrreg (0x20, 0x 00ef); ili_wrreg (0x21, 0x0000); # Elif id_am = 110 ili_wrreg (0x20, 0x0000); ili_wrreg (0x21, 0x0000); # Elif id_am = 111 ili_wrreg (0x20, 0x0000); ili_wrreg (0x21, 0x0000 ); # endif // adjust the gamma curve ili_wrreg (0x30, 0x0007); ili_wrreg (0x31, 0x0007); ili_wrreg (0x32, 0x0107); ili_wrreg (0x35, 0x0206); ili_wrreg (0x36, 0x0406); ili_wrreg (0x37, 0x0101 ); ili_wrreg (0x38, 0x0101); ili_wrreg (0x39, 0x0207); ili _ Wrreg (0x3c, 0x0504); ili_wrreg (0x3d, 0x0806); // set gram area ili_wrreg (0x50, 0x0000 ); // horizontal gram start address ili_wrreg (0x51, 0x00ef); // horizontal gram end address ili_wrreg (0x52, 0x0000 ); // vertical gram start address ili_wrreg (0x53, 0x013f); // vertical gram start address ili_wrreg (0x60, 0x2700 ); // gate Scan Line ili_wrreg (0x61, 0x0001); // NDL, VLE, rev ili_wrreg (0x6a, 0x0000 );// Set scrolling line // partial display control ili_wrreg (0x80, 0x0000); ili_wrreg (0x81, 0x0000); ili_wrreg (0x82, 0x0000); ili_wrreg (0x83, 0x0000); ili_wrreg (0x84, 0x0000); ili_wrreg (0x85, 0x0000 ); // panel control ili_wrreg (0x90, 0x0010); ili_wrreg (0x92, 0x0600); ili_wrreg (0x93, 0x0003 ); ili_wrreg (0x95, 0x0110); ili_wrreg (0x97, 0x0000); ili_wrreg (0x98, 0x0000); ili_wrreg (0x07, 0x0173); // 262 K col Or and display on // turn off the slice and select ili_ncs = 1;} // set cursorvoid ili_setcursor (u8 X, 2010y) {ili_wrreg (0x20, X ); ili_wrreg (0x21, Y);} // set the display region void ili_setdisparea (x0, y0, u8 xlength, ylength, xoffset, yoffset) {# If id_am = 000 ili_setcursor (x0 + xLength-1 + xoffset, y0 + yLength-1 + yoffset); # Elif id_am = 001 ili_setcursor (x0 + xLength-1 + xoffset, y0 + yLength-1 + yoffset); # Elif id_am = 010 ili_setcursor (x0 + Xoffset, y0 + yLength-1 + yoffset); # Elif id_am = 011 ili_setcursor (x0 + xoffset, y0 + yLength-1 + yoffset ); # Elif id_am = 100 ili_setcursor (x0 + xLength-1 + xoffset, y0 + yoffset); # Elif id_am = 101 ili_setcursor (x0 + xLength-1 + xoffset, y0 + yoffset ); # Elif id_am = 110 ili_setcursor (x0 + xoffset, y0 + yoffset); # Elif id_am = 111 ili_setcursor (x0 + xoffset, y0 + yoffset ); # endif ili_wrreg (0x50, x0 + xoffset); // level gram start position ili_wrreg (0x5 1, x0 + xLength-1 + xoffset); // horizontal gram termination position ili_wrreg (0x52, y0 + yoffset); // vertical gram start position ili_wrreg (0x53, y0 + yLength-1 + yoffset); // vertical gram termination position ili_wrcmd (0x00, 0x22);} // clear screen void ili_clearscreen (u32 bcolor) {u32 I; ili_ncs = 0; db_o_en; ili_setdisparea (0, 0,240,320, 0, 0); for (I = 0; I <76800; I ++) ili_wrdb_16b (bcolor ); ili_ncs = 1;} // image point (single operation) void ili_plotpoint (u8 X, b2y, b2color) {ili_ncs = 0; db_o_en; ili _ Setcursor (x, y); ili_wrcmd (0x00, 0x22); ili_wrdb_16b (color); ili_ncs = 1;} // painting point (part of continuous operation) void ili_plotpixel (u8 X, 2010y, 2010color) {ili_setcursor (x, y); ili_wrcmd (0x00, 0x22); ili_wrdb_16b (color );} // draw a big dot void ili_plotbigpoint (u8 X, 2010y, 2010color) {u8 I, j; ili_ncs = 0; db_o_en; for (I = 0; I <3; I ++) {for (j = 0; j <3; j ++) ili_plotpixel (x + I, Y + J, color);} ili_ncs = 1 ;} // print the ASCII code (8x16) void ili_putascii _ 8x16 (2010x, 2010y, uc8 C, u32 fcolor, u32 bcolor) {u32 I, j; u8 temp; ili_ncs = 0; db_o_en; ili_setdisparea (X, y, 8, 16, 0, 0); for (I = 0; I <16; I ++) {temp = ascii_8x16_tab [C * 16 + I]; for (j = 0; j <8; j ++) {If (temp & 0x80) = 0x80) ili_wrdb_16b (fcolor ); else ili_wrdb_16b (bcolor); temp <= 1 ;}} ili_ncs = 1 ;}// print Chinese characters (16x16) void ili_putgb16 (x, y, uc8 C [2], u32 fcolor, u32 bcolor) {u32 I, j, k; b2te MP; ili_ncs = 0; db_o_en; ili_setdisparea (X, Y, 16, 16, 0, 0); For (k = 0; k <64; k ++) // 64 indicates the number of self-built Chinese character libraries, and the internal code {If (gb16 [K]. index [0] = C [0]) & (gb16 [K]. index [1] = C [1]) {for (I = 0; I <32; I ++) {temp = gb16 [K]. MSK [I]; for (j = 0; j <8; j ++) {If (temp & 0x80) = 0x80) ili_wrdb_16b (fcolor ); else ili_wrdb_16b (bcolor); temp <= 1 ;}}} ili_ncs = 1 ;}// print the string void ili_putstring (X, Y, uc8 * s, u32 fcolor, U3 2 bcolor) {u8 L = 0; while (* s! = '\ 0') {If (* S <0x80) {ili_putascii_8x16 (x + L * 8, Y, * s, fcolor, bcolor); s ++; l ++;} else {ili_putgb16 (x + L * 8, Y, (u8 *) s, fcolor, bcolor); S + = 2; L + = 2 ;}}// color bar test void ili_dispcolorbar (void) {2010v, H; ili_ncs = 0; db_o_en; ili_setdisparea (0, 0,240,320, 0, 0 ); for (H = 0; H <240; H ++) {for (V = 0; v <40; V ++) ili_wrdb_16b (white );} for (H = 0; H <240; H ++) {for (V = 40; v <80; V ++) ili_wrdb_16b (black );} for (H = 0; H <240; H ++) {for (V = 80; v <120; V ++) ili_wrdb_16b (blue );} for (H = 0; H <240; H ++) {for (V = 120; v <160; V ++) ili_wrdb_16b (red );} for (H = 0; H <240; H ++) {for (V = 160; v <200; V ++) ili_wrdb_16b (magenta );} for (H = 0; H <240; H ++) {for (V = 200; v <240; V ++) ili_wrdb_16b (green );} for (H = 0; H <240; H ++) {for (V = 240; v <280; V ++) ili_wrdb_16b (Cyan );} for (H = 0; H <240; H ++) {for (V = 280; v <320; V ++) ili_wrdb_16b (yellow);} ili_ncs = 1 ;}

Note the following:

1. For the void ili_initial (void) hardware reset in the initialization function, nrst must be pulled down for a long time and then pulled up. Here, 1 ms is used; otherwise, white screen may occur.

 
Ili_nrst = 0; ili_delayms (1); ili_nrst = 1;

2. To reduce the number of two-way dB bus direction switches and enable or disable the NCs option, only one DB direction is set in each operation and only one DB direction is selected. For example, in the Void ili_initial (void) in the initialization function.

 
// Open the slice selection and output the ili_ncs = 0; db_o_en;
 
// Select ili_ncs = 1 to disable the slice;

Therefore, pay special attention to writing one set or one register before and after, or writing one or more sets of data before and after the DB bus, only one set dB direction and turn on and off the slice selection action. In addition, do not keep the NCs low forever, wasting power. It is best to turn it on when it is used, and turn it off when it is not used.

3. When you repeat an action consecutively, you can also execute 2nd records. For example, 246th ~ Row 3: references to the ili_plotpixel () function.

Step 3 test the ili9325 driver

Code 3.1 main. c

# Include <stdio. h> // printf () # include <unistd. h> // usleep () # include "my_types.h" // data type # include "debug. H "// debug # include" sd_card.h "// SD card # include" ili932x. H "// ili9325 // # define enable_app_debug // turn on debug message # ifdef enable_app_debug # define app_debug (x) debug (x) # else # define app_debug (X) # endifint main (void) {ili_initial (); // initialize ili9325 ili_dispcolorbar (); // color bar test while (1); Return 0 ;}

The test result is as follows (50 ¥ camera shot, let's take a look ).

 

Source code download

LCD _at_nios_nii_part.zip

Directory

1 [original] [serialization]. A simple digital photo frame based on FPGA-Quartus II (hardware)

2 [original] [serialization]. Simple Digital Photo Frame Based on the System-nioii sbte part (software part)-Configuration

3 [original] [serialization]. Simple Digital Photo Frame Based on FPGA-nioii sbte part (software part)-SD card (SPI mode) Driver

4 [original] [serialization]. Easy digital photo frame based on systems-nioii sbte part (software part)-TFT-LCD (ili9325 Controller) Drive

5 [original] [serialization]. A simple digital photo frame based on FPGA-nioii sbte part (software part)-read image files from the SD card and then display on the TFT-LCD

6 [original] [serialization]. Simple Digital Photo Frame Based on the System-nioii sbte part (software part)-Optimization

7 [original] [serialization]. Easy Digital Photo Frame Based on FPGA-nioii sbte part (software part)-ads7843 touch screen driver test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.