Execute a predefined set of codes after the page is switched in Dwin Display

I'm trying to execute a predefined set of codes after the page is switched in Dwin Display

 //Below simple code can be used:

  int a = 1;
  int b = 2;
  int c = 0;
  c = a + b;
  Serial.print(a);
  Serial.print("+");
  Serial.print(b);
  Serial.print("=");
  Serial.print(c);
  Serial.println();
  a++;
  b++;

//Controle should keep on executing the above code till the next page is switched.



How is the page being switched from serial control or by touching the screen?

It switches by touch.

One of the touch controls available is return keycode.
This needs a VP address (a ram address) over 0x1000 and a keycode set, I tend to use 31 for page 1, 32 for page 2 etc. also set the next page to go to.
The serial sends back the VP address and the keycode.
See my github how to use these in code.

The relays example should give you a idea of how to work with the serial.

I should have said this is for the T5L displays not the older K series or the Linux or Android ones, what display have you?

Thank Satspares,
I'll try it.
I'm using T5L display. Thanks again

I want to change the state of GPIO pins on my ESP32, Interrupt has to be triggered by Dwin display. There is no physical button to be used.

Can someone tell me how to do it?

Is it an interrupt from display GUI or from external source(i.e sensor) ?

Hello Noiasca,
Below are the details that you asked

  1. Datasheet of display: dmg80480c070-03wtc datasheet

  2. I'm not using any specific library as such. I have used #include <HardwareSerial.h> to establish UART connection.

  3. Below is my sample code

#include <HardwareSerial.h>
HardwareSerial SerialPort(2); // Connect DWIN via UART2

const byte rxPin = 16; //rx2
const byte txPin = 17; //tx2
//HardwareSerial dwin(1);
unsigned char Buffer[9];
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  //Begin serial communication DWIN
  SerialPort.begin(115200, SERIAL_8N1, rxPin, txPin);

}

void loop() {
  // put your main code here, to run repeatedly:
  display_control();
  delay(50);
}

void display_control()
{
  if (SerialPort.available())
  {
    for (int i = 0; i <= 8; i++) //this loop will store whole frame in buffer array HEX Data coming from Touch Display Button.
    {
      Buffer[i] = SerialPort.read();
    }
 
    if (Buffer[0] == 0X5A)
    {
      switch (Buffer[4])
      {
        case 0x21:   //First Stage Button
        while(Buffer[4] == 0X21)
        {
          Serial.println("First Stage Button is Pressed");  
        }
          break;

        case 0x22:   //Second Stage Button
        while(Buffer[4] == 0X22)
        {
          Serial.println("Second Stage Button is Pressed");   
        }
          break;
          
        case 0x23:   //Third Stage Button
        while(Buffer[4] == 0X23)
        {
          Serial.println("Third Stage Button is Pressed");    
        }
          break;

        case 0x24:   //Fourth Stage Button
        while(Buffer[4] == 0X24)
        {
          Serial.println("Fourth Stage Button is Pressed");    
        }
          break;
 
        default:
          Serial.println("No data..");
      }
    }
  }
}

There 5 touch buttons on my display, each button returns a specific HEX data and my codes read's it and enter into the specific WHILE loop, now I want the control to be shifted to a different WHILE loop depending upon user input.

Dear b707,
The interrupt is triggered from the display GUI.

Not a correct use of the word "interrupt". :wink:

You code receives "input" from the display GUI and changes the output pins accordingly.

These while loops seem wrong to me

      case 0x23:   //Third Stage Button
        while(Buffer[4] == 0X23)
        {
          Serial.println("Third Stage Button is Pressed");    
        }
          break;

because it is an infinite loop. The expression Buffer[4] == 0X23 will remain true forever because the code is trapped in the while loop and the values in the array can never be updated.

Try something like

      case 0x23:   //Third Stage Button
          digitalWrite(myChosenOutputPin, HIGH);
          break;

With a dwin display buffer[4] is a part of the control address to allow you to know which control is returning data.
Depending on the control you probably need buffer[8] which is the data returned by the control if it's a switch 1 or 0.
You should check buffer[4] to determine which control has been touched then buffer[8] for its state.
See the relays example..

https://github.com/satspares/DWIN_DGUS_HMI/tree/master/examples

Thank you all,
I was able to create Interrupts.

Sorry, but you still called it "interrupt"... but there are no interrupts in your code in #4

Here is my updated code:

#include <HardwareSerial.h>
HardwareSerial SerialPort(2); // Connect DWIN via UART2

const byte rxPin = 16; //rx2
const byte txPin = 17; //tx2
//HardwareSerial dwin(1);
unsigned char Buffer[9];

void IRAM_ATTR ISR_H() {
//    Statements;
    Serial.println("Home Page in Progress");
}

void IRAM_ATTR ISR_1() {
//    Statements;
  Serial.println("First Stage in Progress");
}

void IRAM_ATTR ISR_2() {
//    Statements;
  Serial.println("Second Stage in Progress");
}

void IRAM_ATTR ISR_3() {
//    Statements;
  Serial.println("Third Stage in Progress");
}

void IRAM_ATTR ISR_4() {
//    Statements;
  Serial.println("Fourth Stage in Progress");
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  //Begin serial communication DWIN
  SerialPort.begin(115200, SERIAL_8N1, rxPin, txPin);
  pinMode(12, OUTPUT);    // sets the digital pin 13 as output
  pinMode(13, OUTPUT);    // sets the digital pin 12 as output
  pinMode(14, OUTPUT);    // sets the digital pin 14 as output
  pinMode(15, OUTPUT);    // sets the digital pin 32 as output
  pinMode(32, OUTPUT);    // sets the digital pin 35 as output
  
  attachInterrupt(digitalPinToInterrupt(12), ISR_H, HIGH);
  attachInterrupt(digitalPinToInterrupt(13), ISR_1, HIGH);
  attachInterrupt(digitalPinToInterrupt(14), ISR_2, HIGH);
  attachInterrupt(digitalPinToInterrupt(15), ISR_3, HIGH);
  attachInterrupt(digitalPinToInterrupt(32), ISR_4, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  display_control();
  delay(50);
  if(digitalRead(12) == HIGH){
    Serial.println("Home Page Loop");
  }
  if(digitalRead(13) == HIGH){
    Serial.println("First Page Loop");
  }
  if(digitalRead(14) == HIGH){
    Serial.println("Second Page Loop");
  }
  if(digitalRead(15) == HIGH){
    Serial.println("Third Page Loop");
  }
  if(digitalRead(32) == HIGH){
    Serial.println("Fourth Page Loop");
  }
}

void display_control(){
  if (SerialPort.available())
  {
    for (int i = 0; i <= 8; i++) //this loop will store whole frame in buffer array HEX Data coming from Touch Display Button.
    {
      Buffer[i] = SerialPort.read();
            Serial.println(Buffer[i]);
    }
 
    if (Buffer[0] == 0X5A)
    {
      switch (Buffer[4])
      {
        case 0x21:   //First Stage Button
          digitalWrite(12, LOW); // sets Home page OFF
          digitalWrite(13, HIGH); // sets First Stage ON
          digitalWrite(14, LOW); // sets Second Stage OFF
          digitalWrite(15, LOW); // sets Third Stage OFF
          digitalWrite(32, LOW); // sets Fourth Stage OFF
          Serial.println("First Stage Button is Pressed"); 
          break;

        case 0x22:   //Second Stage Button
          digitalWrite(12, LOW); // sets Home page OFF
          digitalWrite(13, LOW); // sets First Stage OFF
          digitalWrite(14, HIGH); // sets Second Stage ON
          digitalWrite(15, LOW); // sets Third Stage OFF
          digitalWrite(32, LOW); // sets Fourth Stage OFF
          Serial.println("Second Stage Button is Pressed");   
          break;
          
        case 0x23:   //Third Stage Button
          digitalWrite(12, LOW); // sets Home page OFF
          digitalWrite(13, LOW); // sets First Stage OFF
          digitalWrite(14, LOW); // sets Second Stage OFF
          digitalWrite(15, HIGH); // sets Third Stage ON
          digitalWrite(32, LOW); // sets Fourth Stage OFF
          Serial.println("Third Stage Button is Pressed");    
          break;

        case 0x24:   //Fourth Stage Button
          digitalWrite(12, LOW); // sets Home page OFF
          digitalWrite(13, LOW); // sets First Stage OFF
          digitalWrite(14, LOW); // sets Second Stage OFF
          digitalWrite(15, LOW); // sets Third Stage OFF
          digitalWrite(32, HIGH); // sets Fourth Stage ON
          Serial.println("Fourth Stage Button is Pressed");    
          break;
 
        default:
          digitalWrite(12, HIGH); // sets Home page ON
          digitalWrite(13, LOW); // sets First Stage OFF
          digitalWrite(14, LOW); // sets Second Stage OFF
          digitalWrite(15, LOW); // sets Third Stage OFF
          digitalWrite(32, LOW); // sets Fourth Stage OFF
          Serial.println("Home Page Button is Pressed");
      }
    }
  }
}


//detachInterrupt(GPIOPin);

Your way of using the interrupts is absolute pointless. You was adviced that at your another topic. I am quit.
Good luck for your project.

Please merge your two topics, its contents are close related. Opening more than one thread about the same subject is violation of the forum rules.

I'm trying to read the HEX data (UART2) coming from the Dwin display when a button is pressed. I'm using ESP32 as my MCU and sensors are communicating via the I2C bus.
Based on the HEX data I'm changing the status of some GPIO pins so that I can use hardware interrupts within my code. Now when I try to read the HEX data that is stored in unsigned char Buffer[9]; is not the one I'm looking for I assume it is corrupted. I'm still a beginner and might a done some silly mistakes and not been able to figure them out. Below is my sketch. Any help will be much appreciated.

#include <Arduino.h>
#include <SensirionI2cScd30.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include "RTClib.h"
#include <BH1750.h>
#include <HardwareSerial.h>
HardwareSerial SerialPort(2); // Connect DWIN via UART2

const byte rxPin = 16; //rx2
const byte txPin = 17; //tx2

RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};


SensirionI2cScd30 sensor;
unsigned char Buffer[9];
static char errorMessage[128];
static int16_t error;

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

BH1750 lightMeter(0x23);

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;

void IRAM_ATTR ISR_H() {
//    Statements;
    Serial.println("Home Page in Progress");
    Buffer[0] == 0X5A;
    Buffer[4] == 0X20;
}

void IRAM_ATTR ISR_1() {
//    Statements;
  Serial.println("First Stage in Progress");
    Buffer[0] == 0X5A;
    Buffer[4] == 0X21;
}

void IRAM_ATTR ISR_2() {
//    Statements;
  Serial.println("Second Stage in Progress");
    Buffer[0] == 0X5A;
    Buffer[4] == 0X22;
}

void IRAM_ATTR ISR_3() {
//    Statements;
  Serial.println("Third Stage in Progress");
    Buffer[0] == 0X5A;
    Buffer[4] == 0X23;
}

void IRAM_ATTR ISR_4() {
//    Statements;
  Serial.println("Fourth Stage in Progress");
    Buffer[0] == 0X5A;
    Buffer[4] == 0X24;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  //Begin serial communication DWIN
  SerialPort.begin(115200, SERIAL_8N1, rxPin, txPin);
  
  pinMode(12, OUTPUT);    // sets the digital pin 13 as output for Home Page
  pinMode(13, OUTPUT);    // sets the digital pin 12 as output for First Page
  pinMode(14, OUTPUT);    // sets the digital pin 14 as output for Second Page
  pinMode(15, OUTPUT);    // sets the digital pin 32 as output for Third Page
  pinMode(32, OUTPUT);    // sets the digital pin 35 as output for Fourth Page

  pinMode(27, OUTPUT);// connected to Terminal-01 of Relay
  pinMode(26, OUTPUT);// connected to Terminal-02 of Relay
  pinMode(25, OUTPUT);// connected to Terminal-03 of Relay
  pinMode(33, OUTPUT);// connected to Terminal-03 of Relay
  
  attachInterrupt(digitalPinToInterrupt(12), ISR_H, HIGH);// Interrupt for Home Page
  attachInterrupt(digitalPinToInterrupt(13), ISR_1, HIGH);// Interrupt for First Page
  attachInterrupt(digitalPinToInterrupt(14), ISR_2, HIGH);// Interrupt for Second Page
  attachInterrupt(digitalPinToInterrupt(15), ISR_3, HIGH);// Interrupt for Third Page
  attachInterrupt(digitalPinToInterrupt(32), ISR_4, HIGH);// Interrupt for Fourth Page

  // Initialize the I2C bus (BH1750 library doesn't do this automatically)
  // On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
  // begin returns a boolean that can be used to detect setup problems.
    Wire.begin();
    
    sensor.begin(Wire, SCD30_I2C_ADDR_61);

    sensor.stopPeriodicMeasurement();
    sensor.softReset();
    delay(2000);//**********************************************
    uint8_t major = 0;
    uint8_t minor = 0;
    error = sensor.readFirmwareVersion(major, minor);
    if (error != NO_ERROR) {
        Serial.print("Error trying to execute readFirmwareVersion(): ");
        errorToString(error, errorMessage, sizeof errorMessage);
        Serial.println(errorMessage);
        return;
    }
    Serial.print("firmware version major: ");
    Serial.print(major);
    Serial.print("\t");
    Serial.print("minor: ");
    Serial.print(minor);
    Serial.println();
    error = sensor.startPeriodicMeasurement(0);
    if (error != NO_ERROR) {
        Serial.print("Error trying to execute startPeriodicMeasurement(): ");
        errorToString(error, errorMessage, sizeof errorMessage);
        Serial.println(errorMessage);
        return;
    }
    
  Serial.println(F("BME280 test"));

  bool status;

    // default settings
  // (you can also pass in a Wire library object like &Wire2)
  status = bme.begin();  
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
  
  Serial.println("-- Default Test --");
//  delayTime = 1000;//************************************

  Serial.println();

  if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
    Serial.println(F("BH1750 Advanced begin"));
  } else {
    Serial.println(F("Error initialising BH1750"));
  }
  #ifndef ESP8266
    while (!Serial); // wait for serial port to connect. Needed for native USB
  #endif

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    rtc.adjust(DateTime(2023, 6, 26, 7, 13, 0));
  }

  // When time needs to be re-set on a previously configured device, the
  // following line sets the RTC to the date & time this sketch was compiled
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // January 21, 2014 at 3am you would call:
  //rtc.adjust(DateTime(2023, 6, 25, 12, 46, 59)); //Adjust Time Here
}

void loop() {
  display_control();
//  delay(50);
  
  // put your main code here, to run repeatedly:
  float co2Concentration = 0.0;
  float temperature = 0.0;
  float humidity = 0.0;
  int lux = 0;

    DateTime now = rtc.now();

    error = sensor.blockingReadMeasurementData(co2Concentration, temperature, humidity);
    if (error != NO_ERROR) {
        Serial.print("Error trying to execute blockingReadMeasurementData(): ");
        errorToString(error, errorMessage, sizeof errorMessage);
        Serial.println(errorMessage);
        return;
    } 

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
  
  error = sensor.blockingReadMeasurementData(co2Concentration, temperature, humidity);
    if (error != NO_ERROR) {
        Serial.print("Error trying to execute blockingReadMeasurementData(): ");
        errorToString(error, errorMessage, sizeof errorMessage);
        Serial.println(errorMessage);
        return;
    } 

    if (lightMeter.measurementReady()) {
    lux = lightMeter.readLightLevel();
    Serial.print("Light Intensity: ");
    Serial.print(lux);
    Serial.println(" Lux");
  }


    int c = (int)co2Concentration;
    temperature = bme.readTemperature();
    humidity = bme.readHumidity();
    float t = temperature;
    float h = humidity;
    int l = lux;
  
    Serial.print("Co2 Concentration: ");
    Serial.print(c);
    Serial.print(" PPM \t");
    Serial.println();

    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
    
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.println(" %");
    Serial.println("***********************************");
    
    sendFloatNumber(t,0x61);
    sendFloatNumber(h,0x62);
    sendIntNumber(l,0x63);
    sendIntNumber(c,0x64);

    if (now.hour() >= 7 && now.hour() < 19){
      digitalWrite(27, LOW);// turn relay-01 ON
      Serial.println();
      Serial.println("Light is ON");
    }
    else{
      digitalWrite(27, HIGH);// turn relay-01 OFF
      Serial.println();
      Serial.println("Light is OFF");
    }
  
  if(digitalRead(12) == HIGH){
    Serial.println("Home Page Loop");
  }
  
  if(digitalRead(13) == HIGH){
    Serial.println("First Page Loop");
    
    if (bme.readTemperature() > 24 && bme.readTemperature() < 26 || bme.readTemperature() < 24){
      digitalWrite(26, HIGH);// turn relay-02 OFF
      Serial.println("Chiller is OFF");
    }
    else{
      digitalWrite(26, LOW);// turn relay-02 ON
      Serial.println("Chiller is ON");
    }
    
    if (bme.readHumidity() > 65 && bme.readHumidity() < 75 || bme.readHumidity() > 75){
      digitalWrite(25, HIGH);// turn relay-03 OFF
      Serial.println("Humidifier is OFF");
    }
    else{
      digitalWrite(25, LOW);// turn relay-03 ON
      Serial.println("Humidifier is ON");
    }

    if (co2Concentration > 2000 && co2Concentration < 4000 || co2Concentration > 4000){
      digitalWrite(33, HIGH);// turn relay-04 OFF
      Serial.println("Co2 Valve is OFF");
      Serial.println();
    }
    else{
      digitalWrite(33, LOW);// turn relay-04 ON
      Serial.println("Co2 Valve is ON");
      Serial.println();
    }
  }
  if(digitalRead(14) == HIGH){
    Serial.println("Second Page Loop");
    if (bme.readTemperature() > 20 && bme.readTemperature() < 25 || bme.readTemperature() < 20){
      digitalWrite(26, HIGH);// turn relay-02 OFF
      Serial.println("Chiller is OFF");
    }
    else{
      digitalWrite(26, LOW);// turn relay-02 ON
      Serial.println("Chiller is ON");
    }
    
    if (bme.readHumidity() > 80 && bme.readHumidity() < 90 || bme.readHumidity() > 90){
      digitalWrite(25, HIGH);// turn relay-03 OFF
      Serial.println("Humidifier is OFF");
    }
    else{
      digitalWrite(25, LOW);// turn relay-03 ON
      Serial.println("Humidifier is ON");
    }

    if (co2Concentration > 700 && co2Concentration < 800 || co2Concentration > 800){
      digitalWrite(33, HIGH);// turn relay-04 OFF
      Serial.println("Co2 Valve is OFF");
      Serial.println();
    }
    else{
      digitalWrite(33, LOW);// turn relay-04 ON
      Serial.println("Co2 Valve is ON");
      Serial.println();
    }
  }
  if(digitalRead(15) == HIGH){
    Serial.println("Third Page Loop");
    
    if (bme.readTemperature() > 10 && bme.readTemperature() < 20 || bme.readTemperature() < 10){
      digitalWrite(26, HIGH);// turn relay-02 OFF
      Serial.println("Chiller is OFF");
    }
    else{
      digitalWrite(26, LOW);// turn relay-02 ON
      Serial.println("Chiller is ON");
    }
    
    if (bme.readHumidity() > 80 && bme.readHumidity() < 90 || bme.readHumidity() > 90){
      digitalWrite(25, HIGH);// turn relay-03 OFF
      Serial.println("Humidifier is OFF");
    }
    else{
      digitalWrite(25, LOW);// turn relay-03 ON
      Serial.println("Humidifier is ON");
    }

    if (co2Concentration > 750 && co2Concentration < 850 || co2Concentration > 850){
      digitalWrite(33, HIGH);// turn relay-04 OFF
      Serial.println("Co2 Valve is OFF");
      Serial.println();
    }
    else{
      digitalWrite(33, LOW);// turn relay-04 ON
      Serial.println("Co2 Valve is ON");
      Serial.println();
    }
  }
  if(digitalRead(32) == HIGH){
    Serial.println("Fourth Page Loop");
    if (bme.readTemperature() > 10 && bme.readTemperature() < 17 || bme.readTemperature() < 10){
      digitalWrite(26, HIGH);// turn relay-02 OFF
      Serial.println("Chiller is OFF");
    }
    else{
      digitalWrite(26, LOW);// turn relay-02 ON
      Serial.println("Chiller is ON");
    }
    
    if (bme.readHumidity() > 80 && bme.readHumidity() < 90 || bme.readHumidity() > 90){
      digitalWrite(25, HIGH);// turn relay-03 OFF
      Serial.println("Humidifier is OFF");
    }
    else{
      digitalWrite(25, LOW);// turn relay-03 ON
      Serial.println("Humidifier is ON");
    }

    if (co2Concentration > 750 && co2Concentration < 850 || co2Concentration > 850){
      digitalWrite(33, HIGH);// turn relay-04 OFF
      Serial.println("Co2 Valve is OFF");
      Serial.println();
    }
    else{
      digitalWrite(33, LOW);// turn relay-04 ON
      Serial.println("Co2 Valve is ON");
      Serial.println();
    }
  }
}

void display_control(){
  if (SerialPort.available())
  {
    Serial.println("Serial Port is available");
//    delay(1000);
    for (int i = 0; i <= 8; i++) //this loop will store whole frame in buffer array HEX Data coming from Touch Display Button.
    {
      Buffer[i] = SerialPort.read();
      Serial.println(Buffer[i]);
    }
 
    if (Buffer[0] == 0X5A)
    {
      if (Buffer[4] == 0X21){//First Stage Button 
          digitalWrite(12, LOW); // sets Home page OFF
          digitalWrite(13, HIGH); // sets First Stage ON
          digitalWrite(14, LOW); // sets Second Stage OFF
          digitalWrite(15, LOW); // sets Third Stage OFF
          digitalWrite(32, LOW); // sets Fourth Stage OFF
          Serial.println("First Stage Button is Pressed"); 
      }

     if (Buffer[4] == 0X22){//Second Stage Button
          digitalWrite(12, LOW); // sets Home page OFF
          digitalWrite(13, LOW); // sets First Stage OFF
          digitalWrite(14, HIGH); // sets Second Stage ON
          digitalWrite(15, LOW); // sets Third Stage OFF
          digitalWrite(32, LOW); // sets Fourth Stage OFF
          Serial.println("Second Stage Button is Pressed");   
     }
          
     if (Buffer[4] == 0X23){//Third Stage Button
          digitalWrite(12, LOW); // sets Home page OFF
          digitalWrite(13, LOW); // sets First Stage OFF
          digitalWrite(14, LOW); // sets Second Stage OFF
          digitalWrite(15, HIGH); // sets Third Stage ON
          digitalWrite(32, LOW); // sets Fourth Stage OFF
          Serial.println("Third Stage Button is Pressed");    
     }

     if (Buffer[4] == 0X24){//Fourth Stage Button
          digitalWrite(12, LOW); // sets Home page OFF
          digitalWrite(13, LOW); // sets First Stage OFF
          digitalWrite(14, LOW); // sets Second Stage OFF
          digitalWrite(15, LOW); // sets Third Stage OFF
          digitalWrite(32, HIGH); // sets Fourth Stage ON
          Serial.println("Fourth Stage Button is Pressed");    
     }
 
     if (Buffer[4] == 0X20){//Home Page Button
          digitalWrite(12, HIGH); // sets Home page ON
          digitalWrite(13, LOW); // sets First Stage OFF
          digitalWrite(14, LOW); // sets Second Stage OFF
          digitalWrite(15, LOW); // sets Third Stage OFF
          digitalWrite(32, LOW); // sets Fourth Stage OFF
          Serial.println("Home Page Button is Pressed");
     }
    }
   }
  }

void sendFloatNumber(float floatvalue,byte address)
{
  SerialPort.write(0x5A);
  SerialPort.write(0xA5);
  SerialPort.write(0x07);
  SerialPort.write(0x82);
  SerialPort.write(address);
  SerialPort.write((byte)0x00);

  byte hex[4]={0};

  FloatToHex(floatvalue,hex);

  SerialPort.write(hex[3]);
  SerialPort.write(hex[2]);
  SerialPort.write(hex[1]);
  SerialPort.write(hex[0]);
}

void sendIntNumber(int intvalue, byte address)
{
  SerialPort.write(0x5A);
  SerialPort.write(0xA5);
  SerialPort.write(0x05);
  SerialPort.write(0x82);
  SerialPort.write(address);
  SerialPort.write((byte)0x00);
  //SerialPort.write(highByte(intvalue));
  //SerialPort.write(lowByte(intvalue));

  byte hex[2]={0};

  IntToHex(intvalue,hex);

  SerialPort.write(hex[1]);
  SerialPort.write(hex[0]);
}

void FloatToHex(float f,byte* hex)
{
  byte* f_byte=reinterpret_cast<byte*>(&f);
  memcpy(hex,f_byte,4);
}

void IntToHex(int f,byte* hex)
{
  byte* f_byte=reinterpret_cast<byte*>(&f);
  memcpy(hex,f_byte,2);
}

//detachInterrupt(GPIOPin);

as a first fix for this

you could do

void display_control(){
  if (SerialPort.available()) {
    Serial.println("Serial Port is available");
    size_t  count = SerialPort.readBytes((char * ) Buffer, 8); // store whole frame in buffer array HEX Data coming from Touch Display Button
    if (count == 8) {
      // you got a complete frame

    }

but best would be to honour the asynchronous nature of your Serial communication. I would suggest to study Serial Input Basics to handle this

I tried but could not get rid of corrupt data.

I believe @J-M-L also suggested the same solution.