Les's ILI9325 Wiki code - Page 6


+ Reply to Thread
Page 6 of 6 FirstFirst ... 456
Results 76 to 89 of 89

Thread: Les's ILI9325 Wiki code93 days old

  1. #76
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    133
    Thumbs Up
    Received: 8
    Given: 12
    Total Downloaded
    2.96 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    The parallel display didn't go to well so I switched to scrolling. That turned out to be easier than I thought. I had routines earlier an they work. The hardest part was to realize that Bottom Fixed Area is defined relative to the bottom:

    Code:
        Device 18F26K22    Declare Xtal 80                                ' 20MHz Xtal
    '    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
    '    Include "18f26k22intosc64.Inc"
    '    On_Hardware_Interrupt Interrupt_handler
    '    Declare Optimiser_Level  3
    '    Declare Dead_Code_Remove = On
      
    
    
        Dim wFSR0 As FSR0L.Word
        Dim wFSR1 As FSR1L.Word
        Dim wFSR2 As FSR2L.Word
               
        Include "rgb565.inc"                        ' List of named internet colors.
    
    
    '    $define ILI9163
        $define ILI9341
    '    $define Use_Parallell
    '    $define Use_SPI1
        Include "ILI9341_9163.inc"                    ' ILI9341 driver
        $define Use_Arial_Bold_16
        '$define Use_Arial_Bold_14
        '$define Use_Times_New_Roman_bold_16
        '$define Use_Times_New_Roman_bold_14
    
    
    
    
        Dim wTmp As Byte
    $define SPI_Read(number_of_bytes,data)            '
        bTmp = number_of_bytes                        '
        wFSR1 =AddressOf(data)                        '
        For bTmp = bTmp To 0 Step - 1                '
            SPI_WR(0,POSTINC1)                        '
        Next
        
    $define SPI_Write(number_of_bytes,data)            '
        bTmp = number_of_bytes                        '
        wFSR1 =AddressOf(data)                        '
        For bTmp = bTmp To 0 Step - 1                '
            SPI_WR(POSTINC1,WREG)                    '
        Next
        
        
        Dim wTopFixedArea As Word                    ' Number of pixels from top        
        Dim wBottomFixedArea As Word                ' Number of pixels from bottom    
        Dim wVerticalScrollArea As Word                ' What is left    
        Dim wScrollStartAddress As Word
     
      
    $define SetupScrollArea                            '
        Low TFT_CS                                    '
        WriteSpiCommand(VSCRDEF)                    '
        WriteSpiData(wTopFixedArea.Byte1)            '
        WriteSpiData(wTopFixedArea.Byte0)            '
        WriteSpiData(wVerticalScrollArea.Byte1)        '
        WriteSpiData(wVerticalScrollArea.Byte0)        '    
        WriteSpiData(wBottomFixedArea.Byte1)        '
        WriteSpiData(wBottomFixedArea.Byte0)        '    
        High TFT_CS
        
    $define ScrollAddress                        '
        Low TFT_CS                                '
        WriteSpiCommand(VSSTADRS)                '
        WriteSpiData(wScrollStartAddress.Byte1)    '    
        WriteSpiData(wScrollStartAddress.Byte0)    '    
        High TFT_CS
        
        
        
    ''    ----------------------------------------------------------------------------
    
    
        DelayMS 100
        InitILI
        DelayMS 100
        SCRorientation0
        
        wTopFixedArea = 20                        ' Number of pixels from top    
        wBottomFixedArea = 20                    ' Number of pixels from bottom    
        wVerticalScrollArea = DISPLAY_HEIGHTH - wBottomFixedArea - wTopFixedArea
    
    
        SetupScrollArea
        
        SetFont(Arial_Bold_16)
        wColor = WHITE
        wPaper = WHITE
        wInk = BLACK
        ClearScreen
        At_XY(10,0)
        PrintString("ILI9341 TFT")
        At_XY(10,30)
        PrintString("ILI9341 TFT")
        At_XY(10,50)
        PrintString("Scrolling demo")
        wColor = RED
        XBlock(0,100,20,20)
        wColor = GREEN
        XBlock(20,100,20,20)
        wColor = BLUE
        XBlock(40,100,20,20)
        wColor = YELLOW
        XBlock(60,100,20,20)
        wColor = MAGENTA
        XBlock(80,100,20,20)
        wColor = CYAN
        XBlock(100,100,20,20)
        For wScrollStartAddress = 0 To 320
            ScrollAddress
            DelayMS 10
        Next
        wScrollStartAddress = 320
        For wScrollStartAddress = wScrollStartAddress To 0 Step - 1
            ScrollAddress
            DelayMS 1
        Next
        Stop
        
        
        Include "fonts.Inc"
    There are two commands SetupScrollArea and ScrollAddress. SetupScrollArea defines the area to scroll and ScrollAddress does the scrolling. If you don't define area ScrollAddress will scroll the whole sreen.
    Flosi Guđmundsson
    Reykjavík

Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #77
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,351
    Thumbs Up
    Received: 43
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    The scrolling is great Flosi. I've now managed to get two different TFT modules I have bought working nicely.
    One small point, the scrolling always goes in the portrait direction, even if the screen orientation is set to landscape or portrait (0, 90, 180 or 270)
    .
    Is this what you intended?

    Cheers
    Charlie

    How did you get the 18F26K22 to run at 80Mhz?
    Last edited by charliecoultas; 25th October 2019 at 14:32.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #78
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    133
    Thumbs Up
    Received: 8
    Given: 12
    Total Downloaded
    2.96 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    No this is just how it works. There is no horizontal scrolling. Only vertical and with the option of having top and or botom static. There is another command, Partial Area (30h)

    Code:
            '    Partial Mode ON (12h)
    '    ----------------------------------------------------------------------------
    
    
    $define PartialModeON                        '
        WriteSpiCommandCS(PTLON)
    
    
    
    
        
    '    Partial Area (30h)        
    '    ----------------------------------------------------------------------------
        
        Dim wStartRow As wYstart
        Dim wEndRow As wYend
        
    $define PartialArea(StartRow,EndRow)        '
        wStartRow = StartRow                    '
        wEndRow = EndRow                        '
        Low TFT_CS                                '
        WriteSpiCommand(PLTAR)                    '
        WriteSpiData(wStartRow,Byte1)            '
        WriteSpiData(wStartRow,Byte0)            '
        WriteSpiData(wEndRow,Byte1)                '
        WriteSpiData(wEndRow,Byte0)                '
        High TFT_CS
    I haven't tried this yet, nor the routines I have written for reading the th display. Ist seems that while the display I have pin marked mosi it seems not connected
    Flosi Guđmundsson
    Reykjavík

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #79
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,425
    Thumbs Up
    Received: 296
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    What I've found with the ILI type of graphic LCDs is that the only real change to make in teh code is the initialisation mechanism for them. The code I wrote uses the start-up commands and values in a flash memory data table so they are easy to change.

    Glad you found use of the BMP converter. I originally wrote it for the Amicus24 board I was developing, but nothing came of that because of the flop and zero money for the Amicus18 I developed. :-(

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #80
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,425
    Thumbs Up
    Received: 296
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    Here's something I created quite a few years ago that used the ILI9325 graphic LCD board. See my stubby little fingers? LOL



    I created it because one of my favourite christmas presents when I was a boy was a stylophone. Mam and Dad also got me the single records so I could play along with them, and the tune I play on the video is one of those tunes. I hadn't played it in quite a few decades, but it came back to me. :-)

    The sound is purely from the PWM peripheral on the 18F25K20 device used on the Amicus18. The vibrato is a software triangle wave modulating the frequency of the square wave PWM output slightly. Just like the stylophone used but with transistors and a Unijunction transistor for the triangle wave modulator. Back in the 1970s I saved up and bought a unijunction transistor (2N2926) and it was like magic to me as a boy making different sounding oscillators from a single transistor. :-)

    Whenever I go to car boot sales, I always look out for the old stylophones and buy them if they are not stupid prices. Ahhhhhh Nostalgia, it's a lovely thing. Especially when I remember my lovely parents. They didn't have a lot of money because dad was a Bricklayer for the local council and this country dumped on its workers when they had finished rebuilding the country after the war, and reduced wages and limited pay rises etc, and they had to save up all year. But we never heard about their money problems when we were kids, and we were so grateful for the christmas presents we received because they both knew what we loved, so the memories and joy of the presents have stayed with me. :-)
    Last edited by top204; 26th October 2019 at 12:08.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #81
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,351
    Thumbs Up
    Received: 43
    Given: 39
    Total Downloaded
    3.36 GB

    1 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    Thanks for the feedback Flosi, it's not a problem, your code works fine.

    Your code shows the 18F26K22 running at 80Mhz, how is that done? External crystal + PPL?

    Les, I love your Stylophone. I think I need to add a "touch" chip to my display module, any idea what chip I need (there's an unpopulated 16 pin smd pad on pcb)

    Charlie

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #82
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,425
    Thumbs Up
    Received: 296
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    The touch chip is the ADS7846. I remember using this type because it was inexpensive and whole lot better than the dreadful Microchip types.

    Here's a screenshot of the touch part of the circuit from the design software. The circuit is a mess in the design package because it has to work not look good in that element of the design. I'm pretty sure the PDF I created for the GLCD board is in the forum's files somewhere.

    Click image for larger version

Name:	GLCD_Touch.jpg
Views:	68
Size:	93.9 KB
ID:	3798

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #83
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,351
    Thumbs Up
    Received: 43
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    Thanks Les.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #84
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,425
    Thumbs Up
    Received: 296
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    Charlie.

    See this little piece of text I wrote on the forum's Wiki for overclocking the 18FxxKxx devices.

    Overclocking the Amicus18 Board to 100MHz

    I remember I had the 18FxxKxx devices working at 100MHz without any problems at all. Just increase the crystal's frequency and add the PLL. The compiler supports a few extra frequencies:

    && (XTAL != 80) // 80MHz Overclocked 20MHz with PLL * 4
    && (XTAL != 88) // 88MHz Overclocked 22MHz with PLL * 4
    && (XTAL != 96) // 96MHz Overclocked 24MHz with PLL * 4
    && (XTAL != 100)) // 100MHz Overclocked 25MHz with PLL * 4


    I was going to add higher frequencies but didn't have the crystals to do the testing beyond 25MHz.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #85
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,351
    Thumbs Up
    Received: 43
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    Ha! As easy as that. Thanks Les.

    I think you wrote some code for a resistive touch screen but I can't find it. Any help appreciated.#

    Charlie

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #86
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    133
    Thumbs Up
    Received: 8
    Given: 12
    Total Downloaded
    2.96 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    I have been playing with this scrolling function for some time now and it seems rather more limited than I thought. I can't find a way to reset the origin.
    Flosi Guđmundsson
    Reykjavík

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #87
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    557
    Thumbs Up
    Received: 36
    Given: 25
    Total Downloaded
    4.40 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    Quote Originally Posted by charliecoultas View Post
    Ha! As easy as that. Thanks Les.

    I think you wrote some code for a resistive touch screen but I can't find it. Any help appreciated.#

    Charlie

    Is this what you're looking for Charlie?

    Code:
    $ifndef _ADS7846_
    $define _ADS7846_
    '
    ' Interface to an ADS7846 Touch Screen Controller
    ' Written by Les Johnson. September 2011
    '
        Include "SPI.inc"                               ' Load the SPI macros into the program
    '
    ' ADS7846 SPI interface pins
    ' Default setting for use with the Amicus Touch Screen Colour LCD Shield
    ' 
    $ifndef ADS_SDO   
        $define ADS_SDO PORTC.5                         ' SPI SDO to ADS7846 DIN (Uses the MSSP1 peripheral)
    $endif
    $ifndef ADS_SDI
        $define ADS_SDI PORTC.4                         ' SPI SDI from ADS7846 DOUT (Uses the MSSP1 peripheral)
    $endif
    $ifndef ADS_SCK
        $define ADS_SCK PORTC.3                         ' SPI SCK to ADS7846 CLK  (Uses the MSSP1 peripheral)
    $endif
    $ifndef ADS_CS
        $define ADS_CS PORTC.1                          ' SPI CS to ADS7846 CS (Active Low)
    $endif 
    
    $ifndef Touch_Sensitivity               
        $define Touch_Sensitivity 64                   ' Sensitivity of the touchscreen to detect a stylus landing on it
    $endif
    '
    ' Screen coordinates for touch calibration (alter as required)
    '    
        $define cScreen_Xminimum 385'370                    ' Raw ADC value from ADS chip for extreme left of the display
        $define cScreen_Yminimum 399'350                    ' Raw ADC value from ADS chip for extreme right of the display
        
        $define cScreen_Xmaximum 2615'3830                   ' Raw ADC value from ADS chip for extreme top of the display
        $define cScreen_Ymaximum 24324'3850                   ' Raw ADC value from ADS chip for extreme bottom of the display
        
        Symbol cScreen_Yrange = (cScreen_Ymaximum - cScreen_Yminimum)     ' Calculate Y ADC range across the LCD
        Symbol cScreen_Xrange = (cScreen_Xmaximum - cScreen_Xminimum)     ' Calculate X ADC range across the LCD
        
        Dim ADS_wAccum As Word System
        Dim ADS_bControl As Byte System
    '
    ' Define some variables used by the Touchscreen subroutines
    '
        Dim ADS_wXlocation As Word                      ' 16-bit X pos location (0 to 239)
        Dim ADS_bXlocation As ADS_wXlocation.Byte0      ' 8-bit X pos location (0 To 239)
        Dim ADS_wYlocation As Word                      ' 16-bit Y pos location (0 To 319)
        
        Dim ADS_wTemp As Word System 
        Dim ADS_dTemp As PP_dAddress.Dword              ' Create an alias to a variable used in ILI9320.inc
        
        Symbol cAmountOfSamples = 8                     ' Amount of samples to take for the averaging. Maximum 8
            
        Dim ADS_bIndex As Byte System
        Dim ADS_wAdres As ADRESL.Word                   ' The raw ADC result given by the ADS7846 touch screen controller chip
    '
    ' ADS7846 Control Byte values
    '    
        Symbol ADS_START          = 000000           ' Start bit (always set)
        Symbol ADS_A2             = 000000           ' A2 bit
        Symbol ADS_A1             = 100000           ' A1 bit
        Symbol ADS_A0             = 010000           ' A0 bit
        Symbol ADS_MODE_8         = 001000           ' Mode bit for 8-bit operation
        Symbol ADS_MODE_12        = 000000           ' Mode bit for 12-bit operation
        Symbol ADS_SINGLE         = 000100           ' Sample setting bit for single ended operation
        Symbol ADS_DIFF           = 000000           ' Sample setting bit for differential operation
        Symbol PWRDWN_CONV_PEN_ON = 000000           ' Power-Down Between Conversions. When each
                                                        ' conversion is finished, the converter enters a
                                                        ' low-power mode. At the start of the next conversion,
                                                        ' the device instantly powers up to full power.
                                                        ' There is no need for additional delays to assure
                                                        ' full operation and the very first conversion is
                                                        ' valid. The Y– switch is on when in power-down.
                                                        ' PENIRQ is enabled
        Symbol REF_OFF_PEN_OFF       = 000001        ' Reference is off and ADC is on. PENIRQ is disabled
        Symbol REF_OFF_ADC_ON_PEN_ON = 000010        ' Reference is on and ADC is off. PENIRQ is enabled
        Symbol PWR_ON_REF_ON_ADC_ON_PEN_OFF = 000011 ' Device is always powered. Reference is on and ADC is on. PENIRQ is disabled
        
        Symbol ADS_MSR_Z1 = 110000
        Symbol ADS_MSR_Z2 = 000000
        Symbol ADS_MSR_Y =  010000
        Symbol ADS_MSR_X =  010000
        
        Symbol cMeasureZ1 = ADS_START | ADS_MSR_Z1 | ADS_MODE_12 | ADS_DIFF | PWR_ON_REF_ON_ADC_ON_PEN_OFF   ' Control byte for a measurement of the Z1 axis
        Symbol cMeasureZ2 = ADS_START | ADS_MSR_Z2 | ADS_MODE_12 | ADS_DIFF | PWR_ON_REF_ON_ADC_ON_PEN_OFF   ' Control byte for a measurement of the Z2 axis
        Symbol cMeasureY = ADS_START | ADS_MSR_Y | ADS_MODE_12 | ADS_DIFF | PWR_ON_REF_ON_ADC_ON_PEN_OFF     ' Control byte for a measurement of the X axis
        Symbol cMeasureX = ADS_START | ADS_MSR_X | ADS_MODE_12 | ADS_DIFF | PWR_ON_REF_ON_ADC_ON_PEN_OFF     ' Control byte for a measurement of the Y axis
    '
    ' Helper defines
    '   
    $ifndef True
        $define True 1
    $endif
    $ifndef False
        $define False 0
    $endif
    
    $define tStylusOff False
    $define tStylusOn True
    
    '--------------------------------------------------------------------    
        GoTo ADS_Main                                   ' Jump over the subroutines and initialise the SPI interface                        
    '--------------------------------------------------------------------
    ' Helper routine to take a measurement from the touch sensor and average the results
    ' Input     : WREG holds the control byte
    ' Output    : ADS_wAdres holds the ADC value read from the touch chip
    ' Notes     : Performs a simple averaging mechanism on each ADC result
    '
    $define hTouch_GetSample(pControl) '
        WREG = pControl '
        _Get_Sample
    
    _Get_Sample Macro- 
        GoSub __Get_Sample
    Endm
    
    #ifMacro- _Get_Sample, _Touch_Active, _Touch_Get
    __Get_Sample:
        
        ADS_bControl = WREG                             ' Get the control byte into its working variable
        ADS_wAccum = 0
        ADS_bIndex = 0
        Repeat
            Clear ADS_CS                                ' Enable the SPI interface  
            WriteSPI(ADS_bControl)                      ' Send the control Byte
            ADS_wAdres.Byte1 = ReadSPI()                ' Get the high byte 
            ADS_wAdres.Byte0 = ReadSPI()                ' Get the low byte
            Set ADS_CS                                  ' Disable the SPI interface
            ADS_wAdres = ADS_wAdres >> 3
            ADS_wAdres.12 = 0
            ADS_wAccum = ADS_wAccum + ADS_wAdres        ' Add the ADC result to the accumualtor
            DelayUS 500                                 ' Allow the screen to settle before taking the next reading
            Inc ADS_bIndex
        Until ADS_bIndex >= cAmountOfSamples
        ADS_wAdres = ADS_wAccum / cAmountOfSamples
        Return
    #endIfMacro-
    
    '------------------------------------------------------------------------------------------------
    ' Test if the screen has been touched
    ' Input     : None
    ' Output    : WREG returns 0 if the display is not being touched by the stylus
    '           : ADS_wAdres holds the Z axis of the screen. i.e. touch pressure value
    ' Notes     : Uses the Z1 axis of the touch screen
    '           : Threshold value for stylus detect is user defined in constant Touch_Sensitivity
    '
    $define Touch_Active() _Touch_Active
    
    _Touch_Active Macro- \Byte
        GoSub __Touch_Active
        Return_WREG
    Endm
    
    #ifMacro- _Touch_Active
    __Touch_Active:
        hTouch_GetSample(cMeasureZ1)                    ' Z1 Conversion, 12-bit into ADS_wAdres
        If ADS_wAdres >= Touch_Sensitivity Then         ' Is the Z axis value greater than the set threshold?
            WREG = tStylusOn                            ' Yes. So the screen must have been touched   
            Return                                      ' Exit the routine immediately
        EndIf
        WREG = tStylusOff                               ' Return the defualt setting for the screen not being touched
        Return
    #endIfMacro-
    
    '--------------------------------------------------------------------
    ' Get the Xpos and Ypos positions
    ' Input     : None
    ' Output    : ADS_wXlocation holds the pixel X position of the stylus (0 to 239)
    '           : ADS_wYlocation holds the pixel Y position of the stylus (0 to 319)
    '           : WREG returns holding false (0) if the stylus is outside the LCD's boundaries
    '           : Otherwise WREG returns true (1)
    ' Notes     : ADS_wXlocation can be picked up by using the Touch_X macro
    '           : ADS_wYlocation can be picked up by using the Touch_Y Macro
    '
    $define Touch_Get() _Touch_Get
    
    _Touch_Get Macro- \Byte
        GoSub __Touch_Get
        Return_WREG
    Endm
    
    #ifMacro- _Touch_Get
    __Touch_Get:      
        hTouch_GetSample(cMeasureX)                         ' X Conversion, 12-bit into ADS_wAdres
        ADS_dTemp = (ADS_wAdres - cScreen_Xminimum) * 240   ' \ Calculate the stylus X location (n * 240)
        ADS_wXlocation = ADS_dTemp / cScreen_Xrange         ' /
        If ADS_bXlocation > 239 Then                        ' Is the stylus outside the LCD's X boundary?
            WREG = False                                    ' Yes. So indicate if the stylus value is outside the LCD's X boundary
            Return                                          ' Exit the routine immediately
        EndIf   
        hTouch_GetSample(cMeasureY)                         ' Y Conversion, 12-bit into ADS_wAdres 
        ADS_dTemp = (ADS_wAdres - cScreen_Yminimum) * 320   ' \ Calculate the stylus Y location (n * 320)
        ADS_wYlocation = ADS_dTemp / cScreen_Yrange         ' /
        If ADS_wYlocation > 319 Then                        ' Is the stylus outside the LCD's Y boundary?
            WREG = False                                    ' Yes. So indicate If the stylus value is outside the LCD's Y boundary
            Return                                          ' Exit the routine immediately
        EndIf
        WREG = True                                         ' Exit with WREG holding True for a good touch
        Return
    #endIfMacro-
    '----------------------------------------------------------------------------------------------
    $define Touch_X() ADS_wXlocation.Byte0                  ' 8-bit X pos location (0 To 239)
    '----------------------------------------------------------------------------------------------
    $define Touch_Y() ADS_wYlocation                        ' 16-bit Y pos location (0 To 319)
    '----------------------------------------------------------------------------------------------
    ' Check of the Stylus is within a certain area of the LCD
    ' Input     : WREG is the Top-Left X coordinate of the area to check
    '           : Glcd_wYpos_S is the Top-Left Y coordinate of the area to check
    '           : Glcd_bXpos_E is the Bottom-Right X coordinate of the area to check
    '           : Glcd_wYpos_E is the Bottom-Right Y coordinate of the area to check
    ' Output    : WREG = 1 if Stylus is within the area, else 0
    ' Notes     : Re-uses variables declared in ILI9320.inc
    ' Syntax    :
    ' Var = Touch_Hotspot(Top-Left X coord, Top-Left Y coord, Bottom-Right X coord, Bottom-Right Y coord)
    '
    ' pXstart, pYstart
    '           X------------------------
    '           |                       |
    '           |                       |
    '           |                       |
    '           |                       |
    '           ------------------------X
    '                           pXend, pYend
    '   
    $define Touch_HotSpot(pXstart, pYstart, pXend, pYend) _mHotSpot pXstart, pYstart, pXend, pYend 
    
    _mHotSpot Macro- pXposStart, pYposStart, pXposEnd, pYposEnd \Byte
        
        #if((Prm_2 == Num8) || (Prm_2 == Num16) || (Prm_2 == Num32))
            Num_Word pYposStart , Glcd_wYpos_S
        #endif
        #if(Prm_2 == Byte)
            Byte_Word pYposStart , Glcd_wYpos_S
        #endif
        #if((Prm_2 == Word) || (Prm_2 == Dword))
            Word_Word pYposStart , Glcd_wYpos_S
        #endif
    
        #if((Prm_3 == Num8) || (Prm_3 == Num16) || (Prm_3 == Num32))
            Num_Byte pXposEnd , Glcd_bXpos_E
        #endif
        #if((Prm_3 == Byte) || (Prm_3 == Word) || (Prm_3 == Dword))
            Byte_Byte pXposEnd , Glcd_bXpos_E
        #endif 
    
        #if((Prm_4 == Num8) || (Prm_4 == Num16) || (Prm_4 == Num32))
            Num_Word pYposEnd , Glcd_wYpos_E
        #endif
        #if(Prm_4 == Byte)
            Byte_Word pYposEnd , Glcd_wYpos_E
        #endif 
        #if((Prm_4 == Word) || (Prm_4 == Dword))
            Word_Word pYposEnd , Glcd_wYpos_E
        #endif 
        
        #if((Prm_1 == Num8) || (Prm_1 == Num16) || (Prm_1 == Num32))
            Num_Wreg pXposStart
        #endif
        #if((Prm_1 == Byte) || (Prm_1 == Word) || (Prm_1 == Dword))
            Byte_Wreg pXposStart
        #endif    
        GoSub _HotSpot   
        Return_WREG
        Endm
    
    #ifMacro- _mHotSpot
    _HotSpot:
        If ADS_bXlocation >= WREG Then
            If ADS_wYlocation >= Glcd_wYpos_S Then
                If ADS_bXlocation <= Glcd_bXpos_E Then
                    If ADS_wYlocation <= Glcd_wYpos_E Then
                        WREG = True
                        Return
                    EndIf
                EndIf
            EndIf
        EndIf
        WREG = False
        Return
    #endIfMacro-
    '----------------------------------------------------------------------------------------------
    ' Check if the Stylus is within a certain area of the LCD with the coordinates held in a code memory table
    ' Input     : Reads position data from a cdata table pointed to by TBLPTRL\H
    ' Output    : WREG = 1 if Stylus is within the area, else 0
    ' Notes     : Table format is Xpos_Start(8-bit), Ypos_Start(16-bit), Xpos_End(8-bit), Ypos_End(16-bit)
    '           : Cdata Byte Xpos_Start, Word, Ypos_Start, Byte Xpos_End, Word Ypos_End
    ' Syntax:
    ' Var = Touch_HotspotTable(pTableAddress)
    '
    ' Xpos_Start, Ypos_Start
    '           X------------------------
    '           |                       |
    '           |                       |
    '           |                       |
    '           |                       |
    '           ------------------------X
    '                           Xpos_End, Ypos_End
    '   
    $define Touch_TableHotSpot(pTableAddress) _mTableHotSpot pTableAddress 
    
    _mTableHotSpot Macro- pTableAddress \Byte   
        
        #if(Prm_1 == Label)
            Label_Word pTableAddress, ILI_wTblPtr
        #endif
        #if((Prm_1 == Num8) || (Prm_1 == Num16) || (Prm_1 == Num32))
            Num_Word pXposStart
        #endif
        #if(Prm_1 == Byte)
            Byte_Word pTableAddress, ILI_wTblPtr
        #endif
        #if((Prm_1 == Word) || (Prm_1 == Dword))
            Word_Word pTableAddress, ILI_wTblPtr
        #endif  
        GoSub _TableHotSpot
        Return_WREG
        Endm
    
    #ifMacro- _mTableHotSpot
    _TableHotSpot:      
        Tblrd*+                                         ' Read 8-bit X start position
        If ADS_bXlocation >= TABLAT Then                ' Is the stylus X location greater than the required X start position?
            Tblrd*+                                     ' Yes. So read the low byte of Y start position
            Glcd_wParam.Byte0 = TABLAT                  ' Store it
            Tblrd*+                                     ' Read the high byte of Y start position
            Glcd_wParam.Byte1 = TABLAT                  ' Store it
            If ADS_wYlocation >= Glcd_wParam Then       ' Is the stylus Y location greater than the required Y start position?
                Tblrd*+                                 ' Yes. So read the 8-bit X end position
                If ADS_bXlocation <= TABLAT Then        ' Is the stylus X location less than the required X end position?
                    Tblrd*+                             ' Yes. So read the low byte of Y end position
                    Glcd_wParam.Byte0 = TABLAT          ' Store it
                    Tblrd*+                             ' Read the high byte of Y End position
                    Glcd_wParam.Byte1 = TABLAT          ' Store it
                    If ADS_wYlocation <= Glcd_wParam Then ' Is the stylus Y location less than the required Y end position? 
                        WREG = True                     ' Yes. So return a positive result
                        Return                          ' Exit the routine
                    EndIf
                EndIf
            EndIf
        EndIf
        WREG = False
        Return
    #endIfMacro-
    '--------------------------------------------------------------------
    ' Initialise the SPI interface to the ADS7846 Touch Screen Controller
    ' Input     : None
    ' Output    : None
    ' Notes     : Opens the SPI peripheral in mode 0:0 at 4MHz
    '
    $define Touch_Init() _Touch_Init
    
    _Touch_Init Macro-
        GoSub __Touch_Init
        Endm
     
    #ifMacro- _Touch_Init   
    __Touch_Init:
    '
    ' Setup the ADS7846 SPI lines
    '
        High ADS_CS                                     ' Hold the ADS chip's SPI interface off   
        OpenSPI(SPI_FOSC_16, MODE_00, SMPMID)           ' Open the SPI peripheral (4MHz, Mode 0:0, Sample in middle)   
        Return
    #endIfMacro-    
    '--------------------------------------------------------------------
    ADS_Main:  
        Touch_Init()
    $endif
    Bob
    Last edited by Mellbreak; 29th October 2019 at 10:29.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #88
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,351
    Thumbs Up
    Received: 43
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    Wow! I think that's it Bob. Many thanks.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #89
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    133
    Thumbs Up
    Received: 8
    Given: 12
    Total Downloaded
    2.96 GB

    0 Not allowed!

    Default Re: Les's ILI9325 Wiki code

    Les touchscreen code is one of the files that come with the code that this tread is about. There are SD card routines to.
    Flosi Guđmundsson
    Reykjavík

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. New Wiki entry for interfacing to an ILI9325 Colour Graphic LCD
      By top204 in forum Proton Plus Compiler v3
      Replies: 11
      Last Post: 17th March 2019, 15:55
    2. Les's WS2812 code
      By RGV250 in forum Proton Plus Compiler v3
      Replies: 25
      Last Post: 10th November 2017, 20:03
    3. [SOLVED !] Convert existing ILI9320 code to ILI9325
      By VaGyver in forum LCD module
      Replies: 14
      Last Post: 27th January 2016, 08:36
    4. Barak's Wiki and code on nRF24L01+. ACK with payload fail.
      By towlerg in forum Master Synchronous Serial Port (MSSP) module / 3-wire SPI / I2C™ / Master and Slave modes
      Replies: 6
      Last Post: 4th December 2014, 03:21
    5. code examples in the wiki = terrible reading experience (to me)
      By Joerideman in forum Website / Forum Issues
      Replies: 0
      Last Post: 11th October 2011, 14:45

    Members who have read this thread since 6th December 2019, 12:40 : 0

    Actions :  (Set Date)  (Clear Date)

    You do not have permission to view the list of names.

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts