News:

;) This forum is the property of Proton software developers

Main Menu

TFT Display Page Access Through Button (Nextion)

Started by Aries_Ryan, Today at 08:14 AM

Previous topic - Next topic

Aries_Ryan

I am encountering an issue with page navigation and need some assistance. I have two pages, page1 and page2.
There is a button on page1 intended to redirect to page2, but it fails to do so. Below is my code:
Device = 18F4620
Declare Xtal = 4
Declare Reminders Off

'--- PIC18F4620 Configuration Fuses ---
Config_Start
  OSC = XT       
  FCMEN = OFF   
  IESO = OFF     
  PWRT = On     
  BOREN = SBORDIS
  WDT = OFF     
  MCLRE = On     
  LVP = OFF     
  PBADEN = OFF   
  XINST = OFF   
  Cp0 = OFF     
Config_End

Declare Reminders On


Declare Hserial_Baud = 9600
Declare Hserial_RCSTA = %10010000
Declare Hserial_TXSTA = %00100100  'BRGH=1 (High Speed Baud)
Declare Hserial_Clear = On 

ADCON1 = %00000110 
ADCON0 = %00000001
ADCON2 = %10000111 

TRISA = %11111111               
TRISB = %01000100               
TRISC = %10000000               
TRISD = %00000000               
TRISE = %00000111               

CMCON = 7

Dim Active_Page As Byte

Tft_Cmd = 0
   
    ' Clear Hardware Overrun Error if buffer crashed
    If RCSTA.1 = 1 Then
        RCSTA.4 = 0
        RCSTA.4 = 1
    EndIf
   
    ' Pull ALL bytes from the hardware FIFO buffer
    While PIR1.5 = 1
        Tft_Cmd = RCREG
    Wend
   
    ' Page1 command button, if I press Button "Touch Press Event(1), for prints "M",0
      Then page1 dissapears then go to page2
    If Active_Page = 1 Then
        If Tft_Cmd = "M" Then
            Active_Page = 2
            HSerOut ["page page2", 255, 255, 255]
        EndIf
'-------------------------------'

End
 

Could someone please help me identify the root cause of this problem?

Thanks.
A_Ryan

 

RGV250

Hi,
As you only have 2 pages I cannot see why you would need to test for which page it is on.
Also, I have not used Nextion but Industrial screens I used have a change screen function which does not need comms. Just wondering if Nextion screens have this.

Bob

Pepe

Test this
Device = 18F4620
Declare Xtal = 4
Declare Reminders Off

'--- PIC18F4620 Configuration Fuses ---
Config_Start
    OSC = XT
    FCMEN = OFF
    IESO = OFF
    PWRT = ON
    BOREN = SBORDIS
    WDT = OFF
    MCLRE = ON
    LVP = OFF
    PBADEN = OFF
    XINST = OFF
    CP0 = OFF
Config_End

Declare Reminders On

Declare Hserial_Baud = 9600
Declare Hserial_RCSTA = %10010000
Declare Hserial_TXSTA = %00100100
Declare Hserial_Clear = On

ADCON1 = %00000110
ADCON0 = %00000001
ADCON2 = %10000111

TRISA = %11111111
TRISB = %01000100
TRISC = %10000000
TRISD = %00000000
TRISE = %00000111

CMCON = 7

Dim Active_Page As Byte
Dim Tft_Cmd As Byte

DelayMS 500

' Comenzar en la página 1
HSerOut ["page page1",255,255,255]
Active_Page = 1

Do

    ' Limpiar Overrun
    If RCSTA.1 = 1 Then
        RCSTA.4 = 0
        RCSTA.4 = 1
    EndIf

    ' Procesar todos los bytes recibidos
    While PIR1.5 = 1

        Tft_Cmd = RCREG

        Select Active_Page

            Case 1
                If Tft_Cmd = "M" Then
                    HSerOut ["page page2",255,255,255]
                    Active_Page = 2
                EndIf

            Case 2
                If Tft_Cmd = "N" Then
                    HSerOut ["page page1",255,255,255]
                    Active_Page = 1
                EndIf

        EndSelect

    Wend

Loop

Frizie

Try:  HSEROUT1 ["dp=2", 0xFF, 0xFF, 0xFF]



It is better to create a procedure for this, for example:

;Procedure om Nextion HMI naar opgegeven pagina te gaan of de huidige pagina te verversen
PROC HMIpag(HMI_Pagina AS BYTE)                  ;Laat de HMI naar de opgegeven pagina gaan of ververs de huidige pagina als de HMI zich al op de betreffende pagina bevindt
  DIM  PagString AS STRING * 2                    ;Declareer een stringvariabele voor 2 karakters (max. "99" HMI pagina's)
  STRN PagString = STR$(DEC HMI_Pagina)          ;Zet BYTE variabele 'HMI_Pagina' om naar stringvariabele 'PagString' voor HMI
  HSEROUT1 ["dp=", PagString, 0xFF, 0xFF, 0xFF]  ;Verzend via UART1 de opdracht naar de HMI  (Voorbeeld: dp=1 = pgHome)
ENDPROC


Declare the page names and page numbers exactly the same as in your Nextion screen, e.g.:
SYMBOL pgHome      = 1
SYMBOL pgInfo      = 2
SYMBOL pgInOut     = 3
SYMBOL pgMenu      = 4
SYMBOL pgMotors    = 5


Call it with:
HMIpag(pgHome) ;Verzend via UART1 de opdracht naar de HMI  (Voorbeeld: dp=1 = pgHome)
Ohm sweet Ohm | www.picbasic.nl

ChrisRowe

Hi,
Not sure why you need to involve the PIC in order to swap pages on nextion display using a button on the display.
Just set the button TouchPress event to page x. I always use a "sendme" when page opens to send page info to PIC. It will send 0x66 page number 0xFF,0xFF,0xFF.

Hope this helps ....
regards Chris