Hi All, need help with my code

I am getting compilation errors with my code. Maybe some could help here.

//###################################################################################
//Needs to Fix:
//Alarm for EN sounds 3x2 secs before oven shutdown- Fixed
//SW for Spisvakt PCB 5.0 and 4.0
//1) Date: 2021-07-29 SW version Spisvakt 7.0
//###################################################################################

#include <NHD_Character_LCD.h>
#include <SPI.h>
#include <Wire.h>

#include <stdint.h>
#include <stdlib.h>

#define STARTUP_DELAY 500
#define I2C_DELAY 100
#define SPI_DELAY 100
#define SLAVE_ADDRESS 0x28

//SPI LCD module
//sbit SPI_SS at RA5_bit; //chipselact
//sbit SPI_SCK at RC3_bit;
//sbit SPI_SDI at RC4_bit;
//sbit SPI_SDO at RC5_bit;

//Inputs:Relays
int Relay_0 = 11; // Relay_0
int Relay_1 = 12; // Relay_1
int Relay_2 = 13; // Relay_2

//Outputs:LEDs
const int led_RED = 1; // led Red for Start/Stop of timers
const int led_GREEN = 2; // led Green for 30 mins
const int led_YELLOW = 3; // led Yellow for 3 hrs
const int led_BLUE = 4; // led Blue for 5 hrs

//Outputs: Buzzer
const int buzzer = 5; //Buzzer

//Inputs: Tact Switches and external signal
const int Start_Stop_Button = 6;
const int Min30_Button = 7;
const int Hour2_Button = 8;
const int Hour5_Button = 9;
const int Oven_OFF = 10;

// Messages
char Message1[]= "30min-5hr:Timer OFF";
char Message2[]= "Timer OFF";
char Message3[]= "Timer ON: HH:MM";
char Message4[]= "Set Time: ";
char Message5[]= "Time Left: ";
char* digit[5] = {"0:00"};

unsigned int i; // Minutes counter
unsigned int j; // Seconds counter

unsigned char unit = 0; // unit of minutes counter
unsigned char ten = 0; // Tens of minutes counter
unsigned char cent = 0; // Cents of minutes counter

unsigned char clear; // Variable to keep track of Start_Stop_Button
unsigned char timerFlag; // Variable to know if timer is running
unsigned int time; // Amount of minutes to run
unsigned char LEDBlink; // Flag that states which timer was enabled
// 1 - 30 Min
// 2 - 2Hs
// 3 - 5Hs

// SPI Interface
uint8_t _SCL; // 13
uint8_t _SDI; // 12
uint8_t _CS; // 10

enum Interface{
SPI
};
Interface _interface;

void setup(){
//SPI pins SCK,SDI and CS
initLCD_SPI(13,12,10);

//initialize the digitals led pins as outputs
pinMode(led_RED, OUTPUT);
pinMode(led_GREEN, OUTPUT);
pinMode(led_YELLOW, OUTPUT);
pinMode(led_BLUE, OUTPUT);
pinMode(buzzer, OUTPUT);

pinMode(Relay_0, OUTPUT);
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);

//initialize the button pins as inputs
pinMode(Start_Stop_Button, INPUT);
pinMode(Min30_Button, INPUT);
pinMode(Hour2_Button, INPUT);
pinMode(Hour5_Button, INPUT);

//initialize the signal pin to SHUTDOWN OVEN as inputs
pinMode(Oven_OFF, INPUT);

}

void initLCD_SPI(uint8_t SCL, uint8_t SDI, uint8_t CS)
{
_interface = SPI;

// Store pin assignments globally
_SCL = SCL;
_SDI = SDI;
_CS = CS;

// Set IO modes
pinMode(CS, OUTPUT);
pinMode(SCL, OUTPUT);
pinMode(SDI, OUTPUT);

// Set pin states
digitalWrite(CS, HIGH);
digitalWrite(SCL, HIGH);

// Wait for display to power ON
delay(STARTUP_DELAY);
clearScreen();
}

/**

  • @brief Set chip/slave select HIGH and wait for 1ms.
  • @return none
    */
    void setCS()
    {
    digitalWrite(_CS, HIGH);
    delay(1);
    }

/**

  • @brief Clear chip/slave select and wait for 1ms.
  • @return none
    */
    void clearCS()
    {
    digitalWrite(_CS, LOW);
    delay(1);
    }

/**

  • @brief Set the SDA/SDI pin high on the I2C/SPI bus.
  • @return none
    */
    void setSDI()
    {
    digitalWrite(_SDI, HIGH);
    delayMicroseconds(SPI_DELAY);
    }

/**

  • @brief Clear the SDA/SDI pin on the I2C/SPI bus.
  • @return none
    */
    void clearSDI()
    {
    digitalWrite(_SDI, LOW);
    delayMicroseconds(SPI_DELAY);
    }

/**

  • @brief Set the SCL/SCK pin on the I2C/SPI bus.
  • @return none
    */
    void setSCL()
    {
    digitalWrite(_SCL, HIGH);
    if(_interface == SPI)
    {
    delayMicroseconds(SPI_DELAY);
    }
    }

/**

  • @brief Clear the SCL/SCK pin on the I2C/SPI bus.
  • @return none
    */
    void clearSCL()
    {
    digitalWrite(_SCL, LOW);
    if(_interface == SPI)
    {
    delayMicroseconds(SPI_DELAY);
    }
    }

/**

  • @brief Write 1 byte of data to the display.
  • @param data Byte of data to be written.
  • @return none
    */
    void write(uint8_t data)
    {
    switch(_interface)
    {
    case SPI:
    clearCS();
    putData_SPI(data);
    setCS();
    break;
    }
    delayMicroseconds(150);
    }

/**

  • @brief Write an array of characters to the display.
  • @param data Pointer to the array of characters.
  • @return none
    /
    void writeString(unsigned char
    data)
    {
    // Iterate through data until null terminator is found.
    while(*data != '\0')
    {
    write(*data);
    data++; // Increment pointer.
    }
    }

/**

  • @brief Put each bit of data on the SPI data bus.

  • This function sends MSB (D7) first and LSB (D0) last.

  • @param data Byte of data to be put on the SPI data bus.

  • @return none
    */
    void putData_SPI(uint8_t data)
    {
    // Write data byte MSB first -> LSB last
    for(int i = 7; i >= 0; i--)
    {
    clearSCL();

    digitalWrite(_SDI, (data >> i) & 0x01);

    setSCL();
    }
    }

/**

  • @brief Send the prefix data byte (0xFE).
  • @return none
    */
    void prefix()
    {
    write(0xFE);
    }

/**

  • @brief Turn the display ON.
  • Display is turned ON by default.
  • @return none
    */
    void displayON()
    {
    prefix();
    write(0x41);
    }

/**

  • @brief Turn the display OFF.
  • Display is turned ON by default.
  • @return none
    */
    void displayOFF()
    {
    prefix();
    write(0x42);
    }

/**

  • @brief Set the display cursor position via DDRAM address.
  • @param position Desired DDRAM address.
  • @return none
    */
    void setCursor(uint8_t position)
    {
    prefix();
    write(0x45);
    write(position);
    }

/**

  • @brief Move the cursor to line 1, column 1.
  • @return none
    */
    void home()
    {
    prefix();
    write(0x46);
    }

/**

  • @brief Clear the display screen.
  • @return none
    */
    void clearScreen()
    {
    prefix();
    write(0x51);
    delay(2);
    }

/**

  • @brief Set the display's contrast.
  • 0x00 <= contrast <= 0x32
  • Default: 0x28
  • @param contrast Desired contrast setting.
  • @return none
    */
    void setContrast(uint8_t contrast)
    {
    prefix();
    write(0x52);
    write(contrast);
    }

/**

  • @brief Set the display's brightness.
  • 0x01 <= brightness <= 0x08
  • brightness = 0x01 | Backlight OFF
  • brightness = 0x08 | Backlight ON (100%)
  • @param brightness Desired brightness setting.
  • @return none
    */
    void setBrightness(uint8_t brightness)
    {
    prefix();
    write(0x53);
    write(brightness);
    }

/**

  • @brief Turn the underline cursor ON.
  • @return none
    */
    void underlineCursorON()
    {
    prefix();
    write(0x47);
    }

// 100ms Delay
void Delay_100(void)
{
Delay_ms(100);
}

// Debounce function
void Debounce(void)
{
Delay_ms(100);
}

// convert minutes to ASCII hours an d minutes
void Display_Hours(void)
{
unsigned int dminutes;

dminutes = (unit + (ten * 10) + (100 * cent));  // put minutes into one varible
digit[0] = (dminutes / 60) + 48;                // hours as ascii
dminutes %= 60;
digit[1] = ':';
digit[2] = (dminutes / 10) + 48;
digit[3] = (dminutes % 10) + 48;
digit[4] = '\0';                                   // null terminator
Lcd_Out(2,11,digit);

}

//Display digits functions
void Display_Digits(void)
{
digit[2] = unit + 48;
digit[1] = ten + 48;
digit[0] = cent + 48;
Lcd_Out(2,11,digit);
}

// Buzzer sound
void Play_Sound()
{
//Play_Sound();
Buzzer=1;
Delay_ms(500);
Buzzer=0;
}

void Sound()
{
//Play Sound2();
Sound_Play(500,5000); //1kHz@1 sec
}

void stop_timer(void)
{
// Turn off relays
Relay_1 = 0;
Relay_2 = 0;
Relay_3 = 0;

// Turn off LEDs
led_BLUE = 0;
led_RED = 0;
led_GREEN = 0;
led_YELLOW = 0;

// Reset timer counters
unit = 0;
ten = 0;
cent = 0;

// Stops TMR1
T1CON &= 0xFE;

clear = 1;

Play_Sound(); //plays sound_1


// Timer is not counting anymore
timerFlag = 0;

Lcd_Out(1,1,Message2);

}

//Timer function
void start_timer(unsigned int MinVal)
{
unsigned int dminutes;
unsigned char blink = 0;
unsigned char flag = 0;
unsigned char Clear = 0;

Play_Sound();  //plays sound_2

// Activates relays
Relay_1 = 1;
Relay_2 = 1;
Relay_3 = 1;

// Activates Red LED and timerFlag to indicate that Timer is running
led_RED = 1;
timerFlag = 1;

Lcd_Cmd(_LCD_CLEAR);           // Clear LCD
Lcd_Out(1,1,Message3);         // "Timer ON: HH:MM"
Lcd_Out(2,1,Message5);         // "Time Left: "

for (i=0; i<MinVal; i++)
{
    // Put minutes into one variable
    dminutes = MinVal-i;

    if(dminutes == 5)  // 5minute before end plays sound
        Play_Sound();

    // Hours as ASCII
    Lcd_Chr(2, 12,  (dminutes / 60) + 48);

    // Colon character
    Lcd_Chr(2, 13,  ':');

    // Minutes as ASCII
    dminutes %= 60;
    Lcd_Chr(2, 14, (dminutes / 10) + 48);
    Lcd_Chr(2, 15, (dminutes % 10) + 48);

    // Start counter
    j = 1;

    do
    {
        // Increment counter
        j++;

        // Increment blinking counter
        blink++;

        // If a second has passed
        if(blink == 10)
        {
            // If colon is on, then turn it off and viceversa
            if(flag == 1)
            {
                flag = 0;
                Lcd_Out(2,13,":");
            }
            else
            {
                flag = 1;
                Lcd_Out(2,13," ");
            }

            if(LEDBlink == 1)
                led_GREEN = ~led_GREEN;
            else if(LEDBlink == 2)
                led_YELLOW = ~led_YELLOW;
            else if(LEDBlink == 3)
                led_BLUE = ~led_BLUE;

            // Reset counter
            blink = 0;
        }

        // Check if temperature is too high. If not, check Start_Stop_Button
        if(Oven_OFF == 1)
        {
           Clear = 1;
           Sound_Play(500,2000);
           Delay_ms(100);
           Sound_Play(500,2000);
           Delay_ms(100);
           Sound_Play(500,2000);
        }
        else
        {
           if(Start_Stop_Button == 0)
           {
               Debounce();
               if(Start_Stop_Button == 0)
               {
                   Clear = 1;
               }
           } // end if !Start_Stop_Button
           else
           {
               Delay_ms(100);
           }
        }
    } while(((j<=600) && (Clear == 0)));

    // If the oven must be shutdown
    if (Clear == 1)
    {
        Delay_ms(500);
        Lcd_Out(1,1,Message2);      // Show message: Timer OFF
        stop_timer();

        break;
    } // end if
} // end for

// Put minutes into one variable
dminutes = MinVal-i;

// Hours as ASCII
Lcd_Chr(2, 12,  (dminutes / 60) + 48);

// Colon as ASCII
Lcd_Chr(2, 13,  ':');

// Minutes as ASCII
dminutes %= 60;
Lcd_Chr(2, 14, (dminutes / 10) + 48);
Lcd_Chr(2, 15, (dminutes % 10) + 48);

stop_timer();

} // end function

void Start_Stop(void)
{
if(timerFlag == 0)
{
time = cent100 + ten10 + unit ; //unit

    if(time > 0)
    {
        start_timer(time);
    }
}
else
{
   stop_timer();
}

}

//Interupt
void interrupt(void)
{
if (INTCON.INTF == 1) // Check if INTF flag is set
{
//Clear = 1;
INTCON.INTF = 0; // Clear interrupt flag before exiting ISR
}
}

int main(void)
{

Relay_1 = 0;                     // RA0
Relay_2 = 0;                     // RA1
Relay_3 = 0;                     // RA2
led_BLUE = 0;                    // RB0
led_RED = 0;                     // RC5
led_GREEN = 0;                   // RA4
led_YELLOW = 0;                  // RA5

timerFlag = 0;                   // Initialize variable

Sound_Init(&PORTB,1);            // Initialize Buzzer pin #1
Lcd_Init();                      // Initialize LCD

// Show Init message
Lcd_Cmd(_LCD_CLEAR);                // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);           // Cursor off
Lcd_Out(1,1, "Hello Again");
Lcd_Out(2,1, "Hello Once Again");
 i=0;
while(i<4){
     Delay_100();
     i ++;
}

while(1)
{
    // Restart Variable
    clear = 0;

    // 300ms delay
    Delay_100();
    Delay_100();
    Delay_100();

    // Show initial message
    Lcd_Cmd(_LCD_CLEAR);                // Clear display
    Lcd_Out(1,1, "Hello Again");
    Lcd_Out(2,1, "Hello Once Again");
     i=0;
    while(i<6){
       Delay_100();
       i ++;
    }

    Lcd_Cmd(_LCD_CLEAR);                // Clear display
    Lcd_Out(1,1,Message1);              // "30min-5hr:Timer OFF"
    Lcd_Out(2,1,Message4);              // "Set Time: "

    cent = 0;
    ten = 0;                            // Set time to zero
    unit = 0;
    Display_Hours();                    // Display_Digits

    do
    {
        if(Min30_Button == 0)         // RC1 - 30 minute button is pressed
        {
            Debounce();
            if(Min30_Button == 0)
            {
                led_GREEN = 1;            // RA4
                led_YELLOW = 0;           // RA5
                led_BLUE = 0;             // RB0
                cent = 0;
                ten = 3;
                unit = 0;                 // 3 minutes time for test purpose
                LEDBlink = 1;
                Display_Hours();
            }
        } // end if !Min30_Button

        if(Hour2_Button == 0) // RC2 - 2 hours(120 min) button is pressed
        {
            Debounce();
            if(Hour2_Button == 0)
            {
                led_GREEN = 0;            // RA4
                led_YELLOW = 1;           // RA5
                led_BLUE = 0;             // RB0
                cent = 1;
                ten = 2;
                unit = 0;
                LEDBlink = 2;
                Display_Hours();
            }
        } // end if !Hour2_Button

        if(Hour5_Button == 0)         // RA3 - 5 hour(300 min) button is pressed
        {
            Debounce();
            if(Hour5_Button == 0)
            {
                led_GREEN = 0;            // RA4
                led_YELLOW = 0;           // RA5
                led_BLUE = 1;             // RB0
                cent = 3;
                ten = 0;
                unit = 0;
                LEDBlink = 3;
                Display_Hours();
            }
        } // end if !Hour5_Button

        if(Start_Stop_Button == 0) // RC0 - Start_Stop button is pressed
        {
            Debounce();
            if(Start_Stop_Button == 0)
            {
               Start_Stop();
            }
        } // end if !Start_Stop_Button

    } while(clear == 0);    // End of do...while
}

}
//################################## //Use code tags to format code for the forum

Please post your full sketch, using code tags when you do. This prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Someone failed to include the actual errors they got!!!

int main(void)

Why did you deliberately decide not to use the normal setup() and loop() functions and does your code correctly initialise the Arduino hardware as the built in main() function of the Arduino environment does ?

This code might be written for Arduino, but there are a few redefinitions and "loop()" is absent (with main() present)... among other things. Learn to post your formatted code in <CODE> blocks by clicking the <CODE> button in your message box... it should look like this (because that is how people like to see it)...

//###################################################################################
//Needs to Fix:
//Alarm for EN sounds 3x2 secs before oven shutdown- Fixed
//SW for Spisvakt PCB 5.0 and 4.0
//1) Date: 2021-07-29 SW version Spisvakt 7.0
//###################################################################################
#include <NHD_Character_LCD.h>
#include <SPI.h>
#include <Wire.h>
#include <stdint.h>
#include <stdlib.h>
#define STARTUP_DELAY 500
#define I2C_DELAY 100
#define SPI_DELAY 100
#define SLAVE_ADDRESS 0x28
//SPI LCD module
//sbit SPI_SS at RA5_bit; //chipselact
//sbit SPI_SCK at RC3_bit;
//sbit SPI_SDI at RC4_bit;
//sbit SPI_SDO at RC5_bit;
//Inputs:Relays
int Relay_0 = 11; // Relay_0
int Relay_1 = 12; // Relay_1
int Relay_2 = 13; // Relay_2
//Outputs:LEDs
const int led_RED = 1; // led Red for Start/Stop of timers
const int led_GREEN = 2; // led Green for 30 mins
const int led_YELLOW = 3; // led Yellow for 3 hrs
const int led_BLUE = 4; // led Blue for 5 hrs
//Outputs: Buzzer
const int buzzer = 5; //Buzzer
//Inputs: Tact Switches and external signal
const int Start_Stop_Button = 6;
const int Min30_Button = 7;
const int Hour2_Button = 8;
const int Hour5_Button = 9;
const int Oven_OFF = 10;
// Messages
char Message1[] = "30min-5hr:Timer OFF";
char Message2[] = "Timer OFF";
char Message3[] = "Timer ON: HH:MM";
char Message4[] = "Set Time: ";
char Message5[] = "Time Left: ";
char* digit[5] = {"0:00"};
unsigned int i; // Minutes counter
unsigned int j; // Seconds counter
unsigned char unit = 0; // unit of minutes counter
unsigned char ten = 0; // Tens of minutes counter
unsigned char cent = 0; // Cents of minutes counter
unsigned char clear; // Variable to keep track of Start_Stop_Button
unsigned char timerFlag; // Variable to know if timer is running
unsigned int time; // Amount of minutes to run
unsigned char LEDBlink; // Flag that states which timer was enabled
// 1 - 30 Min
// 2 - 2Hs
// 3 - 5Hs
// SPI Interface
uint8_t _SCL; // 13
uint8_t _SDI; // 12
uint8_t _CS; // 10
enum Interface {
  SPI
};
Interface _interface;

void setup() {
  //SPI pins SCK,SDI and CS
  initLCD_SPI(13, 12, 10);
  //initialize the digitals led pins as outputs
  pinMode(led_RED, OUTPUT);
  pinMode(led_GREEN, OUTPUT);
  pinMode(led_YELLOW, OUTPUT);
  pinMode(led_BLUE, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(Relay_0, OUTPUT);
  pinMode(Relay_1, OUTPUT);
  pinMode(Relay_2, OUTPUT);
  //initialize the button pins as inputs
  pinMode(Start_Stop_Button, INPUT);
  pinMode(Min30_Button, INPUT);
  pinMode(Hour2_Button, INPUT);
  pinMode(Hour5_Button, INPUT);
  //initialize the signal pin to SHUTDOWN OVEN as inputs
  pinMode(Oven_OFF, INPUT);
}

void initLCD_SPI(uint8_t SCL, uint8_t SDI, uint8_t CS)
{
  _interface = SPI;
  // Store pin assignments globally
  _SCL = SCL;
  _SDI = SDI;
  _CS = CS;
  // Set IO modes
  pinMode(CS, OUTPUT);
  pinMode(SCL, OUTPUT);
  pinMode(SDI, OUTPUT);
  // Set pin states
  digitalWrite(CS, HIGH);
  digitalWrite(SCL, HIGH);
  // Wait for display to power ON
  delay(STARTUP_DELAY);
  clearScreen();
}

/**
    @brief Set chip/slave select HIGH and wait for 1ms.
    @return none
*/
void setCS()
{
  digitalWrite(_CS, HIGH);
  delay(1);
}

/**
    @brief Clear chip/slave select and wait for 1ms.
    @return none
*/
void clearCS()
{
  digitalWrite(_CS, LOW);
  delay(1);
}

/**
    @brief Set the SDA/SDI pin high on the I2C/SPI bus.
    @return none
*/
void setSDI()
{
  digitalWrite(_SDI, HIGH);
  delayMicroseconds(SPI_DELAY);
}

/**
    @brief Clear the SDA/SDI pin on the I2C/SPI bus.
    @return none
*/
void clearSDI()
{
  digitalWrite(_SDI, LOW);
  delayMicroseconds(SPI_DELAY);
}

/**
    @brief Set the SCL/SCK pin on the I2C/SPI bus.
    @return none
*/
void setSCL()
{
  digitalWrite(_SCL, HIGH);
  if (_interface == SPI)
  {
    delayMicroseconds(SPI_DELAY);
  }
}

/**
    @brief Clear the SCL/SCK pin on the I2C/SPI bus.
    @return none
*/
void clearSCL()
{
  digitalWrite(_SCL, LOW);
  if (_interface == SPI)
  {
    delayMicroseconds(SPI_DELAY);
  }
}

/**
    @brief Write 1 byte of data to the display.
    @param data Byte of data to be written.
    @return none
*/
void write(uint8_t data)
{
  switch (_interface)
  {
    case SPI:
      clearCS();
      putData_SPI(data);
      setCS();
      break;
  }
  delayMicroseconds(150);
}

/**
    @brief Write an array of characters to the display.
    @param data Pointer to the array of characters.
    @return none
    /
    void writeString(unsigned char data)
    {
    // Iterate through data until null terminator is found.
    while(*data != '\0')
    {
    write(*data);
    data++; // Increment pointer.
    }
    }
  /**
    @brief Put each bit of data on the SPI data bus.
    This function sends MSB (D7) first and LSB (D0) last.
    @param data Byte of data to be put on the SPI data bus.
    @return none
*/
void putData_SPI(uint8_t data)
{
  // Write data byte MSB first -> LSB last
  for (int i = 7; i >= 0; i--)
  {
    clearSCL();
    digitalWrite(_SDI, (data >> i) & 0x01);
    setSCL();
  }
}

/**
    @brief Send the prefix data byte (0xFE).
    @return none
*/
void prefix()
{
  write(0xFE);
}

/**
    @brief Turn the display ON.
    Display is turned ON by default.
    @return none
*/
void displayON()
{
  prefix();
  write(0x41);
}

/**
    @brief Turn the display OFF.
    Display is turned ON by default.
    @return none
*/
void displayOFF()
{
  prefix();
  write(0x42);
}

/**
    @brief Set the display cursor position via DDRAM address.
    @param position Desired DDRAM address.
    @return none
*/
void setCursor(uint8_t position)
{
  prefix();
  write(0x45);
  write(position);
}

/**
    @brief Move the cursor to line 1, column 1.
    @return none
*/
void home()
{
  prefix();
  write(0x46);
}

/**
    @brief Clear the display screen.
    @return none
*/
void clearScreen()
{
  prefix();
  write(0x51);
  delay(2);
}

/**
    @brief Set the display's contrast.
    0x00 <= contrast <= 0x32
    Default: 0x28
    @param contrast Desired contrast setting.
    @return none
*/
void setContrast(uint8_t contrast)
{
  prefix();
  write(0x52);
  write(contrast);
}

/**
    @brief Set the display's brightness.
    0x01 <= brightness <= 0x08
    brightness = 0x01 | Backlight OFF
    brightness = 0x08 | Backlight ON (100%)
    @param brightness Desired brightness setting.
    @return none
*/
void setBrightness(uint8_t brightness)
{
  prefix();
  write(0x53);
  write(brightness);
}

/**
    @brief Turn the underline cursor ON.
    @return none
*/
void underlineCursorON()
{
  prefix();
  write(0x47);
}

// 100ms Delay
void Delay_100(void)
{
  Delay_ms(100);
}

// Debounce function
void Debounce(void)
{
  Delay_ms(100);
}

// convert minutes to ASCII hours an d minutes
void Display_Hours(void)
{
  unsigned int dminutes;
  dminutes = (unit + (ten * 10) + (100 * cent));  // put minutes into one varible
  digit[0] = (dminutes / 60) + 48;                // hours as ascii
  dminutes %= 60;
  digit[1] = ':';
  digit[2] = (dminutes / 10) + 48;
  digit[3] = (dminutes % 10) + 48;
  digit[4] = '\0';                                   // null terminator
  Lcd_Out(2, 11, digit);
}

//Display digits functions
void Display_Digits(void)
{
  digit[2] = unit + 48;
  digit[1] = ten + 48;
  digit[0] = cent + 48;
  Lcd_Out(2, 11, digit);
}
// Buzzer sound
void Play_Sound()
{
  //Play_Sound();
  Buzzer = 1;
  Delay_ms(500);
  Buzzer = 0;
}
void Sound()
{
  //Play Sound2();
  Sound_Play(500, 5000); //1kHz@1 sec
}

void stop_timer(void)
{
  // Turn off relays
  Relay_1 = 0;
  Relay_2 = 0;
  Relay_3 = 0;
  // Turn off LEDs
  led_BLUE = 0;
  led_RED = 0;
  led_GREEN = 0;
  led_YELLOW = 0;
  // Reset timer counters
  unit = 0;
  ten = 0;
  cent = 0;
  // Stops TMR1
  T1CON &= 0xFE;
  clear = 1;
  Play_Sound(); //plays sound_1
  // Timer is not counting anymore
  timerFlag = 0;
  Lcd_Out(1, 1, Message2);
}

//Timer function
void start_timer(unsigned int MinVal)
{
  unsigned int dminutes;
  unsigned char blink = 0;
  unsigned char flag = 0;
  unsigned char Clear = 0;
  Play_Sound();  //plays sound_2
  // Activates relays
  Relay_1 = 1;
  Relay_2 = 1;
  Relay_3 = 1;
  // Activates Red LED and timerFlag to indicate that Timer is running
  led_RED = 1;
  timerFlag = 1;
  Lcd_Cmd(_LCD_CLEAR);           // Clear LCD
  Lcd_Out(1, 1, Message3);       // "Timer ON: HH:MM"
  Lcd_Out(2, 1, Message5);       // "Time Left: "
  for (i = 0; i < MinVal; i++)
  {
    // Put minutes into one variable
    dminutes = MinVal - i;
    if (dminutes == 5) // 5minute before end plays sound
      Play_Sound();
    // Hours as ASCII
    Lcd_Chr(2, 12,  (dminutes / 60) + 48);
    // Colon character
    Lcd_Chr(2, 13,  ':');
    // Minutes as ASCII
    dminutes %= 60;
    Lcd_Chr(2, 14, (dminutes / 10) + 48);
    Lcd_Chr(2, 15, (dminutes % 10) + 48);
    // Start counter
    j = 1;
    do
    {
      // Increment counter
      j++;
      // Increment blinking counter
      blink++;
      // If a second has passed
      if (blink == 10)
      {
        // If colon is on, then turn it off and viceversa
        if (flag == 1)
        {
          flag = 0;
          Lcd_Out(2, 13, ":");
        }
        else
        {
          flag = 1;
          Lcd_Out(2, 13, " ");
        }
        if (LEDBlink == 1)
          led_GREEN = ~led_GREEN;
        else if (LEDBlink == 2)
          led_YELLOW = ~led_YELLOW;
        else if (LEDBlink == 3)
          led_BLUE = ~led_BLUE;
        // Reset counter
        blink = 0;
      }
      // Check if temperature is too high. If not, check Start_Stop_Button
      if (Oven_OFF == 1)
      {
        Clear = 1;
        Sound_Play(500, 2000);
        Delay_ms(100);
        Sound_Play(500, 2000);
        Delay_ms(100);
        Sound_Play(500, 2000);
      }
      else
      {
        if (Start_Stop_Button == 0)
        {
          Debounce();
          if (Start_Stop_Button == 0)
          {
            Clear = 1;
          }
        } // end if !Start_Stop_Button
        else
        {
          Delay_ms(100);
        }
      }
    } while (((j <= 600) && (Clear == 0)));
    // If the oven must be shutdown
    if (Clear == 1)
    {
      Delay_ms(500);
      Lcd_Out(1, 1, Message2);    // Show message: Timer OFF
      stop_timer();
      break;
    } // end if
  } // end for
  // Put minutes into one variable
  dminutes = MinVal - i;
  // Hours as ASCII
  Lcd_Chr(2, 12,  (dminutes / 60) + 48);
  // Colon as ASCII
  Lcd_Chr(2, 13,  ':');
  // Minutes as ASCII
  dminutes %= 60;
  Lcd_Chr(2, 14, (dminutes / 10) + 48);
  Lcd_Chr(2, 15, (dminutes % 10) + 48);
  stop_timer();
} // end function

void Start_Stop(void)
{
  if (timerFlag == 0)
  {
    time = cent100 + ten10 + unit ; //unit
    if (time > 0)
    {
      start_timer(time);
    }
  }
  else
  {
    stop_timer();
  }
}
//Interupt
void interrupt(void)
{
  if (INTCON.INTF == 1) // Check if INTF flag is set
  {
    //Clear = 1;
    INTCON.INTF = 0; // Clear interrupt flag before exiting ISR
  }
}

int main(void)
{
  Relay_1 = 0;                     // RA0
  Relay_2 = 0;                     // RA1
  Relay_3 = 0;                     // RA2
  led_BLUE = 0;                    // RB0
  led_RED = 0;                     // RC5
  led_GREEN = 0;                   // RA4
  led_YELLOW = 0;                  // RA5
  timerFlag = 0;                   // Initialize variable
  Sound_Init(&PORTB, 1);           // Initialize Buzzer pin #1
  Lcd_Init();                      // Initialize LCD
  // Show Init message
  Lcd_Cmd(_LCD_CLEAR);                // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);           // Cursor off
  Lcd_Out(1, 1, "Hello Again");
  Lcd_Out(2, 1, "Hello Once Again");
  i = 0;
  while (i < 4) {
    Delay_100();
    i ++;
  }
  while (1)
  {
    // Restart Variable
    clear = 0;
    // 300ms delay
    Delay_100();
    Delay_100();
    Delay_100();
    // Show initial message
    Lcd_Cmd(_LCD_CLEAR);                // Clear display
    Lcd_Out(1, 1, "Hello Again");
    Lcd_Out(2, 1, "Hello Once Again");
    i = 0;
    while (i < 6) {
      Delay_100();
      i ++;
    }
    Lcd_Cmd(_LCD_CLEAR);                // Clear display
    Lcd_Out(1, 1, Message1);            // "30min-5hr:Timer OFF"
    Lcd_Out(2, 1, Message4);            // "Set Time: "
    cent = 0;
    ten = 0;                            // Set time to zero
    unit = 0;
    Display_Hours();                    // Display_Digits
    do
    {
      if (Min30_Button == 0)        // RC1 - 30 minute button is pressed
      {
        Debounce();
        if (Min30_Button == 0)
        {
          led_GREEN = 1;            // RA4
          led_YELLOW = 0;           // RA5
          led_BLUE = 0;             // RB0
          cent = 0;
          ten = 3;
          unit = 0;                 // 3 minutes time for test purpose
          LEDBlink = 1;
          Display_Hours();
        }
      } // end if !Min30_Button
      if (Hour2_Button == 0) // RC2 - 2 hours(120 min) button is pressed
      {
        Debounce();
        if (Hour2_Button == 0)
        {
          led_GREEN = 0;            // RA4
          led_YELLOW = 1;           // RA5
          led_BLUE = 0;             // RB0
          cent = 1;
          ten = 2;
          unit = 0;
          LEDBlink = 2;
          Display_Hours();
        }
      } // end if !Hour2_Button
      if (Hour5_Button == 0)        // RA3 - 5 hour(300 min) button is pressed
      {
        Debounce();
        if (Hour5_Button == 0)
        {
          led_GREEN = 0;            // RA4
          led_YELLOW = 0;           // RA5
          led_BLUE = 1;             // RB0
          cent = 3;
          ten = 0;
          unit = 0;
          LEDBlink = 3;
          Display_Hours();
        }
      } // end if !Hour5_Button
      if (Start_Stop_Button == 0) // RC0 - Start_Stop button is pressed
      {
        Debounce();
        if (Start_Stop_Button == 0)
        {
          Start_Stop();
        }
      } // end if !Start_Stop_Button
    } while (clear == 0);   // End of do...while
  }
}

Hi, I used this code for the MikroC compiler and ported it so that it could work in Arduino.
Got stuck with the compilation errors.
Thanks for looking into it
//Jay

@gonzo123
Put your code AND errors in a <CODE> block.

This code could never have worked with any C compiler

An example

const int led_RED = 1; // led Red for Start/Stop of timers

This declares a const variable whose value cannot be changed

Then you do this that attempts to change the value of the variable

led_RED = 0;

I don't think that you are ready for this project until you have grasped the basics of C/C++

1 Like

"Spisvakt" translates to "stove watcher."

Discard the SPI stuff, then arrange the pins for the Uno/Nano, and learn to set a digital pin HIGH/on and LOW/off. It's just a mess of buttons, LEDs, Relays, an LCD and "delay()"... but it is "working" like a Trabant... by replacing the "SPI LCD" commands with I2C LCD functions. I have not had time to fiddle with the buttons, buzzer, LEDs or relays.

sketch.ino for wokwi
// https://forum.arduino.cc/t/hi-all-need-help-with-my-code/1320952/

//###################################################################################
//Needs to Fix:
//Alarm for EN sounds 3x2 secs before oven shutdown- Fixed
//SW for Spisvakt PCB 5.0 and 4.0
//1) Date: 2021-07-29 SW version Spisvakt 7.0
//###################################################################################
#include <NHD_Character_LCD.h>
// #include <SPI.h>
#include <Wire.h>
#include <stdint.h>
#include <stdlib.h>
// #define STARTUP_DELAY 500
// #define I2C_DELAY 100
// #define SPI_DELAY 100
// #define SLAVE_ADDRESS 0x28 // not used

#include <LiquidCrystal_I2C.h>
#define I2C_ADDR    0x27
#define LCD_COLUMNS 20
#define LCD_LINES   4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);

//Inputs:Relays
int Relay_0 = 11; // Relay_0
int Relay_1 = 12; // Relay_1
int Relay_2 = 13; // Relay_2
int Relay_3 = 15; // Relay_0
int Relay_4 = 16; // Relay_1
int Relay_5 = 17; // Relay_2

//Outputs:LEDs
const int led_RED = 5; // led Red for Start/Stop of timers
const int led_GREEN = 2; // led Green for 30 mins
const int led_YELLOW = 3; // led Yellow for 3 hrs
const int led_BLUE = 4; // led Blue for 5 hrs

//Outputs: Buzzer
const int Buzzer = 14; // 5; //Buzzer

//Inputs: Tact Switches and external signal
const int Start_Stop_Button = 6;
const int Min30_Button = 7;
const int Hour2_Button = 8;
const int Hour5_Button = 9;
const int Oven_OFF = 10;

// Messages
char Message1[] = "30min-5hr:Timer OFF";
char Message2[] = "Timer OFF";
char Message3[] = "Timer ON: HH:MM";
char Message4[] = "Set Time: ";
char Message5[] = "Time Left: ";
char* digit[5] = {"0:00"};

unsigned int i; // Minutes counter
unsigned int j; // Seconds counter
unsigned char unit = 0; // unit of minutes counter
unsigned char ten = 0; // Tens of minutes counter
unsigned char cent = 0; // Cents of minutes counter
unsigned char clear; // Variable to keep track of Start_Stop_Button
unsigned char timerFlag; // Variable to know if timer is running
unsigned int time; // Amount of minutes to run
unsigned char LEDBlink; // Flag that states which timer was enabled
// 1 - 30 Min
// 2 - 2Hs
// 3 - 5Hs

// SPI Interface
// uint8_t _SCL; // 13
// uint8_t _SDI; // 12
// uint8_t _CS; // 10
// enum Interface {
//   SPI
// };
// Interface _interface;

void setup() {
  lcd.init();
  lcd.backlight();

  //SPI pins SCK,SDI and CS
  // initLCD_SPI(13, 12, 10);
  //initialize the digitals led pins as outputs
  pinMode(led_RED, OUTPUT);
  pinMode(led_GREEN, OUTPUT);
  pinMode(led_YELLOW, OUTPUT);
  pinMode(led_BLUE, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  pinMode(Relay_0, OUTPUT);
  pinMode(Relay_1, OUTPUT);
  pinMode(Relay_2, OUTPUT);
  //initialize the button pins as inputs
  pinMode(Start_Stop_Button, INPUT);
  pinMode(Min30_Button, INPUT);
  pinMode(Hour2_Button, INPUT);
  pinMode(Hour5_Button, INPUT);
  //initialize the signal pin to SHUTDOWN OVEN as inputs
  pinMode(Oven_OFF, INPUT);
}

// void initLCD_SPI(uint8_t SCL, uint8_t SDI, uint8_t CS)
// {
//   _interface = SPI;
//   // Store pin assignments globally
//   _SCL = SCL;
//   _SDI = SDI;
//   _CS = CS;
//   // Set IO modes
//   pinMode(CS, OUTPUT);
//   pinMode(SCL, OUTPUT);
//   pinMode(SDI, OUTPUT);
//   // Set pin states
//   digitalWrite(CS, HIGH);
//   digitalWrite(SCL, HIGH);
//   // Wait for display to power ON
//   delay(STARTUP_DELAY);
//   clearScreen();
// }

/**
    @brief Set chip/slave select HIGH and wait for 1ms.
    @return none
*/
// void setCS()
// {
//   digitalWrite(_CS, HIGH);
//   delay(1);
// }

/**
    @brief Clear chip/slave select and wait for 1ms.
    @return none
*/
// void clearCS()
// {
//   digitalWrite(_CS, LOW);
//   delay(1);
// }

/**
    @brief Set the SDA/SDI pin high on the I2C/SPI bus.
    @return none
*/
// void setSDI()
// {
//   digitalWrite(_SDI, HIGH);
//   delayMicroseconds(SPI_DELAY);
// }

/**
    @brief Clear the SDA/SDI pin on the I2C/SPI bus.
    @return none
*/
// void clearSDI()
// {
//   digitalWrite(_SDI, LOW);
//   delayMicroseconds(SPI_DELAY);
// }

/**
    @brief Set the SCL/SCK pin on the I2C/SPI bus.
    @return none
*/
// void setSCL()
// {
//   digitalWrite(_SCL, HIGH);
//   if (_interface == SPI)
//   {
//     delayMicroseconds(SPI_DELAY);
//   }
// }

/**
    @brief Clear the SCL/SCK pin on the I2C/SPI bus.
    @return none
*/
// void clearSCL()
// {
//   digitalWrite(_SCL, LOW);
//   if (_interface == SPI)
//   {
//     delayMicroseconds(SPI_DELAY);
//   }
// }

/**
    @brief Write 1 byte of data to the display.
    @param data Byte of data to be written.
    @return none
*/
// void write(uint8_t data)
// {
//   switch (_interface)
//   {
//     case SPI:
//       clearCS();
//       putData_SPI(data);
//       setCS();
//       break;
//   }
//   delayMicroseconds(150);
// }

/**
    @brief Write an array of characters to the display.
    @param data Pointer to the array of characters.
    @return none
    /
    void writeString(unsigned char data)
    {
    // Iterate through data until null terminator is found.
    while(*data != '\0')
    {
    write(*data);
    data++; // Increment pointer.
    }
    }
  /**
    @brief Put each bit of data on the SPI data bus.
    This function sends MSB (D7) first and LSB (D0) last.
    @param data Byte of data to be put on the SPI data bus.
    @return none
*/
// void putData_SPI(uint8_t data)
// {
//   // Write data byte MSB first -> LSB last
//   for (int i = 7; i >= 0; i--)
//   {
//     clearSCL();
//     digitalWrite(_SDI, (data >> i) & 0x01);
//     setSCL();
//   }
// }

/**
    @brief Send the prefix data byte (0xFE).
    @return none
*/
void prefix() {
  lcd.write(0xFE);
}

/**
    @brief Turn the display ON.
    Display is turned ON by default.
    @return none
*/
void displayON() {
  prefix();
  lcd.write(0x41);
}

/**
    @brief Turn the display OFF.
    Display is turned ON by default.
    @return none
*/
void displayOFF() {
  prefix();
  lcd.write(0x42);
}

/**
    @brief Set the display cursor position via DDRAM address.
    @param position Desired DDRAM address.
    @return none
*/
void setCursor(uint8_t position) {
  prefix();
  lcd.write(0x45);
  lcd.write(position);
}

/**
    @brief Move the cursor to line 1, column 1.
    @return none
*/
void home() {
  prefix();
  lcd.write(0x46);
}

/**
    @brief Clear the display screen.
    @return none
*/

void clearScreen() {
  prefix();
  lcd.write(0x51);
  delay(2);
}

/**
    @brief Set the display's contrast.
    0x00 <= contrast <= 0x32
    Default: 0x28
    @param contrast Desired contrast setting.
    @return none
*/
void setContrast(uint8_t contrast) {
  prefix();
  lcd.write(0x52);
  lcd.write(contrast);
}

/**
    @brief Set the display's brightness.
    0x01 <= brightness <= 0x08
    brightness = 0x01 | Backlight OFF
    brightness = 0x08 | Backlight ON (100%)
    @param brightness Desired brightness setting.
    @return none
*/
void setBrightness(uint8_t brightness) {
  prefix();
  lcd.write(0x53);
  lcd.write(brightness);
}

/**
    @brief Turn the underline cursor ON.
    @return none
*/
void underlineCursorON() {
  prefix();
  lcd.write(0x47);
}

// 100ms Delay
void Delay_ms(int value) {
  delay(value);
}

// Debounce function
void Debounce(void) {
  Delay_ms(100);
}

// convert minutes to ASCII hours an d minutes
void Display_Hours(void) {
  unsigned int dminutes;
  dminutes = (unit + (ten * 10) + (100 * cent));  // put minutes into one varible
  digit[0] = (dminutes / 60) + 48;                // hours as ascii
  dminutes %= 60;
  digit[1] = ':';
  digit[2] = (dminutes / 10) + 48;
  digit[3] = (dminutes % 10) + 48;
  digit[4] = '\0';                                   // null terminator
  Lcd_Num(1, 11, digit);
  // Lcd_Out(1, 11, digit);
}

//Display digits functions
void Display_Digits(void) {
  digit[2] = unit + 48;
  digit[1] = ten + 48;
  digit[0] = cent + 48;
  Lcd_Num(1, 11, digit);
  // Lcd_Out(1, 11, digit);
}

// Buzzer sound
void Play_Sound() {
  //Play_Sound();
  digitalWrite(Buzzer, 1);
  // Buzzer = 1;
  Delay_ms(500);
  digitalWrite(Buzzer, 0);
  // Buzzer = 0;
}
void Sound() {
  //Play Sound2();
  Play_Sound;
  // Sound_Play(500, 5000); //1kHz@1 sec
}

void stop_timer(void) {
  // Turn off relays
  digitalWrite(Relay_1, 0);
  digitalWrite(Relay_2, 0);
  digitalWrite(Relay_3, 0);
  // Relay_1 = 0;
  // Relay_2 = 0;
  // Relay_3 = 0;

  // Turn off LEDs
  digitalWrite(led_BLUE, 0);
  digitalWrite(led_RED, 0);
  digitalWrite(led_GREEN, 0);
  digitalWrite(led_YELLOW, 0);
  // led_BLUE = 0;
  // led_RED = 0;
  // led_GREEN = 0;
  // led_YELLOW = 0;

  // Reset timer counters
  unit = 0;
  ten = 0;
  cent = 0;

  // Stops TMR1
  // T1CON &= 0xFE; // probably for the buzzer

  clear = 1;
  Play_Sound(); //plays sound_1

  // Timer is not counting anymore
  // timerFlag = 0;
  Lcd_Out(0, 1, Message2);
}

//Timer function
void start_timer(unsigned int MinVal) {
  unsigned int dminutes;
  unsigned char blink = 0;
  unsigned char flag = 0;
  unsigned char Clear = 0;
  Play_Sound();  //plays sound_2
  // Activates relays
  digitalWrite(Relay_1, 1);
  digitalWrite(Relay_2, 1);
  digitalWrite(Relay_3, 1);
  // Relay_1 = 1;
  // Relay_2 = 1;
  // Relay_3 = 1;

  // Activates Red LED and timerFlag to indicate that Timer is running
  digitalWrite(led_RED, 1);
  // led_RED = 1;
  // timerFlag = 1;
  lcd.clear();
  // Lcd_Cmd(_LCD_CLEAR);           // Clear LCD
  Lcd_Out(0, 1, Message3);       // "Timer ON: HH:MM"
  Lcd_Out(1, 1, Message5);       // "Time Left: "
  for (i = 0; i < MinVal; i++)
  {
    // Put minutes into one variable
    dminutes = MinVal - i;
    if (dminutes == 5) // 5minute before end plays sound
      Play_Sound();

    // Hours as ASCII
    Lcd_Out(1, 12,  (dminutes / 60) + 48);
    // Lcd_Chr(2, 12,  (dminutes / 60) + 48);

    // Colon character
    Lcd_Out(1, 13,  ':');
    // Lcd_Chr(2, 13,  ':');

    // Minutes as ASCII
    dminutes %= 60;
    Lcd_Out(1, 14, (dminutes / 10) + 48);
    Lcd_Out(1, 15, (dminutes % 10) + 48);
    // Lcd_Chr(2, 14, (dminutes / 10) + 48);
    // Lcd_Chr(2, 15, (dminutes % 10) + 48);
    // Start counter
    j = 1;
    do
    {
      // Increment counter
      j++;
      // Increment blinking counter
      blink++;
      // If a second has passed
      if (blink == 10)
      {
        // If colon is on, then turn it off and viceversa
        if (flag == 1)
        {
          flag = 0;
          Lcd_Out(1, 13, ":");
        }
        else
        {
          flag = 1;
          Lcd_Out(1, 13, " ");
        }
        if (LEDBlink == 1)
          digitalWrite(led_GREEN, ~digitalRead(led_GREEN));
        // led_GREEN = ~led_GREEN;
        else if (LEDBlink == 2)
          digitalWrite(led_YELLOW, ~digitalRead(led_YELLOW));
        // led_YELLOW = ~led_YELLOW;
        else if (LEDBlink == 3)
          digitalWrite(led_BLUE, ~digitalRead(led_BLUE));
        // led_BLUE = ~led_BLUE;

        // Reset counter
        blink = 0;
      }
      // Check if temperature is too high. If not, check Start_Stop_Button
      if (Oven_OFF == 1)
      {
        Clear = 1;
        Play_Sound();
        // Sound_Play(500, 2000);
        Delay_ms(100);
        Play_Sound();
        // Sound_Play(500, 2000);
        Delay_ms(100);
        Play_Sound();
        // Sound_Play(500, 2000);
      }
      else
      {
        if (Start_Stop_Button == 0)
        {
          Debounce();
          if (Start_Stop_Button == 0)
          {
            Clear = 1;
          }
        } // end if !Start_Stop_Button
        else
        {
          Delay_ms(100);
        }
      }
    } while (((j <= 600) && (Clear == 0)));
    // If the oven must be shutdown
    if (Clear == 1)
    {
      Delay_ms(500);
      Lcd_Out(0, 1, Message2);    // Show message: Timer OFF
      stop_timer();
      break;
    } // end if
  } // end for

  // Put minutes into one variable
  dminutes = MinVal - i;
  // Hours as ASCII
  Lcd_Out(1, 12,  (dminutes / 60) + 48);
  // Lcd_Chr(2, 12,  (dminutes / 60) + 48);

  // Colon as ASCII
  Lcd_Out(1, 13,  ':');
  // Lcd_Chr(2, 13,  ':');

  // Minutes as ASCII
  dminutes %= 60;
  Lcd_Out(1, 14, (dminutes / 10) + 48);
  Lcd_Out(1, 14, (dminutes / 10) + 48);
  // Lcd_Chr(2, 15, (dminutes % 10) + 48);
  // Lcd_Chr(2, 15, (dminutes % 10) + 48);

  stop_timer();
} // end function

void Start_Stop(void) {
  if (timerFlag == 0)
  {
    time = cent + ten + unit ; //unit
    // time = cent100 + ten10 + unit ; //unit
    if (time > 0)
    {
      start_timer(time);
    }
  }
  else
  {
    stop_timer();
  }
}

//Interupt
// void interrupt(void) {
//   if (INTCON.INTF == 1) // Check if INTF flag is set
//   {
//     //Clear = 1;
//     INTCON.INTF = 0; // Clear interrupt flag before exiting ISR
//   }
// }

void Lcd_Out(int x, int y, char text[]) {
  lcd.setCursor(x, y);
  lcd.print(text);
}

void Lcd_Num(int x, int y, int z) {
  lcd.setCursor(x, y);
  lcd.print(z);
}

void  loop() {
  digitalWrite(Relay_1, 0);
  digitalWrite(Relay_2, 0);
  digitalWrite(Relay_3, 0);
  // Relay_1 = 0;                     // RA0
  // Relay_2 = 0;                     // RA1
  // Relay_3 = 0;                     // RA2

  digitalWrite(led_BLUE, 0);
  digitalWrite(led_RED, 0);
  digitalWrite(led_GREEN, 0);
  digitalWrite(led_YELLOW, 0);
  // led_BLUE = 0;                    // RB0
  // led_RED = 0;                     // RC5
  // led_GREEN = 0;                   // RA4
  // led_YELLOW = 0;                  // RA5

  timerFlag = 0;                   // Initialize variable
  // Sound_Init(&PORTB, 1);           // Initialize Buzzer pin #1 // not used
  // Lcd_Init();                      // Initialize LCD
  // Show Init message
  lcd.clear();
  // Lcd_Cmd(_LCD_CLEAR);                // Clear display
  lcd.noBlink();
  // Lcd_Cmd(_LCD_CURSOR_OFF);           // Cursor off

  Lcd_Out(0, 1, "Hello Again");
  Lcd_Out(1, 1, "Hello Once Again");
  i = 0;

  while (i < 4) {
    Delay_ms(100);
    i ++;
  }

  while (1)
  {
    // Restart Variable
    clear = 0;
    // 300ms delay
    Delay_ms(100);
    Delay_ms(100);
    Delay_ms(100);
    // Show initial message

    lcd.clear();
    // Lcd_Cmd(_LCD_CLEAR);                // Clear display
    Lcd_Out(0, 1, "Hello Again");
    Lcd_Out(1, 1, "Hello Once Again");
    i = 0;
    while (i < 6) {
      Delay_ms(100);
      i ++;
    }
    lcd.clear();
    // Lcd_Cmd(_LCD_CLEAR);                // Clear display
    Lcd_Out(0, 1, Message1);            // "30min-5hr:Timer OFF"
    Lcd_Out(1, 1, Message4);            // "Set Time: "
    cent = 0;
    ten = 0;                            // Set time to zero
    unit = 0;
    Display_Hours();                    // Display_Digits

    do {
      if (Min30_Button == 0)        // RC1 - 30 minute button is pressed
      {
        Debounce();
        if (Min30_Button == 0)
        {
          // led_GREEN = 1;            // RA4
          // led_YELLOW = 0;           // RA5
          // led_BLUE = 0;             // RB0
          digitalWrite(led_GREEN, 1);            // RA4
          digitalWrite(led_YELLOW, 0);           // RA5
          digitalWrite(led_BLUE, 0);             // RB0
          cent = 0;
          ten = 3;
          unit = 0;                 // 3 minutes time for test purpose
          LEDBlink = 1;
          Display_Hours();
        }
      } // end if !Min30_Button
      if (Hour2_Button == 0) // RC2 - 2 hours(120 min) button is pressed
      {
        Debounce();
        if (Hour2_Button == 0)
        {
          // led_GREEN = 0;            // RA4
          // led_YELLOW = 1;           // RA5
          // led_BLUE = 0;             // RB0
          digitalWrite(led_GREEN, 0);            // RA4
          digitalWrite(led_YELLOW, 1);           // RA5
          digitalWrite(led_BLUE, 0);             // RB0
          cent = 1;
          ten = 2;
          unit = 0;
          LEDBlink = 2;
          Display_Hours();
        }
      } // end if !Hour2_Button
      if (Hour5_Button == 0)        // RA3 - 5 hour(300 min) button is pressed
      {
        Debounce();
        if (Hour5_Button == 0)
        {
          // led_GREEN = 0;            // RA4
          // led_YELLOW = 0;           // RA5
          // led_BLUE = 1;             // RB0
          digitalWrite(led_GREEN, 0);            // RA4
          digitalWrite(led_YELLOW, 0);           // RA5
          digitalWrite(led_BLUE, 1);             // RB0
          cent = 3;
          ten = 0;
          unit = 0;
          LEDBlink = 3;
          Display_Hours();
        }
      } // end if !Hour5_Button
      if (Start_Stop_Button == 0) // RC0 - Start_Stop button is pressed
      {
        Debounce();
        if (Start_Stop_Button == 0)
        {
          Start_Stop();
        }
      } // end if !Start_Stop_Button
    } while (clear == 0);   // End of do...while
  }
}

diagram.json for wokwi
{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": -4.8, "left": -0.5, "attrs": {} },
    {
      "type": "wokwi-lcd1602",
      "id": "lcd1",
      "top": -387.2,
      "left": 5.6,
      "attrs": { "pins": "i2c" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn1",
      "top": -51.4,
      "left": 182.4,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn2",
      "top": -99.4,
      "left": 182.4,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn3",
      "top": -147.4,
      "left": 182.4,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn4",
      "top": -195.4,
      "left": 182.4,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn5",
      "top": -243.4,
      "left": 182.4,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-relay-module",
      "id": "relay1",
      "top": -67.8,
      "left": -166.4,
      "rotate": 180,
      "attrs": {}
    },
    {
      "type": "wokwi-relay-module",
      "id": "relay2",
      "top": -135,
      "left": -166.4,
      "rotate": 180,
      "attrs": {}
    },
    {
      "type": "wokwi-relay-module",
      "id": "relay3",
      "top": -202.2,
      "left": -166.4,
      "rotate": 180,
      "attrs": {}
    },
    {
      "type": "wokwi-led",
      "id": "led1",
      "top": -301.2,
      "left": -140.2,
      "attrs": { "color": "red" }
    },
    {
      "type": "wokwi-led",
      "id": "led2",
      "top": -301.2,
      "left": -121,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-led",
      "id": "led3",
      "top": -301.2,
      "left": -101.8,
      "attrs": { "color": "yellow" }
    },
    {
      "type": "wokwi-led",
      "id": "led4",
      "top": -301.2,
      "left": -82.6,
      "attrs": { "color": "blue" }
    },
    {
      "type": "wokwi-buzzer",
      "id": "bz1",
      "top": -400.8,
      "left": -123,
      "attrs": { "volume": "0.1" }
    }
  ],
  "connections": [
    [ "lcd1:SCL", "nano:A5", "green", [ "h-19.2", "v403.5", "h105.6" ] ],
    [ "lcd1:SDA", "nano:A4", "green", [ "h-19.2", "v403.4", "h96" ] ],
    [ "lcd1:VCC", "nano:5V", "red", [ "h-19.2", "v432.1", "h134.4" ] ],
    [ "lcd1:GND", "nano:GND.1", "black", [ "h-19.2", "v451.2", "h153.6" ] ],
    [ "nano:GND.2", "btn1:2.l", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn2:2.l", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn3:2.l", "black", [ "v0" ] ],
    [ "nano:GND.2", "btn4:2.l", "black", [ "v0" ] ],
    [ "nano:6", "btn1:1.l", "green", [ "v0" ] ],
    [ "nano:7", "btn2:1.l", "green", [ "v0" ] ],
    [ "nano:8", "btn3:1.l", "green", [ "v0" ] ],
    [ "nano:9", "btn4:1.l", "green", [ "v0" ] ],
    [ "nano:GND.2", "btn5:2.l", "black", [ "v0" ] ],
    [ "nano:10", "btn5:1.l", "green", [ "v0" ] ],
    [ "relay1:VCC", "nano:5V", "red", [ "h9.6", "v115.2", "h144" ] ],
    [ "relay1:GND", "nano:GND.1", "black", [ "h19.2", "v134.8", "h153.6" ] ],
    [ "relay1:GND", "relay2:GND", "black", [ "h19.2", "v-66.8" ] ],
    [ "relay2:GND", "relay3:GND", "black", [ "h19.2", "v-66.8" ] ],
    [ "relay1:VCC", "relay2:VCC", "red", [ "h9.6", "v-67.2" ] ],
    [ "relay2:VCC", "relay3:VCC", "red", [ "h9.6", "v-67.2" ] ],
    [ "relay1:IN", "nano:13", "green", [ "h38.4", "v86.6" ] ],
    [ "relay2:IN", "nano:12", "green", [ "h0" ] ],
    [ "relay3:IN", "nano:11", "green", [ "h0" ] ],
    [ "nano:GND.2", "led1:C", "black", [ "v-211.2", "h-220.8" ] ],
    [ "led1:C", "led2:C", "green", [ "v19.2", "h0.4" ] ],
    [ "led2:C", "led3:C", "green", [ "v19.2", "h19.6" ] ],
    [ "led3:C", "led4:C", "green", [ "v19.2", "h19.6" ] ],
    [ "nano:5", "led1:A", "green", [ "v-220.8", "h-201.6" ] ],
    [ "nano:4", "led3:A", "green", [ "v-220.8", "h-172.8" ] ],
    [ "nano:3", "led4:A", "green", [ "v-220.8", "h-163.2" ] ],
    [ "nano:2", "led2:A", "green", [ "v-220.8", "h-211.2" ] ],
    [ "nano:GND.2", "bz1:1", "black", [ "v-211.2", "h-163.2", "v-96", "h-57.6" ] ],
    [
      "nano:A0",
      "bz1:2",
      "green",
      [ "v-19.2", "h-38.4", "v-268.8", "h-38.4", "v-86.4", "h-57.2" ]
    ]
  ],
  "dependencies": {}
}