program MyProject ' TFT display connections dim TFT_DataPort as byte at LATD dim TFT_WR as sbit at LATE2_bit dim TFT_RD as sbit at LATG13_bit dim TFT_CS as sbit at LATE4_bit dim TFT_RS as sbit at LATE3_bit dim TFT_RST as sbit at LATG12_bit dim TFT_DataPort_Direction as byte at TRISD dim TFT_WR_Direction as sbit at TRISE2_bit dim TFT_RD_Direction as sbit at TRISG13_bit dim TFT_CS_Direction as sbit at TRISE4_bit dim TFT_RS_Direction as sbit at TRISE3_bit dim TFT_RST_Direction as sbit at TRISG12_bit ' End of TFT display connections dim TFT_ID as word 'tft identificator dim ii as byte const SCREEN_HEIGHT as word = 320 SCREEN_WIDTH as word = 240 const G_BLACK as word = 0x0000 G_RED as word = 0xf800 G_GREEN as word = 0x07e0 G_YELLOW as word = 0xffe0 G_BLUE as word = 0x001f G_MAGENTA as word = 0xf81f G_CYAN as word = 0x07ff G_WHITE as word = 0xffff sub procedure Delay(dim Argument as word) dim n as word for n=0 to Argument asm nop end asm next n end sub sub procedure TFT_Reset() TFT_RST=1 'reset disp delay_ms(10) TFT_RST=0 delay_ms(10) TFT_RST=1 'end reset delay_ms(50) 'nessecary end sub sub procedure TFT_Write_Com(dim MyData as word) LATD=0000 TFT_CS=0 'select LCD TFT_RD=1 TFT_RS=0 'send comand TFT_WR=0 LATD=MyData 'Delay(1) TFT_WR=1 TFT_RS=1 TFT_CS=1 end sub sub procedure TFT_Write_Dat(dim MyData as word) TFT_CS=0 'select LCD TFT_RS=1 TFT_RD=1 TFT_WR=1 TFT_WR=0 LATD=MyData 'Delay(1) TFT_WR=1 TFT_RS=1 TFT_CS=1 end sub sub procedure TFT_Write_Register(dim Registr as word, dim Param as word) '************************************************************************ '** ** '** nCS ----\__________________________________________/------- ** '** RS ------\____________/----------------------------------- ** '** nRD ------------------------------------------------------- ** '** nWR --------\_______/--------\_____/----------------------- ** '** DB[0:15] ---------[index]----------[data]----------------------- ** '** ** '************************************************************************/ TRISD=0x0000 LATD=0 TFT_CS=0 'select LCD TFT_RS=0 'send comand TFT_RD=1 TFT_WR=0 LATD=Registr 'delay(1) TFT_WR=1 TFT_RS=1 'send param 'Delay(1) TFT_WR=0 LATD=Param 'delay(1) TFT_WR=1 TFT_CS=1 end sub sub procedure TFT_Read_ID() ''//======================================================================== ''// ** ** ''// ** nCS ----\__________________________________________/------- ** ''// ** RS ------\____________/----------------------------------- ** ''// ** nRD -------------------------\_____/--------------------- ** ''// ** nWR --------\_______/-------------------------------------- ** ''// ** DB[0:15] ---------[index]----------[data]----------------------- ** ''// ** ** ''//======================================================================== dim i as word TRISD=0x0000 PORTD=0x0000 TFT_CS=1 TFT_RS=1 TFT_RD=1 TFT_WR=1 LATD=$FFFF TFT_RST=1 'reset disp delay_ms(10) TFT_RST=0 delay_ms(10) TFT_RST=1 'end reset delay_ms(50) 'nessecary 'send registr TFT_WR=1 TFT_CS=0 TFT_RD=1 TFT_RS=0 TFT_WR=0 delay_us(1) LATD=00 delay_us(1) TFT_WR=1 TFT_RS=1 Delay(1) TRISD=0xFFFF PORTD=0x0000 TFT_RD=0 'get ID from TFT delay_us(1) TFT_ID=PORTD delay_us(1) TFT_RD=1 Delay(1) TFT_CS=1 Delay_ms(100) TRISD=0x0000 while true LATD=TFT_ID PORTC.2=not PORTC.2 Delay_ms(100) LATD=0 PORTC.2=not PORTC.2 Delay_ms(100) wend end sub sub procedure TFT_Init() TFT_RESET() ' //************* Start Initial Sequence **********// TFT_Write_Register(0x00E3, 0x3008)'; // Set internal timing TFT_Write_Register(0x00E7, 0x0012)'; // Set internal timing TFT_Write_Register(0x00EF, 0x1231)'; // Set internal timing TFT_Write_Register(0x0001, 0x0100)'; // set SS and SM bit TFT_Write_Register(0x0002, 0x0700)'; // set 1 line inversion TFT_Write_Register(0x0003, 0x1030)''; // set GRAM write direction and BGR=1. TFT_Write_Register(0x0004, 0x0000)'; // Resize register TFT_Write_Register(0x0008, 0x0202)'; // set the back porch and front porch TFT_Write_Register(0x0009, 0x0000)'; // set non-display area refresh cycle ISC[3:0] TFT_Write_Register(0x000A, 0x0000)'; // FMARK function TFT_Write_Register(0x000C, 0x0000)'; // RGB interface setting TFT_Write_Register(0x000D, 0x0000)'; // Frame marker Position TFT_Write_Register(0x000F, 0x0000)'; // RGB interface polarity ' //*************Power On sequence ****************// TFT_Write_Register(0x0010, 0x0000)'; // SAP, BT[3:0], AP, DSTB, SLP, STB TFT_Write_Register(0x0011, 0x0007)'; // DC1[2:0], DC0[2:0], VC[2:0] TFT_Write_Register(0x0012, 0x0000)'; // VREG1OUT voltage TFT_Write_Register(0x0013, 0x0000)'; // VDV[4:0] for VCOM amplitude Delay_ms(200)'; // Dis-charge capacitor power voltage TFT_Write_Register(0x0010, 0x1690)'; // SAP, BT[3:0], AP, DSTB, SLP, STB TFT_Write_Register(0x0011, 0x0227)'; // R11h=0x0221 at VCI=3.3V, DC1[2:0], DC0[2:0], VC[2:0] Delay_ms(50)'; // Delay 50ms TFT_Write_Register(0x0012, 0x001C)'; // External reference voltage= Vci; Delay_ms(50)'; // Delay 50ms TFT_Write_Register(0x0013, 0x1800)'; // R13=1200 when R12=009D;VDV[4:0] for VCOM amplitude TFT_Write_Register(0x0029, 0x001C)'; // R29=000C when R12=009D;VCM[5:0] for VCOMH TFT_Write_Register(0x002B, 0x000D)'; // Frame Rate = 91Hz Delay_ms(50)'; // Delay 50ms TFT_Write_Register(0x0020, 0x0000)'; // GRAM horizontal Address TFT_Write_Register(0x0021, 0x0000)'; // GRAM Vertical Address '// ----------- Adjust the Gamma Curve ----------// TFT_Write_Register(0x0030, 0x0007)'; TFT_Write_Register(0x0031, 0x0302)'; TFT_Write_Register(0x0032, 0x0105)'; TFT_Write_Register(0x0035, 0x0206)'; TFT_Write_Register(0x0036, 0x0808)'; TFT_Write_Register(0x0037, 0x0206)'; TFT_Write_Register(0x0038, 0x0504)'; TFT_Write_Register(0x0039, 0x0007)'; TFT_Write_Register(0x003C, 0x0105)'; TFT_Write_Register(0x003D, 0x0808)'; '//------------------ Set GRAM area ---------------// TFT_Write_Register(0x0050, 0x0000)'; // Horizontal GRAM Start Address TFT_Write_Register(0x0051, 0x00EF)'; // Horizontal GRAM End Address TFT_Write_Register(0x0052, 0x0000)'; // Vertical GRAM Start Address TFT_Write_Register(0x0053, 0x013F)'; // Vertical GRAM Start Address TFT_Write_Register(0x0060, 0xA700)'; // Gate Scan Line TFT_Write_Register(0x0061, 0x0001)'; // NDL,VLE, REV TFT_Write_Register(0x006A, 0x0000)'; // set scrolling line '//-------------- Partial Display Control ---------// TFT_Write_Register(0x0080, 0x0000)'; TFT_Write_Register(0x0081, 0x0000)'; TFT_Write_Register(0x0082, 0x0000)'; TFT_Write_Register(0x0083, 0x0000)'; TFT_Write_Register(0x0084, 0x0000)'; TFT_Write_Register(0x0085, 0x0000)'; '//-------------- Panel Control -------------------// TFT_Write_Register(0x0090, 0x0010)'; TFT_Write_Register(0x0092, 0x0000)'; TFT_Write_Register(0x0093, 0x0003)'; TFT_Write_Register(0x0095, 0x0110)'; TFT_Write_Register(0x0097, 0x0000)'; TFT_Write_Register(0x0098, 0x0000)'; TFT_Write_Register(0x0007, 0x0133)'; // 262K color and display ON end sub sub procedure TFT_SetCursor(dim x as word, dim y as word) TFT_Write_Register(0x0020,y)'; // ok TFT_Write_Register(0x0021,0x13f-x)'; // columns end sub sub procedure TFT_Clear(dim MyFillColor as word) dim i as longint TFT_SetCursor(0x0000, 0x0000) TFT_CS=0 '//Выбор LCD TFT_RS=0 '//Передача команды в LCD 'TFT_Write_Com($0022) LATD=0x0022 TFT_WR=0 '//Выдача сигнала записи в LCD TFT_WR=1 '//Снятие сигнала записи в LCD TFT_RS=1 '//Передача Данных в LCD for i=0 to 76800 'TFT_Write_Dat(MyFillColor) LATD=MyFillColor TFT_WR=0 '//Выдача сигнала записи в LCD TFT_WR=1 '//Снятие сигнала записи в LCD next i TFT_CS=1 end sub sub procedure TFT_SetWimdow(dim xs, xe, ys, ye as word) 'void LCD_set_Window_ILI9325(int xs,int xe,int ys,int ye) TFT_Write_Register(0x0050,xs) TFT_Write_Register(0x0051,xe) TFT_Write_Register(0x0052,ys) TFT_Write_Register(0x0053,ye) TFT_Write_Register(0x0020,xs) TFT_Write_Register(0x0021,ys) TFT_WRITE_Com(0x0022) end sub sub procedure Proverka_PIN1() start3: if portf.12=0 then ii=ii+1 if ii>5 then ii=0 end if portc.2=not portc.2 delay_ms(100) end if select case ii case 0 TFT_CS=0 TFT_RS=0 TFT_WR=0 TFT_RD=0 TFT_RST=0 case 1 TFT_CS=1 TFT_RS=0 TFT_WR=0 TFT_RD=0 TFT_RST=0 case 2 TFT_CS=0 TFT_RS=1 TFT_WR=0 TFT_RD=0 TFT_RST=0 case 3 TFT_CS=0 TFT_RS=0 TFT_WR=1 TFT_RD=0 TFT_RST=0 case 4 TFT_CS=0 TFT_RS=0 TFT_WR=0 TFT_RD=1 TFT_RST=0 case 5 TFT_CS=0 TFT_RS=0 TFT_WR=0 TFT_RD=0 TFT_RST=1 end select goto start3 end sub sub procedure Proverka_PIN2() dim out1, i as word start4: out1=1 if portf.12=0 then ii=ii+1 if ii>16 then ii=0 end if portc.2=not portc.2 delay_ms(300) end if for i=0 to ii out1=out1*2 next i LATD=out1 goto start4 end sub main: ' Main program TRISD=0 TRISC.2=0 TRISG.12=0 TRISG.13=0 TRISe.2=0 TRISE.3=0 TRISE.4=0 TRISB=$ffff trisf.12=1 portc=0 portd=0 porte=0 portg=0 portc.2=1 'TFT_Read_ID() 'for ii=0 to 6 ' LATC.2=not PORTC.2 ' delay_ms(200) 'next ii start1: TFT_Init() while true TFT_Init() TFT_Clear(g_red) delay_ms(1000) TFT_Clear(g_green) delay_ms(1000) TFT_Clear(g_blue) delay_ms(1000) TFT_Clear(g_white) delay_ms(1000) portc.2=not portc.2 wend end.