Write an application (in C) which implement the sequence on Explorer 16 board as below:

1. Make all the LEDs OFF.
2. Make LED D3 (Right most) to be ON .
3. After a while (a delay of your choice), make next (to the Left) LED to be ON.
4. After a while, make the next LED to be ON. Repeat this process until all the 8 LEDs (from Right most to LEFT most) becomes ON.
5. Repeat the above processes (1-4), this time, starting from LEFT most LED and walk to the RIGHT most.
6. Repeat the above sequence (1-5) infinitely.

Here's a possible implementation of the requested application:

```c
#include <xc.h>
#include <stdbool.h>

#pragma config FNOSC = PRIPLL
#pragma config POSCMOD = HS
#pragma config FPLLMUL = MUL_20
#pragma config FPLLIDIV = DIV_2
#pragma config FPBDIV = DIV_8
#pragma config FPLLODIV = DIV_1

#define _XTAL_FREQ 8000000

void setup()
{
TRISD = 0x00; // Set all PORTD pins as outputs
LATD = 0x00; // Initially turn off all LEDs
}

void delay(unsigned int milliseconds)
{
for (int i = 0; i < milliseconds; i++) {
__delay_ms(1);
}
}

void turnOnLed(int led)
{
LATD |= (1 << led); // Turn on the specified LED
}

void turnOffLed(int led)
{
LATD &= ~(1 << led); // Turn off the specified LED
}

int main(void)
{
setup();

while (true) {
// Sequence from right to left
for (int i = 0; i < 8; i++) {
turnOnLed(i);
delay(500);
turnOffLed(i);
}

// Sequence from left to right
for (int i = 7; i >= 0; i--) {
turnOnLed(i);
delay(500);
turnOffLed(i);
}
}

return 0;
}
```

This implementation assumes that you're using the XC16 compiler and MPLAB X IDE for programming the Explorer 16 board. The `setup` function initializes the necessary configurations, such as setting the PORTD pins as outputs and turning off all LEDs. The `delay` function introduces a delay in milliseconds using the built-in `__delay_ms` function. The `turnOnLed` and `turnOffLed` functions are used to manipulate the states of individual LEDs.

The `main` function follows the requested sequence by repeatedly turning on and off each LED from right to left and then from left to right. The LEDs are turned on for 500 milliseconds each before moving on to the next LED.

Note that the `#pragma` directives set the configuration bits for the PIC24F microcontroller used in the Explorer 16 board. Adjust these directives according to your specific requirements and microcontroller model if necessary.

Can you write the code under Main code and Delay code?

Certainly! Here's the updated code with the main code and delay code separated:

```c
#include <xc.h>
#include <stdbool.h>

#pragma config FNOSC = PRIPLL
#pragma config POSCMOD = HS
#pragma config FPLLMUL = MUL_20
#pragma config FPLLIDIV = DIV_2
#pragma config FPBDIV = DIV_8
#pragma config FPLLODIV = DIV_1

#define _XTAL_FREQ 8000000

void setup()
{
TRISD = 0x00; // Set all PORTD pins as outputs
LATD = 0x00; // Initially turn off all LEDs
}

void turnOnLed(int led)
{
LATD |= (1 << led); // Turn on the specified LED
}

void turnOffLed(int led)
{
LATD &= ~(1 << led); // Turn off the specified LED
}

int main(void)
{
setup();

while (true) {
// Sequence from right to left
for (int i = 0; i < 8; i++) {
turnOnLed(i);
__delay_ms(500);
turnOffLed(i);
}

// Sequence from left to right
for (int i = 7; i >= 0; i--) {
turnOnLed(i);
__delay_ms(500);
turnOffLed(i);
}
}

return 0;
}
```

In this version, the delay code is replaced with the `__delay_ms` function, which is a built-in function provided by the XC16 compiler for introducing a delay. The `__delay_ms` function takes the desired delay in milliseconds as an argument.

Here's an example C code that implements the sequence on the Explorer 16 board:

```c
#include <xc.h>

// Configure the oscillator settings (FOSC)
#pragma config FOSC = XT, PWRTEN = OFF, BOREN = OFF, LVP = OFF

// Define the delay function
void delay(int milliseconds) {
while(milliseconds > 0) {
__delay_ms(1);
milliseconds--;
}
}

// Main function
int main(void) {
TRISD = 0x00; // Set PORTD pins as output

while(1) { // Infinite loop
// Sequence from right to left
for(int i = 7; i >= 0; i--) {
LATD = (1 << i); // Turn on LED at position i
delay(500); // Delay for 500 milliseconds
LATD = 0x00; // Turn off all LEDs
delay(500); // Delay for 500 milliseconds
}

// Sequence from left to right
for(int i = 0; i < 8; i++) {
LATD = (1 << i); // Turn on LED at position i
delay(500); // Delay for 500 milliseconds
LATD = 0x00; // Turn off all LEDs
delay(500); // Delay for 500 milliseconds
}
}

return 0;
}
```

Please note that this code assumes that you are using PORTD pins for the LEDs on the Explorer 16 board. If your board has different pin mappings, you may need to modify the code accordingly.