TFT Lib works fine, my init code don't work

General discussion on mikroPascal PRO for ARM.
Post Reply
Author
Message
simonsayz
Posts: 30
Joined: 09 Feb 2012 06:32
Location: south kroea
Contact:

TFT Lib works fine, my init code don't work

#1 Post by simonsayz » 12 Feb 2012 05:13

Stellaris board works fine with demo. :)
I write the my own code for TFT init. but It don't work.

Case 1. TFT Lib Init + Dot Works
TFT_Init(320, 240);
TFT_Dot(X,Y,cl_Red ); .......
Case 2. TFT Lib Init + My Init + Dot works
TFT_Init(320, 240);
LCD_Init; // my code
TFT_Dot(X,Y,cl_Red ); .......
Case 3. My Init + Dot don't works
// TFT_Init(320, 240);
LCD_Init; // my code
TFT_Dot(X,Y,cl_Red ); .......

Would you teach me the what is the wrong ?

Here is my code...

----------------------------------------------------------------
program MyProject;
{ Declarations section }
Var
TFT_BLED : sbit at GPIO_PORTD_DATA.B3; // Back Light
TFT_RST : sbit at GPIO_PORTH_DATA.B5; // Reset
TFT_CS : sbit at GPIO_PORTH_DATA.B6; // Chip Selection
//
TFT_DataPort : char at GPIO_PORTJ_DATA; // Data
TFT_RS : sbit at GPIO_PORTG_DATA.B7; // Command/ Data Select
TFT_RD : sbit at GPIO_PORTA_DATA.B6; // /RD , Read Signal
TFT_WR : sbit at GPIO_PORTA_DATA.B7; // /WR,SCL
//
TFT_DataPort_Direction : char at GPIO_PORTJ_DIR;
TFT_RST_Direction : sbit at GPIO_PORTH_DIR.B5;
TFT_BLED_Direction : sbit at GPIO_PORTD_DIR.B3;
TFT_RS_Direction : sbit at GPIO_PORTG_DIR.B7;
TFT_CS_Direction : sbit at GPIO_PORTH_DIR.B6;
TFT_RD_Direction : sbit at GPIO_PORTA_DIR.B6;
TFT_WR_Direction : sbit at GPIO_PORTA_DIR.B7;

X,Y : Integer;

Procedure LCD_Cmd(cmd : Byte);
begin
TFT_RS := 0;
TFT_DataPort := cmd;
TFT_WR := 0; Delay_ms(1); TFT_WR := 1; Delay_ms(1);
end;

Procedure LCD_Dat(dat : Byte);
begin
TFT_RS := 1;
TFT_DataPort := dat;
TFT_WR := 0; Delay_ms(1); TFT_WR := 1; Delay_ms(1);
end;

Procedure LCD_Set(cmd,dat : Byte);
begin
TFT_CS := 0;
TFT_RS := 0;
TFT_DataPort := cmd;
TFT_WR := 0; delay_ms(1); TFT_WR := 1; delay_ms(1);
TFT_RS := 1;
TFT_DataPort := dat;
TFT_WR := 0; delay_ms(1); TFT_WR := 1; delay_ms(1);
TFT_CS := 1;
end;

Procedure LCD_Init;
begin
{
TFT_RST_Direction := 1;
TFT_RS_Direction := 1;
TFT_CS_Direction := 1;
TFT_RD_Direction := 1;
TFT_WR_Direction := 1;
TFT_DataPort_Direction := $FF;
}
TFT_RS := 1;
TFT_CS := 1;
TFT_RD := 1;
TFT_WR := 1;
TFT_Rst := 0; Delay_ms(100);
TFT_Rst := 1; Delay_ms(200);
//
LCD_Set($EA, 0); // 234, 0 Power Control Internal use 1
LCD_Set($EB, 32); // 235, 32 Power Control Internal use 2
LCD_Set($EC, 12); // 236, 12 Source control internal use 1
LCD_Set($ED,196); // 237,196 Source control internal use 2
LCD_Set($E8, 64); // 232, 64 Source OP control_Normal;
LCD_Set($E9, 56); // 233, 56 Source OP control_IDLE;
LCD_Set($F1, 1); // 241, 1 ?
LCD_Set($F2, 16); // 242, 16 ?
LCD_Set($27,163); // 39,163 Display Control
LCD_Set($40, 0); // 64, 0 r1 Control (1)
LCD_Set($41, 0); // 65, 0 r1 Control (2)
LCD_Set($42, 1); // 66, 1 r1 Control (3)
LCD_Set($43, 19); // 67, 19 r1 Control (4)
LCD_Set($44, 16); // 68, 16 r1 Control (5)
LCD_Set($45, 38); // 69, 38 r1 Control (6)
LCD_Set($46, 8); // 70, 8 r1 Control (7)
LCD_Set($47, 81); // 71, 81 r1 Control (8)
LCD_Set($48, 2); // 72, 2 r1 Control (9)
LCD_Set($49, 18); // 73, 18 r1 Control (10)
LCD_Set($4A, 24); // 74, 24 r1 Control (11)
LCD_Set($4B, 25); // 75, 25 r1 Control (12)
LCD_Set($4C, 20); // 76, 20 r1 Control (13)
LCD_Set($50, 25); // 80, 25 r1 Control (14)
LCD_Set($51, 47); // 81, 47 r1 Control (15)
LCD_Set($52, 44); // 82, 44 r1 Control (16)
LCD_Set($53, 62); // 83, 62 r1 Control (17)
LCD_Set($54, 63); // 84, 63 r1 Control (18)
LCD_Set($55, 63); // 85, 63 r1 Control (19)
LCD_Set($56, 46); // 86, 46 r1 Control (20)
LCD_Set($57,119); // 87,119 r1 Control (21)
LCD_Set($58, 11); // 88, 11 r1 Control (22)
LCD_Set($59, 6); // 89, 6 r1 Control (23)
LCD_Set($5A, 7); // 90, 7 r1 Control (24)
LCD_Set($5B, 13); // 91, 13 r1 Control (25)
LCD_Set($5C, 29); // 92, 29 r1 Control (26)
LCD_Set($5D,204); // 93,204 r1 Control (27)

LCD_Set($04, 1); // 04, 0 Column address end 2
LCD_Set($05, 63); // 05,239 Column address end 1
LCD_Set($08, 0); // 08, 1 Row address end 2
LCD_Set($09,239); // 09, 63 Row address end 1

LCD_Set($16,104); // 22,104
LCD_Set($1B, 27); // 27, 27
LCD_Set($1A, 1); // 26, 1
LCD_Set($24, 47); // 36, 47
LCD_Set($25, 87); // 37, 87
LCD_Set($23,141); // 35,141
LCD_Set($18, 54); // 24, 54
LCD_Set($19, 1); // 25, 1
LCD_Set($01, 0); // 1, 0
LCD_Set($1F,136); Delay_ms(50); // 31,136
LCD_Set($1F,128); Delay_ms(50); // 31,128
LCD_Set($1F,144); Delay_ms(50); // 31,144
LCD_Set($1F,208); Delay_ms(100); // 31,208
LCD_Set($17, 5); // 23,5
LCD_Set($36, 0); // 54,0
LCD_Set($28, 56); Delay_ms(100); // 40,56
LCD_Set($28, 60); // 40,60
//
end;

begin
//
GPIO_Config(@GPIO_PORTD_DATA_BITS, %00001000, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);
GPIO_Config(@GPIO_PORTH_DATA_BITS, %01100000, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);
GPIO_Config(@GPIO_PORTJ_DATA_BITS, %11111111, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);
GPIO_Config(@GPIO_PORTG_DATA_BITS, %10000000, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);
GPIO_Config(@GPIO_PORTA_DATA_BITS, %11000000, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);

TFT_BLED_Direction := 1;
TFT_BLED := 1;

// MI0283QT2 / HX8347D
TFT_Init(320, 240);
LCD_Init; // <-------
//
While (true) do
begin
For X := 0 to 320-1 do
For Y := 0 to 240-1 do
TFT_Dot(X,Y,cl_Red );

For X := 0 to 320-1 do
For Y := 0 to 240-1 do
TFT_Dot(X,Y,cl_Blue );
end;

end.

simonsayz
Posts: 30
Joined: 09 Feb 2012 06:32
Location: south kroea
Contact:

Re: TFT Lib works fine, my init code don't work

#2 Post by simonsayz » 12 Feb 2012 15:57

Sorry... my mistake
All is good, Works fines :)

//
// TFT Basic Driver
// by simonsayz
//
// --------------------------------------------------------------------
// MI0283QT2
// Driver : HX8347-D
// Pixel : 320x240
// Color : 16bit (5:6:5)
// Interface : IM3~0 [0,0,1,1] 8080 MCU 8bit Parallel Type II
// CPU : LM3S9B95 (mikromedia for Stellaris M3 80Mhz)
// Compiler : mikroPascal Pro for ARM v.1.0.0
// --------------------------------------------------------------------
//
// History
// --------------------------------------------------------------------
// 2012.02.12 first draft
//
// Example
// ---------------------------------------------------------------------
// uses
// Drv_TFT;
// begin
// LCD_Init(clWhite);
// LCD_BackLight(True);
// while (true) do
// begin
// LCD_Fill(0,0,cXmax,cYmax,clGreen);
// LCD_Fill(0,0,cXmax,cYmax,clBlue );
// end;
// end.
//
//
unit Drv_TFT;

Const
cXmax = 320-1;
cYmax = 240-1;
clWhite = %1111111111111111;
clBlack = %0000000000000000;
clRed = %1111100000000000;
clGreen = %0000011111100000;
clBlue = %0000000000011111;
//
Procedure LCD_Init (Color : Word);
Procedure LCD_BackLight(OnOff : Boolean);
Procedure LCD_Pixel (X1,Y1,Color : Word);
Procedure LCD_Fill (X1,Y1,X2,Y2,Color : Word);

implementation

Var
TFT_BLED : sbit at GPIO_PORTD_DATA.B3; // Back Light
TFT_RST : sbit at GPIO_PORTH_DATA.B5; // Reset
TFT_CS : sbit at GPIO_PORTH_DATA.B6; // Chip Selection
//
TFT_DataPort : char at GPIO_PORTJ_DATA; // Data
TFT_RS : sbit at GPIO_PORTG_DATA.B7; // Command/ Data Select
TFT_RD : sbit at GPIO_PORTA_DATA.B6; // /RD , Read Signal
TFT_WR : sbit at GPIO_PORTA_DATA.B7; // /WR,SCL
//
TFT_DataPort_Direction : char at GPIO_PORTJ_DIR;
TFT_RST_Direction : sbit at GPIO_PORTH_DIR.B5;
TFT_BLED_Direction : sbit at GPIO_PORTD_DIR.B3;
TFT_RS_Direction : sbit at GPIO_PORTG_DIR.B7;
TFT_CS_Direction : sbit at GPIO_PORTH_DIR.B6;
TFT_RD_Direction : sbit at GPIO_PORTA_DIR.B6;
TFT_WR_Direction : sbit at GPIO_PORTA_DIR.B7;

Procedure LCD_Cmd(cmd : Byte);
begin
TFT_RS := 0;
TFT_DataPort := cmd;
TFT_WR := 0; TFT_WR := 1;
end;

Procedure LCD_Dat(dat : Byte);
begin
TFT_RS := 1;
TFT_DataPort := dat;
TFT_WR := 0; TFT_WR := 1;
end;

Procedure LCD_Set(cmd,dat : Byte);
begin
TFT_CS := 0;
TFT_RS := 0;
TFT_DataPort := cmd;
TFT_WR := 0; TFT_WR := 1;
TFT_RS := 1;
TFT_DataPort := dat;
TFT_WR := 0; TFT_WR := 1;
TFT_CS := 1;
end;

//
Procedure LCD_BackLight(OnOff : Boolean);
begin
Case OnOff of
True : TFT_BLED := 1;
False : TFT_BLED := 0;
End;
end;

//
Procedure LCD_Win(X1,Y1,X2,Y2 : Word);
begin
LCD_Set($02,hi(x1)); // Column address Start 2
LCD_Set($03,lo(x1)); // Column address Start 1
LCD_Set($04,hi(x2)); // Column address End 2
LCD_set($05,lo(x2)); // Column address End 1
LCD_Set($06,hi(y1)); // Row address Start 2
LCD_Set($07,lo(y1)); // Row address Start 1
LCD_Set($08,hi(y2)); // Row address End 2
LCD_Set($09,lo(y2)); // Row address End 1
end;

//
Procedure LCD_Pixel(X1,Y1,Color : Word);
Var
X,Y : Integer;
A,B : Byte;
begin
//
If (X1 >= cXmax) or
(Y1 >= cYmax) then Exit;
//
LCD_Win(X1,Y1,X1+1,Y1+1);
//
TFT_CS := False;
LCD_cmd($22);
TFT_RS := 1;
A := Hi(Color);
B := Lo(Color);
TFT_DataPort := A; TFT_WR := 0; TFT_WR := 1;
TFT_DataPort := B; TFT_WR := 0; TFT_WR := 1;
TFT_CS := True;
end;

//
Procedure LCD_Fill(X1,Y1,X2,Y2,Color : Word);
Var
X,Y : Integer;
A,B : Byte;
begin
LCD_Win(X1,Y1,X2,Y2);
//
TFT_CS := False;
LCD_cmd($22);
TFT_RS := 1;
A := Hi(Color);
B := Lo(Color);
For X := 0 to (X2-X1-1) do
For Y := 0 to (Y2-Y1-1) do
begin
TFT_DataPort := A; TFT_WR := 0; TFT_WR := 1;
TFT_DataPort := B; TFT_WR := 0; TFT_WR := 1;
end;
TFT_CS := True;
end;

//
Procedure LCD_Init(Color : Word);
begin
//
GPIO_Config(@GPIO_PORTD_DATA_BITS, %00001000, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);
GPIO_Config(@GPIO_PORTH_DATA_BITS, %01100000, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);
GPIO_Config(@GPIO_PORTJ_DATA_BITS, %11111111, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);
GPIO_Config(@GPIO_PORTG_DATA_BITS, %10000000, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);
GPIO_Config(@GPIO_PORTA_DATA_BITS, %11000000, _GPIO_DIR_OUTPUT, _GPIO_CFG_DIGITAL_ENABLE or _GPIO_CFG_DRIVE_8mA, 0);
//
TFT_BLED_Direction := 1;
TFT_BLED := 0;
//
TFT_RST_Direction := 1;
TFT_RS_Direction := 1;
TFT_CS_Direction := 1;
TFT_RD_Direction := 1;
TFT_WR_Direction := 1;
TFT_DataPort_Direction := $FF;

TFT_RS := 1;
TFT_CS := 1;
TFT_RD := 1;
TFT_WR := 1;
TFT_Rst := 0; Delay_ms(100);
TFT_Rst := 1; Delay_ms(200);
//
LCD_Set($EA, 0); // 234, 0 Power Control Internal use 1
LCD_Set($EB, 32); // 235, 32 Power Control Internal use 2
LCD_Set($EC, 12); // 236, 12 Source control internal use 1
LCD_Set($ED,196); // 237,196 Source control internal use 2
LCD_Set($E8, 64); // 232, 64 Source OP control_Normal;
LCD_Set($E9, 56); // 233, 56 Source OP control_IDLE;
LCD_Set($F1, 1); // 241, 1 ?
LCD_Set($F2, 16); // 242, 16 ?
LCD_Set($27,163); // 39,163 Display Control
LCD_Set($40, 0); // 64, 0 r1 Control (1)
LCD_Set($41, 0); // 65, 0 r1 Control (2)
LCD_Set($42, 1); // 66, 1 r1 Control (3)
LCD_Set($43, 19); // 67, 19 r1 Control (4)
LCD_Set($44, 16); // 68, 16 r1 Control (5)
LCD_Set($45, 38); // 69, 38 r1 Control (6)
LCD_Set($46, 8); // 70, 8 r1 Control (7)
LCD_Set($47, 81); // 71, 81 r1 Control (8)
LCD_Set($48, 2); // 72, 2 r1 Control (9)
LCD_Set($49, 18); // 73, 18 r1 Control (10)
LCD_Set($4A, 24); // 74, 24 r1 Control (11)
LCD_Set($4B, 25); // 75, 25 r1 Control (12)
LCD_Set($4C, 20); // 76, 20 r1 Control (13)
LCD_Set($50, 25); // 80, 25 r1 Control (14)
LCD_Set($51, 47); // 81, 47 r1 Control (15)
LCD_Set($52, 44); // 82, 44 r1 Control (16)
LCD_Set($53, 62); // 83, 62 r1 Control (17)
LCD_Set($54, 63); // 84, 63 r1 Control (18)
LCD_Set($55, 63); // 85, 63 r1 Control (19)
LCD_Set($56, 46); // 86, 46 r1 Control (20)
LCD_Set($57,119); // 87,119 r1 Control (21)
LCD_Set($58, 11); // 88, 11 r1 Control (22)
LCD_Set($59, 6); // 89, 6 r1 Control (23)
LCD_Set($5A, 7); // 90, 7 r1 Control (24)
LCD_Set($5B, 13); // 91, 13 r1 Control (25)
LCD_Set($5C, 29); // 92, 29 r1 Control (26)
LCD_Set($5D,204); // 93,204 r1 Control (27)

LCD_Set($16,104); // 22,104 Memory Access control
LCD_Set($1B, 27); // 27, 27 Power Control 2
LCD_Set($1A, 1); // 26, 1 Power Control 1
LCD_Set($24, 47); // 36, 47 VCom Control 2
LCD_Set($25, 87); // 37, 87 VCom Control 3
LCD_Set($23,141); // 35,141 VCom Control 1
LCD_Set($18, 54); // 24, 54 OSC Control 2
LCD_Set($19, 1); // 25, 1 OSC Control 1
LCD_Set($01, 0); // 1, 0 Display Mode Control
LCD_Set($1F,136); Delay_ms(50); // 31,136 Power Control 6
LCD_Set($1F,128); Delay_ms(50); // 31,128 Power Control 6
LCD_Set($1F,144); Delay_ms(50); // 31,144 Power Control 6
LCD_Set($1F,208); Delay_ms(100); // 31,208 Power Control 6
LCD_Set($17, 5); // 23, 5 COLMOD (5:6:5)
LCD_Set($36, 0); // 54, 0 Panel Characteristic
LCD_Set($28, 56); Delay_ms(100); // 40, 56 Display Control 3
LCD_Set($28, 60); // 40, 60 Display Control 3
//
// LCD_Fill(0,0,320-1,240-1,color);
end;


end.

Post Reply

Return to “mikroPascal PRO for ARM General”