News:

;) This forum is the property of Proton software developers

Main Menu

TFT DISPLAY

Started by Abdullah, Oct 31, 2025, 04:37 PM

Previous topic - Next topic

Abdullah

    Device 18F25K22
    Declare Xtal 64
    Symbol PLLEN = OSCTUNE.6                    ' PLL enable
    Symbol PLLRDY = OSCCON2.7                    ' PLL run status
    PLLEN = 1                                    ' Enable PLL 4x 20MHz = 80Mhz
    While PLLRDY = 0 : Wend                        ' Wait until PLL is stable

    Dim wFSR0 As FSR0L.Word
    Dim wFSR1 As FSR1L.Word
    Dim wFSR2 As FSR2L.Word
    Dim KeyVal As Byte

    $define ILI9341
    Include "ILI9341_9163.inc"                    ' ILI9341 driver
    Include "Amicus18_spi2.inc"
    Include "ADS7846_spi2.inc"
    Include "rgb565.inc"                        ' List of named internet colors.
    DelayMS 100
    InitILI
    DelayMS 100
    SCRorientation0                                                         
    wColor = WHITE
'   SetFont(Arial_Bold_14)
    wPaper = RED
    wInk = BLACK

    GoTo Initialise

Proc WriteKeys()
    SetFont(Arial_Bold_16)   'was 20
    wInk = BLUE
    wPaper = WHITE ' TEXT COLOUR
    At_XY(40,3)
    PrintString("ASSALAMUALAIKUM")
    At_XY(55,24)
    PrintString("SIR SHAHAB DIN")             'just to put something on the screen at top
    At_XY(8,46)
    'PrintString("Key: ")             'and another line to test spacing
   ; SetFont(Arial_Bold_14)
    PrintString("SIR JI PROTON KA TFT DEMO")
    wColor = RED ' BOX COLOUR

    XBox(10,270,66,38)
    XBox(86,270,66,38)
    XBox(162,270,66,38)

    XBox(10,222,66,38)
    XBox(86,222,66,38)
    XBox(162,222,66,38)

    XBox(10,174,66,38)
    XBox(86,174,66,38)
    XBox(162,174,66,38)

    XBox(10,126,66,38)
    XBox(86,126,66,38)
    XBox(162,126,66,38)

    XBox(10,78,66,38)
    XBox(86,78,66,38)
    XBox(162,78,66,38)

    SetFont(Arial_Bold_16)
    wInk = GREEN ' TEXT COLOUR
    wPaper = WHITE
    At_XY(28,280)
    PrintString("Prev")
    At_XY(100,280)
    PrintString("Save")
    At_XY(177,280)
    PrintString("Next")
    At_XY(16,232)
    PrintString("Cancel")
    At_XY(115,232)
    PrintString("0")
    At_XY(177,232)
    PrintString("Exit")
    At_XY(38,184)
    PrintString("7")
    At_XY(115,184)
    PrintString("8")
    At_XY(188,184)
    PrintString("9")
    At_XY(38,136)
    PrintString("4")
    At_XY(115,136)
    PrintString("5")
    At_XY(188,136)
    PrintString("6")
    At_XY(38,91)
    PrintString("1")
    At_XY(116,91)
    PrintString("2")
    At_XY(188,91)
    PrintString("3")
EndProc
Proc SelectColumn1()
    Select ADS_wYlocation
    Case 212 To 241
        KeyVal = 1
    Case 162 To 192
        KeyVal = 4
    Case 116 To 145
        KeyVal = 7
    Case 61 To 98
        KeyVal = 0
    Case 15 To 47
        KeyVal = 11
    EndSelect
EndProc
Proc SelectColumn2()
    Select ADS_wYlocation
    Case 212 To 241
        KeyVal = 2
    Case 162 To 192
        KeyVal = 5
    Case 116 To 145
        KeyVal = 8
    Case 61 To 98
        KeyVal = 12
    Case 15 To 47
        KeyVal = 13
    EndSelect
EndProc
Proc SelectColumn3()
    Select ADS_wYlocation
    Case 212 To 241
        KeyVal = 3
    Case 162 To 192
        KeyVal = 6
    Case 116 To 145
        KeyVal = 9
    Case 61 To 98
        KeyVal = 14
    Case 15 To 47
        KeyVal = 15
    EndSelect
EndProc
Initialise:
    ADS_Init()
    ClearScreen
Main:
    WriteKeys()
    While
    If ADS_Active() = tStylusOn Then
        hADS_GetSample(cMeasureX)                ' Get the raw X value from the touch screen controller
        wInk = BLACK
        ADS_Get()
    Select ADS_wXlocation
    Case 10 To 64
         SelectColumn1()
    Case 82 To 149
         SelectColumn2()
    Case 164 To 225
         SelectColumn3()
    EndSelect
    SetFont(Arial_20)
    At_XY(60,46)
    PrintString(Str$ (Dec KeyVal)+"   "+ Str$(Dec ADS_wPressure)+"     ")         ' Display the value of the key
    DelayMS 200
    EndIf
    Wend
Include "Arial_Bold_14.Inc"
Include "Arial_Bold_16.inc"
Include "Arial_20.inc"
Declare Reminders Off
@ CONFIG_REQ = 0 ; Override Compiler's configuration settings
Asm-
Config FOSC = HSHP ;HS oscillator (high power > 16 MHz)
Config PLLCFG = On ;Oscillator multiplied by 4
Config PRICLKEN = On ;Primary clock enabled
Config FCMEN = OFF ;Fail-Safe Clock Monitor disabled
Config IESO = OFF ;Oscillator Switchover mode disabled
Config PWRTEN = On ;Power up timer enabled
Config BOREN = SBORDIS ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
Config BORV = 190 ;VBOR set to 1.90 V nominal
Config WDTEN = OFF ;Watch dog timer is always disabled. SWDTEN has no effect.
Config WDTPS = 32768 ;1:32768
Config CCP2MX = PORTC1 ;CCP2 input/output is multiplexed with RC1
Config PBADEN = OFF ;PORTB<5:0> pins are configured as digital I/O on Reset
Config CCP3MX = PORTB5 ;P3A/CCP3 input/output is multiplexed with RB5
Config HFOFST = On ;HFINTOSC output and ready status are not delayed by the oscillator stable status
Config T3CMX = PORTC0 ;T3CKI is on RC0
Config P2BMX = PORTB5 ;P2B is on RB5
Config MCLRE = INTMCLR ;RE3 input pin enabled; MCLR disabled
Config STVREN = OFF ;Stack full/underflow will not cause Reset
Config LVP = OFF ;Single-Supply ICSP disabled
Config XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
Config Debug = OFF ;Disabled
Config Cp0 = OFF ;Block 0 (000800-001FFFh) not code-protected
Config CP1 = OFF ;Block 1 (002000-003FFFh) not code-protected
Config CP2 = OFF ;Block 2 (004000-005FFFh) not code-protected
Config CP3 = OFF ;Block 3 (006000-007FFFh) not code-protected
Config CPB = OFF ;Boot block (000000-0007FFh) not code-protected
Config CPD = OFF ;Data EEPROM not code-protected
Config WRT0 = OFF ;Block 0 (000800-001FFFh) not write-protected
Config WRT1 = OFF ;Block 1 (002000-003FFFh) not write-protected
Config WRT2 = OFF ;Block 2 (004000-005FFFh) not write-protected
Config WRT3 = OFF ;Block 3 (006000-007FFFh) not write-protected
Config WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
Config WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
Config WRTD = OFF ;Data EEPROM not write-protected
Config EBTR0 = OFF ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
Config EBTR1 = OFF ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
Config EBTR2 = OFF ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
Config EBTR3 = OFF ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
Config EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Endasm-
Declare Reminders On
HI EVERYONE THIS CODE FOR KEYPAD
XBOX COMMANDS FOR BOX WHAT IS COMMANDS OF CIRCLE
Abdullah

Abdullah

Device = 18F25K22
Declare Xtal = 64

'==================== PLL ENABLE ====================
Symbol PLLEN  = OSCTUNE.6
Symbol PLLRDY = OSCCON2.7
PLLEN = 1
While PLLRDY = 0 : Wend

'==================== VARIABLES ====================
Dim wFSR0 As FSR0L.Word
Dim wFSR1 As FSR1L.Word
Dim wFSR2 As FSR2L.Word
Dim KeyVal As Byte

$define ILI9341
Include "ILI9341_9163.inc"
Include "Amicus18_spi2.inc"
Include "ADS7846_spi2.inc"
Include "rgb565.inc"

'==================== USER VARIABLES ====================
Dim circle_x As Word
Dim circle_y As Word
Dim circle_radius As Word
Dim circle_d As SWord
Dim circle_x1 As SWord
Dim circle_y1 As SWord

'==================== INITIALISE DISPLAY ====================
DelayMS 100
InitILI
DelayMS 100
SCRorientation0
wColor = WHITE
wPaper = RED
wInk = BLACK

'===========================================================
GoTo Initialise

'==================== DRAW CIRCLE PROC ====================
Proc DrawCircle(x As Word, y As Word, radius As Word)
    wColor = RED
    circle_d = 3 - 2 * radius
    circle_x1 = 0
    circle_y1 = radius

    While circle_x1 <= circle_y1
        Pixel = x + circle_x1, y + circle_y1
        Pixel = x - circle_x1, y + circle_y1
        Pixel = x + circle_x1, y - circle_y1
        Pixel = x - circle_x1, y - circle_y1
        Pixel = x + circle_y1, y + circle_x1
        Pixel = x - circle_y1, y + circle_x1
        Pixel = x + circle_y1, y - circle_x1
        Pixel = x - circle_y1, y - circle_x1

        If circle_d < 0 Then
            circle_d = circle_d + 4 * circle_x1 + 6
        Else
            circle_d = circle_d + 4 * (circle_x1 - circle_y1) + 10
            circle_y1 = circle_y1 - 1
        EndIf
        circle_x1 = circle_x1 + 1
    Wend
EndProc

'==================== DRAW FILLED CIRCLE ====================
Proc DrawFilledCircle(x As Word, y As Word, radius As Word)
    Dim i As Word
    Dim j As Word
    For i = 0 To radius
        For j = 0 To radius
            If (i * i + j * j) <= (radius * radius) Then
                Pixel x + i, y + j
                Pixel x - i, y + j
                Pixel x + i, y - j
                Pixel x - i, y - j
            EndIf
        Next j
    Next i
EndProc

'==================== DRAW KEYS ====================
Proc WriteKeys()
    SetFont(Arial_Bold_16)
    wInk = BLUE
    wPaper = WHITE
    At_XY(40,3)
    PrintString("ASSALAMUALAIKUM")
    At_XY(55,24)
    PrintString("SIR SHAHAB DIN")
    At_XY(8,46)
    PrintString("SIR JI PROTON KA TFT DEMO")
    wColor = RED

    ' Draw Key Circles
    DrawCircle(43, 289, 20)   ' Prev
    DrawCircle(119, 289, 20)  ' Save
    DrawCircle(195, 289, 20)  ' Next
    DrawCircle(43, 241, 20)   ' Cancel
    DrawCircle(119, 241, 20)  ' 0
    DrawCircle(195, 241, 20)  ' Exit
    DrawCircle(43, 193, 20)   ' 7
    DrawCircle(119, 193, 20)  ' 8
    DrawCircle(195, 193, 20)  ' 9
    DrawCircle(43, 145, 20)   ' 4
    DrawCircle(119, 145, 20)  ' 5
    DrawCircle(195, 145, 20)  ' 6
    DrawCircle(43, 97, 20)    ' 1
    DrawCircle(119, 97, 20)   ' 2
    DrawCircle(195, 97, 20)   ' 3

    ' Draw Key Text
    SetFont(Arial_Bold_16)
    wInk = GREEN
    wPaper = WHITE
    At_XY(28,280) : PrintString("Prev")
    At_XY(100,280) : PrintString("Save")
    At_XY(177,280) : PrintString("Next")
    At_XY(16,232) : PrintString("Cancel")
    At_XY(115,232) : PrintString("0")
    At_XY(177,232) : PrintString("Exit")
    At_XY(38,184) : PrintString("7")
    At_XY(115,184) : PrintString("8")
    At_XY(188,184) : PrintString("9")
    At_XY(38,136) : PrintString("4")
    At_XY(115,136) : PrintString("5")
    At_XY(188,136) : PrintString("6")
    At_XY(38,91) : PrintString("1")
    At_XY(116,91) : PrintString("2")
    At_XY(188,91) : PrintString("3")
EndProc

'==================== COLUMN SELECT ROUTINES ====================
Proc SelectColumn1()
    Select ADS_wYlocation
    Case 212 To 241
     KeyVal = 1
    Case 162 To 192
     KeyVal = 4
    Case 116 To 145
     KeyVal = 7
    Case 61 To 98
     KeyVal = 0
    Case 15 To 47
     KeyVal = 11
    EndSelect
EndProc

Proc SelectColumn2()
    Select ADS_wYlocation
    Case 212 To 241
     KeyVal = 2
    Case 162 To 192
     KeyVal = 5
    Case 116 To 145
     KeyVal = 8
    Case 61 To 98
     KeyVal = 12
    Case 15 To 47
     KeyVal = 13
    EndSelect
EndProc

Proc SelectColumn3()
    Select ADS_wYlocation
    Case 212 To 241
     KeyVal = 3
    Case 162 To 192
     KeyVal = 6
    Case 116 To 145
     KeyVal = 9
    Case 61 To 98
     KeyVal = 14
    Case 15 To 47
     KeyVal = 15
    EndSelect
EndProc

'==================== MAIN PROGRAM ====================
Initialise:
    ADS_Init()
    ClearScreen

Main:
    WriteKeys()
    While 1 = 1
        If ADS_Active() = tStylusOn Then
            hADS_GetSample(cMeasureX)
            wInk = BLACK
            ADS_Get()
            Select ADS_wXlocation
            Case 10 To 64
             SelectColumn1()
            Case 82 To 149
             SelectColumn2()
            Case 164 To 225
             SelectColumn3()
            EndSelect
            SetFont(Arial_20)
            At_XY(60,46)
            PrintString(Str$(Dec KeyVal) + "   " + Str$(Dec ADS_wPressure) + "     ")
            DelayMS 200
        EndIf
    Wend

'==================== FONTS ====================
Include "Arial_Bold_14.inc"
Include "Arial_Bold_16.inc"
Include "Arial_20.inc"

'==================== CONFIG ====================
Declare Reminders Off
@ CONFIG_REQ = 0
Asm-
Config FOSC = HSHP
Config PLLCFG = On
Config PRICLKEN = On
Config FCMEN = OFF
Config IESO = OFF
Config PWRTEN = On
Config BOREN = SBORDIS
Config BORV = 190
Config WDTEN = OFF
Config WDTPS = 32768
Config CCP2MX = PORTC1
Config PBADEN = OFF
Config CCP3MX = PORTB5
Config HFOFST = On
Config T3CMX = PORTC0
Config P2BMX = PORTB5
Config MCLRE = INTMCLR
Config STVREN = OFF
Config LVP = OFF
Config XINST = OFF
Config Debug = OFF
Config Cp0 = OFF
Config CP1 = OFF
Config CP2 = OFF
Config CP3 = OFF
Config CPB = OFF
Config CPD = OFF
Config WRT0 = OFF
Config WRT1 = OFF
Config WRT2 = OFF
Config WRT3 = OFF
Config WRTC = OFF
Config WRTB = OFF
Config WRTD = OFF
Config EBTR0 = OFF
Config EBTR1 = OFF
Config EBTR2 = OFF
Config EBTR3 = OFF
Config EBTRB = OFF
Endasm-
Declare Reminders On

HELLO I asked CHAT GPT to create circle but this code not work not create circle but other code is working
Abdullah

Pepe

demo proteus

Abdullah

Abdullah

Abdullah

Abdullah