how to use visual ssd1289 with TFT ?

General discussion on Visual TFT Software.
Post Reply
Author
Message
patabr
Posts: 11
Joined: 11 Mar 2010 13:15

how to use visual ssd1289 with TFT ?

#1 Post by patabr » 21 Nov 2014 16:10

hello all

I was desperately trying to work with visual TFT with driver ssd1289,
I first tried my LCD with a code found on this forum here:
http://www.mikroe.com/forum/viewtopic.php?f=160&t=46901
and it works perfectly :D ,
Now, I would like to use with visualtft ssd1289,
first, in file __Lib_TFT_16bit_Defs.mbas I replaced the init part of ILI9341 by the driver found on the forum, I then created a Visual TFT (demo) project with ILI9341 driver but nothing works !! :(
can you please help me.
here is my simple code:

__Lib_TFT_16bit_Defs.mbas
'========= ILI9341 (16bit) ==> SSD1289 =============
'-------------------------------------------------------------------------------
sub procedure TFT_16bit_Set_Address_ILI9341(dim x as word, dim y as word)
'-------------------------------------------------------------------------------
dim x2, y2 as word
x2 = TFT_16bit_DISP_WIDTH - 1
y2 = TFT_16bit_DISP_HEIGHT - 1
' if (TFT_16bit_Disp_Rotation = 90) then
TFT_16bit_Set_Index_Ptr(68) TFT_16bit_Write_Data_Ptr((x2 << 8) + x)
TFT_16bit_Set_Index_Ptr(69) TFT_16bit_Write_Data_Ptr(y)
TFT_16bit_Set_Index_Ptr(70) TFT_16bit_Write_Data_Ptr(y2)
TFT_16bit_Set_Index_Ptr(78) TFT_16bit_Write_Data_Ptr(x)
TFT_16bit_Set_Index_Ptr(79) TFT_16bit_Write_Data_Ptr(y)
' else
' TFT_16bit_Set_Index_Ptr(68) TFT_16bit_Write_Data_Ptr((y2 << 8) + x)
' TFT_16bit_Set_Index_Ptr(69) TFT_16bit_Write_Data_Ptr(x)
' TFT_16bit_Set_Index_Ptr(70) TFT_16bit_Write_Data_Ptr(x2)
' TFT_16bit_Set_Index_Ptr(78) TFT_16bit_Write_Data_Ptr(y)
' TFT_16bit_Set_Index_Ptr(79) TFT_16bit_Write_Data_Ptr(x)
' end if
TFT_16bit_Set_Index_Ptr(34)
end sub

'-------------------------------------------------------------------------------
sub procedure TFT_16bit_Reset_ILI9341()
'-------------------------------------------------------------------------------
TFT_16bit_RST = 0
TFT_16bit_RST_Direction= 0
TFT_16bit_RS = 1
TFT_16bit_RS_Direction = 0
TFT_16bit_CS = 1
TFT_16bit_CS_Direction = 0
TFT_16bit_RD_Direction = 0
TFT_16bit_WR_Direction = 0
TFT_16bit_RD = 1
TFT_16bit_WR = 1

Delay_100ms()
TFT_16bit_RST = 1
Delay_100ms() Delay_100ms()
TFT_16bit_CS = 0
Delay_100ms()
TFT_16bit_Set_Index_Ptr(0x0000) TFT_16bit_Write_Data_Ptr(0x0001)

TFT_16bit_Set_Index_Ptr(0x0003) TFT_16bit_Write_Data_Ptr(0xA8A4)
TFT_16bit_Set_Index_Ptr(0x000C) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x000D) TFT_16bit_Write_Data_Ptr(0x800C) '800c 080c
TFT_16bit_Set_Index_Ptr(0x000E) TFT_16bit_Write_Data_Ptr(0x2B00)
TFT_16bit_Set_Index_Ptr(0x001E) TFT_16bit_Write_Data_Ptr(0x00B7)

TFT_16bit_Set_Index_Ptr(0x0001) TFT_16bit_Write_Data_Ptr(0x2B3F)
TFT_16bit_Set_Index_Ptr(0x0002) TFT_16bit_Write_Data_Ptr(0x0600) '1000 0600
TFT_16bit_Set_Index_Ptr(0x0010) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x0011) TFT_16bit_Write_Data_Ptr(0x6070) '68F0 6070

TFT_16bit_Set_Index_Ptr(0x0005) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x0006) TFT_16bit_Write_Data_Ptr(0x0000)

TFT_16bit_Set_Index_Ptr(0x0016) TFT_16bit_Write_Data_Ptr(0xEF1C)
TFT_16bit_Set_Index_Ptr(0x0017) TFT_16bit_Write_Data_Ptr(0x0003)
TFT_16bit_Set_Index_Ptr(0x0007) TFT_16bit_Write_Data_Ptr(0x0233)
TFT_16bit_Set_Index_Ptr(0x000B) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x000F) TFT_16bit_Write_Data_Ptr(0x0000)

TFT_16bit_Set_Index_Ptr(0x0041) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x0042) TFT_16bit_Write_Data_Ptr(0x0000)

TFT_16bit_Set_Index_Ptr(0x0048) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x0049) TFT_16bit_Write_Data_Ptr(0x013F)
TFT_16bit_Set_Index_Ptr(0x004A) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x004B) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x0044) TFT_16bit_Write_Data_Ptr(0xEF95) 'ef95 ef00
TFT_16bit_Set_Index_Ptr(0x0045) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x0046) TFT_16bit_Write_Data_Ptr(0x013F)

TFT_16bit_Set_Index_Ptr(0x0030) TFT_16bit_Write_Data_Ptr(0x0707)
TFT_16bit_Set_Index_Ptr(0x0031) TFT_16bit_Write_Data_Ptr(0x0204)
TFT_16bit_Set_Index_Ptr(0x0032) TFT_16bit_Write_Data_Ptr(0x0204)
TFT_16bit_Set_Index_Ptr(0x0033) TFT_16bit_Write_Data_Ptr(0x0502)
TFT_16bit_Set_Index_Ptr(0x0034) TFT_16bit_Write_Data_Ptr(0x0507)
TFT_16bit_Set_Index_Ptr(0x0035) TFT_16bit_Write_Data_Ptr(0x0204)
TFT_16bit_Set_Index_Ptr(0x0036) TFT_16bit_Write_Data_Ptr(0x0204)
TFT_16bit_Set_Index_Ptr(0x0037) TFT_16bit_Write_Data_Ptr(0x0502)
TFT_16bit_Set_Index_Ptr(0x003A) TFT_16bit_Write_Data_Ptr(0x0302)
TFT_16bit_Set_Index_Ptr(0x003B) TFT_16bit_Write_Data_Ptr(0x0302)

TFT_16bit_Set_Index_Ptr(0x0023) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x0024) TFT_16bit_Write_Data_Ptr(0x0000)

TFT_16bit_Set_Index_Ptr(0x0025) TFT_16bit_Write_Data_Ptr(0x8000)
TFT_16bit_Set_Index_Ptr(0x004F) TFT_16bit_Write_Data_Ptr(0x0000)
TFT_16bit_Set_Index_Ptr(0x004E) TFT_16bit_Write_Data_Ptr(0x0000)

TFT_16bit_Set_Index_Ptr(0x0022)

TFT_16bit_CS = 1
end sub

'-------------------------------------------------------------------------------
sub procedure TFT_Init_ILI9341_16bit(dim display_width as word display_height as word)
'-------------------------------------------------------------------------------
if(Is_TFT_16bit_Set() <> 1) then
TFT_16bit_Set_Index_Ptr = @TFT_16bit_Set_Index
TFT_16bit_Write_Command_Ptr = @TFT_16bit_Write_Command
TFT_16bit_Write_Data_Ptr = @TFT_16bit_Write_Data
end if

TFT_16bit_DISP_WIDTH = display_width
TFT_16bit_DISP_HEIGHT = display_height
if (display_width >= display_height) then
TFT_16bit_Disp_Rotation = 0
else
TFT_16bit_Disp_Rotation = 90
end if

TFT_16bit_Set_Pen(CL_BLACK_16bit, 1)
TFT_16bit_Set_Brush(0, 0, 0, 0, 0, 0)

TFT_16bit_Move_Cursor(0, 0)
TFT_16bit_Clear_Fonts()
TFT_16bit_DataPort_Lo_Direction = 0
TFT_16bit_DataPort_Hi_Direction = 0
' Reset device
TFT_16bit_Reset_ILI9341()
TFT_16bit_Set_Address_Ptr = @TFT_16bit_Set_Address_ILI9341
end sub

'-------------------------------------------------------------------------------
sub procedure TFT_Init_ILI9341_16bit_Custom(dim display_width as word display_height as word)
'-------------------------------------------------------------------------------
if(Is_TFT_16bit_Set() <> 1) then
TFT_16bit_Set_Index_Ptr = @TFT_16bit_Set_Index
TFT_16bit_Write_Command_Ptr = @TFT_16bit_Write_Command
TFT_16bit_Write_Data_Ptr = @TFT_16bit_Write_Data
end if

TFT_16bit_DISP_WIDTH = display_width
TFT_16bit_DISP_HEIGHT = display_height
if (display_width >= display_height) then
TFT_16bit_Disp_Rotation = 0
else
TFT_16bit_Disp_Rotation = 90
end if

TFT_16bit_Set_Pen(CL_BLACK_16bit, 1)
TFT_16bit_Set_Brush(0, 0, 0, 0, 0, 0)

TFT_16bit_Move_Cursor(0, 0)
TFT_16bit_Clear_Fonts()
' Reset device
TFT_16bit_Reset_ILI9341() 'init
TFT_16bit_Set_Address_Ptr = @TFT_16bit_Set_Address_ILI9341
end sub
'***************************** eof ILI9341 (16bit) *****************************'

Module Driver (created with Visual TFT)
------------------------------------------
module test32_driver

include test32_objects
include test32_resources

' External Declarations
'/////////////////////////

sub procedure DrawScreen(dim aScreen as ^TScreen)
sub procedure Start_TP()
sub procedure DrawLabel(dim ALabel as ^TLabel)
sub procedure DrawRoundBox(dim Around_box as ^TBox_Round)

' TFT module connections
dim TFT_16bit_DataPort_Hi as char at LATB
TFT_16bit_DataPort_Lo as char at LATD
TFT_16bit_RST as sbit at LATC4_bit
TFT_16bit_RS as sbit at LATC0_bit
TFT_16bit_CS as sbit at LATC3_bit
TFT_16bit_RD as sbit at LATC1_bit
TFT_16bit_WR as sbit at LATC2_bit
TFT_16bit_BLED as sbit at LATC7_bit
TFT_16bit_DataPort_Hi_Direction as char at TRISB
TFT_16bit_DataPort_Lo_Direction as char at TRISD
TFT_16bit_RST_Direction as sbit at TRISC4_bit
TFT_16bit_RS_Direction as sbit at TRISC0_bit
TFT_16bit_CS_Direction as sbit at TRISC3_bit
TFT_16bit_RD_Direction as sbit at TRISC1_bit
TFT_16bit_WR_Direction as sbit at TRISC2_bit
TFT_16bit_BLED_Direction as sbit at TRISC7_bit

' Global variables
dim Xcoord, Ycoord as word
'const ADC_THRESHOLD = Todo
dim PenDown as byte
dim PressedObject as TBytePtr
dim PressedObjectType as integer
dim display_width, display_height as word

dim
_object_count as integer
object_pressed as byte
local_label as ^TLabel
exec_label as ^TLabel
label_order as integer
local_round_box as ^TBox_Round
exec_round_box as ^TBox_Round
box_round_order as integer

dim CurrentScreen as ^TScreen

const Screen1_Labels as TLabelPtr[1] code forward
const Screen1_Boxes_Round as TBox_RoundPtr[1] code forward

dim Screen1 as TScreen
dim Label1 as TLabel
Label1_Caption as string[18]

dim BoxRound3 as TBox_Round
const Screen1_Labels as TLabelPtr[1] =
(
@Label1
) code
const Screen1_Boxes_Round as TBox_RoundPtr[1] =
(
@BoxRound3
) code

implements

sub procedure InitializeTouchPanel() ' static
TFT_Init_ILI9341_16bit(320, 240)

PenDown = 0
PressedObject = 0
PressedObjectType = -1
end sub


sub procedure InitializeObjects() ' static
Screen1.Color = 0xFC00
Screen1.Width = 320
Screen1.Height = 240
Screen1.LabelsCount = 1
Screen1.Labels = @Screen1_Labels
Screen1.Boxes_RoundCount = 1
Screen1.Boxes_Round = @Screen1_Boxes_Round
Screen1.ObjectsCount = 2

Label1.OwnerScreenAddress = @Screen1
Label1.Order = 0
Label1.Left_ = 98
Label1.Top = 74
Label1.Width = 85
Label1.Height = 15
Label1.Visible = 1
Label1.Active = 1
Label1.Caption = @Label1_Caption
Label1_Caption = "un titre pour voir"
Label1.FontName = @Tahoma11x13_Regular
Label1.Font_Color = 0x0000
Label1.OnUpPtr = 0
Label1.OnDownPtr = 0
Label1.OnClickPtr = 0
Label1.OnPressPtr = 0

BoxRound3.OwnerScreenAddress = @Screen1
BoxRound3.Order = 1
BoxRound3.Left_ = 84
BoxRound3.Top = 102
BoxRound3.Width = 118
BoxRound3.Height = 56
BoxRound3.Pen_Width = 1
BoxRound3.Pen_Color = 0x0000
BoxRound3.Visible = 1
BoxRound3.Active = 1
BoxRound3.Transparent = 1
BoxRound3.Gradient = 1
BoxRound3.Gradient_Orientation = 0
BoxRound3.Gradient_Start_Color = 0xFFFF
BoxRound3.Gradient_End_Color = 0xC618
BoxRound3.Color = 0xC618
BoxRound3.PressColEnabled = 1
BoxRound3.Press_Color = 0xE71C
BoxRound3.Corner_Radius = 3
BoxRound3.OnUpPtr = 0
BoxRound3.OnDownPtr = 0
BoxRound3.OnClickPtr = 0
BoxRound3.OnPressPtr = 0
end sub

sub function IsInsideObject (dim X, Y as word, dim Left_, Top, Width, Height as word) as byte ' static
if ( (Left_<= X) and (Left_+ Width - 1 >= X) and
(Top <= Y) and (Top + Height - 1 >= Y) ) then
Result = 1
else
Result = 0
end if
end sub

sub function GetLabel (dim index as byte) as ^TLabel ' static
dim objPtr as ^ const code ^TLabel
objPtr = CurrentScreen^.Labels + index
Result = objPtr^
end sub

sub function GetBox_Round (dim index as byte) as ^TBox_Round ' static
dim objPtr as ^ const code ^TBox_Round
objPtr = CurrentScreen^.Boxes_Round + index
Result = objPtr^
end sub

sub procedure DrawLabel(dim ALabel as ^TLabel)
if (ALabel^.Visible = 1) then
TFT_16bit_Set_Font(ALabel^.FontName, ALabel^.Font_Color, FO_HORIZONTAL_16bit)
TFT_16bit_Write_Text(ALabel^.Caption, ALabel^.Left_, ALabel^.Top)
end if
end sub

sub procedure DrawRoundBox(dim Around_box as ^TBox_Round)
if (Around_box^.Visible = 1) then
if object_pressed = 1 then
object_pressed = 0
TFT_16bit_Set_Brush(Around_box^.Transparent, Around_box^.Press_Color, Around_box^.Gradient, Around_box^.Gradient_Orientation,
Around_box^.Gradient_End_Color, Around_box^.Gradient_Start_Color)
else
TFT_16bit_Set_Brush(Around_box^.Transparent, Around_box^.Color, Around_box^.Gradient, Around_box^.Gradient_Orientation,
Around_box^.Gradient_Start_Color, Around_box^.Gradient_End_Color)
end if
TFT_16bit_Set_Pen(Around_box^.Pen_Color, Around_box^.Pen_Width)
TFT_16bit_Rectangle_Round_Edges(Around_box^.Left_ + 1, Around_box^.Top + 1,
Around_box^.Left_ + Around_box^.Width - 2,
Around_box^.Top + Around_box^.Height - 2, Around_box^.Corner_Radius)
end if
end sub

sub procedure DrawScreen(dim aScreen as ^TScreen)
dim order as word
dim label_idx as byte
local_label as ^TLabel
dim round_box_idx as byte
local_round_box as ^TBox_Round
dim save_bled, save_bled_direction as byte

object_pressed = 0
order = 0
label_idx = 0
round_box_idx = 0
CurrentScreen = aScreen

if (display_width <> CurrentScreen^.Width) or (display_height <> CurrentScreen^.Height) then
save_bled = TFT_16bit_BLED
save_bled_direction = TFT_16bit_BLED_Direction
TFT_16bit_BLED_Direction = 0
TFT_16bit_BLED = 0
TFT_Init_ILI9341_16bit(CurrentScreen^.Width, CurrentScreen^.Height)
TFT_16bit_Fill_Screen(CurrentScreen^.Color)
display_width = CurrentScreen^.Width
display_height = CurrentScreen^.Height
TFT_16bit_BLED = save_bled
TFT_16bit_BLED_Direction = save_bled_direction
else
TFT_16bit_Fill_Screen(CurrentScreen^.Color)
end if

while (order < CurrentScreen^.ObjectsCount)
if (label_idx < CurrentScreen^.LabelsCount) then
local_label = GetLabel(label_idx)
if (order = local_label^.Order) then
Inc(label_idx)
Inc(order)
DrawLabel(local_label)
end if
end if

if (round_box_idx < CurrentScreen^.Boxes_RoundCount) then
local_round_box = GetBox_Round(round_box_idx)
if (order = local_round_box^.Order) then
Inc(round_box_idx)
Inc(order)
DrawRoundBox(local_round_box)
end if
end if

wend
end sub

sub procedure Init_MCU()
PLLEN_bit = 1
Delay_ms(150)
TFT_16bit_Set_Default_Mode()
end sub

sub procedure Start_TP()
Init_MCU()

InitializeTouchPanel()
InitializeObjects()
display_width = Screen1.Width
display_height = Screen1.Height
DrawScreen(@Screen1)
end sub

end.


Main Program
---------------------
' MCU: P18F46K22
' Oscillator: 64000000 Hz
' MikroBasic: 6.4.0
program test32_main

main:
Start_TP()

while TRUE
'Check_TP()
nop
wend
end.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: how to use visual ssd1289 with TFT ?

#2 Post by filip » 16 Dec 2014 09:59

Hi,

Have you been able to sort out this issue ?

Regards,
Filip.

Post Reply

Return to “Visual TFT General”