Programming "mikromedia for PIC24" with Bootloader or mikro

Post Reply
Author
Message
kollergmbh
Posts: 2
Joined: 22 May 2015 06:38

Programming "mikromedia for PIC24" with Bootloader or mikro

#1 Post by kollergmbh » 22 Sep 2019 20:58

I have 2 new mikromedia-modules for PIC24, but after programming the TFT stays dark.
An older module is ok.
The Software is generated by VTFT in Pascal.

Are there changes at the modules from old to new?

-----------------------------------------------------------
Here is the Source-Program:

program AFUmini;

type TOnEventPtr = procedure();

type TBytePtr = ^byte;

type TScreen = record
Color : word;
Width : word;
Height : word;
ObjectsCount : word;
end;

// TFT module connections
var TFT_DataPort : char at LATE;
TFT_RST : sbit at LATC1_bit;
TFT_BLED : sbit at LATD2_bit;
TFT_RS : sbit at LATB15_bit;
TFT_CS : sbit at LATF12_bit;
TFT_RD : sbit at LATD5_bit;
TFT_WR : sbit at LATD4_bit;
TFT_DataPort_Direction : char at TRISE;
TFT_RST_Direction : sbit at TRISC1_bit;
TFT_BLED_Direction : sbit at TRISD2_bit;
TFT_RS_Direction : sbit at TRISB15_bit;
TFT_CS_Direction : sbit at TRISF12_bit;
TFT_RD_Direction : sbit at TRISD5_bit;
TFT_WR_Direction : sbit at TRISD4_bit;
// End TFT module connections

// Touch Panel module connections
var DriveX_Left : sbit at LATB13_bit;
var DriveX_Right : sbit at LATB11_bit;
var DriveY_Up : sbit at LATB12_bit;
var DriveY_Down : sbit at LATB10_bit;
var DriveX_Left_Direction : sbit at TRISB13_bit;
var DriveX_Right_Direction : sbit at TRISB11_bit;
var DriveY_Up_Direction : sbit at TRISB12_bit;
var DriveY_Down_Direction : sbit at TRISB10_bit;
// End Touch Panel module connections

// Global variables
var Xcoord, Ycoord : word;
const ADC_THRESHOLD = 850;
var PenDown : byte;
type TPointer = dword;
var PressedObject : TPointer;
var PressedObjectType : integer;
var display_width, display_height : word;

var
_object_count : integer;
object_pressed : byte;

/////////////////////////
var CurrentScreen : ^TScreen;
var Screen1 : TScreen;



procedure Init_ADC();
begin
AD1PCFGL := 0xCFFF;
Delay_ms(150);
ADC1_Init();
end;

procedure InitializeTouchPanel(); // static
begin
Init_ADC();
TFT_Init(320, 240);

TP_TFT_Init(320, 240, 13, 12); // Initialize touch panel
TP_TFT_Set_ADC_Threshold(ADC_THRESHOLD); // Set touch panel ADC threshold

PenDown := 0;
PressedObject := 0;
PressedObjectType := -1;
end;

procedure Calibrate();
begin
TFT_Set_Pen(CL_WHITE, 3);
TFT_Set_Font(@TFT_defaultFont, CL_WHITE, FO_HORIZONTAL);
TFT_Write_Text('Touch selected corners for calibration', 50, 80);
TFT_Line(315, 1, 319, 1);
TFT_Line(310, 10, 319, 1);
TFT_Line(319, 5, 319, 1);
TFT_Write_Text('first here', 230, 20);

TP_TFT_Calibrate_Min(); // Calibration of TP minimum
Delay_ms(500);

TFT_Set_Pen(CL_BLACK, 3);
TFT_Set_Font(@TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
TFT_Line(315, 1, 319, 1);
TFT_Line(310, 10, 319, 1);
TFT_Line(319, 5, 319, 1);
TFT_Write_Text('first here', 230, 20);

TFT_Set_Pen(CL_WHITE, 3);
TFT_Set_Font(@TFT_defaultFont, CL_WHITE, FO_HORIZONTAL);
TFT_Line(0, 239, 0, 235);
TFT_Line(0, 239, 5, 239);
TFT_Line(0, 239, 10, 230);
TFT_Write_Text('now here ', 15, 200);

TP_TFT_Calibrate_Max(); // Calibration of TP maximum
Delay_ms(500);
end;

procedure InitializeObjects(); // static
begin
Screen1.Color := 0x5AEB;
Screen1.Width := 320;
Screen1.Height := 240;
Screen1.ObjectsCount := 0;
end;

function IsInsideObject (X, Y, Left, Top, Width, Height : word) : byte; // static
begin
if ( (Left<= X) and (Left+ Width - 1 >= X) and
(Top <= Y) and (Top + Height - 1 >= Y) ) then
Result := 1
else
Result := 0;
end;

procedure DrawScreen(aScreen : ^TScreen);
var order : word;
var save_bled, save_bled_direction : byte;

begin
object_pressed := 0;
order := 0;
CurrentScreen := aScreen;

if (display_width <> CurrentScreen^.Width) or (display_height <> CurrentScreen^.Height) then
begin
save_bled := TFT_BLED;
save_bled_direction := TFT_BLED_Direction;
TFT_BLED_Direction := 0;
TFT_BLED := 0;
TFT_Init(CurrentScreen^.Width, CurrentScreen^.Height);
TP_TFT_Init(CurrentScreen^.Width, CurrentScreen^.Height, 13, 12); // Initialize touch panel
TP_TFT_Set_ADC_Threshold(ADC_THRESHOLD); // Set touch panel ADC threshold
TFT_Fill_Screen(CurrentScreen^.Color);
display_width := CurrentScreen^.Width;
display_height := CurrentScreen^.Height;
TFT_BLED := save_bled;
TFT_BLED_Direction := save_bled_direction;
end
else
TFT_Fill_Screen(CurrentScreen^.Color);


while (order < CurrentScreen^.ObjectsCount) do
begin
end;
end;

procedure Get_Object( X : word; Y : word);
var counter : integer;
begin
_object_count := -1;
end;


procedure Process_TP_Press( X : word; Y : word); // static
begin

Get_Object(X, Y);

if (_object_count <> -1) then
begin
end;
end;

procedure Process_TP_Up( X : word; Y : word); // static
begin

Get_Object(X, Y);

if (_object_count <> -1) then
begin
end;
PressedObject := 0;
PressedObjectType := -1;
end;

procedure Process_TP_Down( X : word; Y : word); // static
begin
object_pressed := 0;

Get_Object(X, Y);

if (_object_count <> -1) then
begin
end;
end;

procedure Check_TP();
begin
if (TP_TFT_Press_Detect()) then
begin
if (TP_TFT_Get_Coordinates(@Xcoord, @Ycoord) = 0) then
// After a PRESS is detected read X-Y and convert it to Display dimensions space
begin
Process_TP_Press(Xcoord, Ycoord);
if PenDown = 0 then
begin
PenDown := 1;
Process_TP_Down(Xcoord, Ycoord);
end;
end;
end
else if PenDown = 1 then
begin
PenDown := 0;
Process_TP_Up(Xcoord, Ycoord);
end;
end;

procedure Init_MCU();
begin
TFT_Set_Default_Mode();
TP_TFT_Set_Default_Mode();
end;

procedure Start_TP();
begin
Init_MCU();

InitializeTouchPanel();

Delay_ms(1000);
TFT_Fill_Screen(0);
Calibrate();
TFT_Fill_Screen(0);

InitializeObjects();
display_width := Screen1.Width;
display_height := Screen1.Height;
DrawScreen(@Screen1);
end;

begin
Start_TP();

while (TRUE) do
begin
Check_TP();
end;
end.

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

Re: Programming "mikromedia for PIC24" with Bootloader or mi

#2 Post by filip » 27 Sep 2019 16:28

Hello,

Can you please attach the photo of the display, I suspect different display driver is used here ?

Regards,
Filip.

Post Reply

Return to “Mikromedia”