Implement the design on Explorer 16. LED D10 will be used as the RUN LED indicator.

Write an application (in C) which does the following:
1. Make the RUN LED(D10) toggle at every 3.5 Seconds (exact) interval using one of the Timer (Timer 1) module of the Microcontroller.
2. The Knight Rider pattern now consists of 7 LEDs (D9-D3). If the switch (S3) is open, the pattern is from Left to Right direction. If the switch (S3) is closed, the pattern is from Right to Left direction.
3. Repeat the whole process in an infinite way.

Here is a possible implementation of the given design on Explorer 16 using the Timer 1 module of the Microcontroller:

```c
#include <xc.h>

// Configuration Bits
#pragma config FNOSC = PRIPLL // Primary Oscillator with PLL
#pragma config POSCMOD = XT // XT Oscillator mode
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider
#pragma config FPBDIV = DIV_8 // Peripheral Bus Clock Divider

#define SYS_FREQ 80000000UL // System frequency in Hz

#define TOGGLE_DELAY 3500 // Delay in milliseconds for toggling RUN LED
#define PATTERN_DELAY 300 // Delay in milliseconds for updating Knight Rider pattern

#define LED_RUN LATEbits.LATE0 // RUN LED indicator (D10)
#define SWITCH_DIRECTION PORTEbits.RE7 // Switch (S3) to change pattern direction
#define LED_PATTERN LATB

void delay_ms(unsigned int milliseconds) {
unsigned long t_start = _CP0_GET_COUNT();
unsigned long t_wait = milliseconds * (SYS_FREQ / 2 / 1000);

while ((_CP0_GET_COUNT() - t_start) < t_wait) {
continue;
}
}

void initTimer1() {
T1CONbits.ON = 0; // Turn OFF Timer 1 before configuration
TMR1 = 0; // Clear Timer 1

T1CONbits.TCKPS = 0b11; // 1:256 prescaler value
T1CONbits.TCS = 0; // Internal clock source (Peripheral Bus Clock)
T1CONbits.TGATE = 0; // Disable Gated mode
T1CONbits.TSIDL = 0; // Continue operation in Idle mode

PR1 = (SYS_FREQ / 256) * (TOGGLE_DELAY / 1000); // Set period value for 3.5 second toggle delay

IPC1bits.T1IP = 0x01; // Set Timer 1 priority level to 1
IFS0bits.T1IF = 0; // Clear Timer 1 Interrupt Flag
IEC0bits.T1IE = 1; // Enable Timer 1 interrupt

T1CONbits.ON = 1; // Turn ON Timer 1
}

int main(void) {
// Set RUN LED (D10) as output
TRISEbits.TRISE0 = 0;

// Set all pattern LEDs (D9-D3) as output
TRISB &= 0xFF81;

// Enable weak pull-ups for the switch (S3)
CNPUEbits.CNPUE7 = 1;

// Set initial pattern direction based on the switch (S3)
int patternDirection = (SWITCH_DIRECTION == 0) ? 1 : -1;

// Initialize Timer 1
initTimer1();

// Infinite loop
while (1) {
// Knight Rider pattern
for (int i = 0; i < 5; i++) {
if (patternDirection == 1) {
LED_PATTERN |= (0x18 >> i); // Light the LEDs from Left to Right (D9-D3)
} else {
LED_PATTERN |= (0xC0 >> i); // Light the LEDs from Right to Left (D9-D3)
}
delay_ms(PATTERN_DELAY);
LED_PATTERN &= ~(0xFF); // Turn off all pattern LEDs
delay_ms(PATTERN_DELAY);
}
}

return 0;
}

// Timer 1 Interrupt Service Routine
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void) {
IFS0bits.T1IF = 0; // Clear Timer 1 Interrupt Flag
LED_RUN = !LED_RUN; // Toggle RUN LED (D10)
}
```

This implementation uses Timer 1 in interrupt mode to toggle the RUN LED (D10) at every 3.5-second interval. The Knight Rider pattern is implemented using a for loop which controls the pattern direction based on the state of the switch (S3). The whole process is repeated infinitely in the main loop.

To implement the design on Explorer 16 and achieve the desired functionality, you can follow these steps:

Step 1: Set up the configuration:
- Include the necessary header files for the microcontroller being used.
- Configure the oscillator settings, system peripheral settings, and any other required configurations.

Step 2: Define the necessary constants and variables:
- Define the run LED (D10) pin as an output pin.
- Define the Knight Rider LEDs (D9-D3) pins as output pins.
- Define a variable to track the direction of the Knight Rider pattern (Left to Right or Right to Left).

Step 3: Configure Timer1:
- Configure Timer1 for a 3.5 second interval using the appropriate prescaler and register settings.

Step 4: Main loop:
- In the main loop, toggle the run LED (D10) state using the Timer1 interrupt.
- Check the state of switch S3.
- If S3 is open, shift the Knight Rider pattern from Left to Right.
- If S3 is closed, shift the Knight Rider pattern from Right to Left.

Step 5: Shift the Knight Rider pattern:
- Based on the direction determined in step 4, consecutively turn on and off the Knight Rider LEDs (D9-D3).

Step 6: Repeat the process:
- Once the pattern has completed shifting, repeat the entire process again in an infinite loop.

Please note that the exact implementation may vary depending on the specific microcontroller being used and the development environment. The code provided here is a general outline and may require some modifications to work correctly.

To implement the design on the Explorer 16 and achieve the functionality as described, you will need to use the Timer module and GPIO pins of the microcontroller. Here's how you can write the application in C to accomplish each requirement:

1. Toggling the RUN LED (D10) at every 3.5-second interval using Timer 1:

- Configure Timer 1 with the appropriate prescaler and period to generate an interrupt every 3.5 seconds.
- In the interrupt service routine for Timer 1, toggle the state of the RUN LED (D10) using the corresponding GPIO pin.

Here's an example code snippet to achieve this:

```c
#include <xc.h> // Include the microcontroller specific header file

#pragma config FOSC = INTOSCIO // Set the oscillator configuration
#pragma config WDTEN = OFF // Disable the watchdog timer

#define RUN_LED_PIN RB7 // Define the GPIO pin for RUN LED

void __interrupt() Timer1_ISR(void) // Timer1 interrupt service routine
{
if (TMR1IF) // Check if Timer 1 flag is set
{
TMR1IF = 0; // Clear the Timer 1 interrupt flag
RUN_LED_PIN ^= 1; // Toggle the state of the RUN LED
}
}

void main()
{
// Configure Timer 1 with desired settings
T1CON = 0b00000000; // Use internal clock, 1:1 prescaler

// Set the initial state of the RUN LED
RUN_LED_PIN = 0;

// Enable Timer 1 interrupt
TMR1IE = 1;

// Enable global interrupts
PEIE = 1;
GIE = 1;

while (1)
{
// Your main program logic here
// No need to do anything specific for this requirement
}
}
```

2. Creating the Knight Rider pattern with 7 LEDs (D9-D3) based on the state of switch S3:

- Read the state of switch S3 using the corresponding GPIO pin.
- Depending on the state of S3, you can control the order of toggling the LEDs to achieve the left-to-right or right-to-left direction.

Here's an example code snippet to achieve this:

```c
#define SWITCH_S3_PIN RB0 // Define the GPIO pin for switch S3

void knightRiderPattern()
{
if (SWITCH_S3_PIN) // Switch S3 is closed, right-to-left direction
{
// Toggle the LED's in right-to-left direction
for (int i = 6; i >= 3; i--)
{
LATB = (1 << i); // Set the corresponding LED pin high
__delay_ms(100); // Delay between each LED
LATB = 0; // Turn off all LED pins
}
}
else // Switch S3 is open, left-to-right direction (default)
{
// Toggle the LED's in left-to-right direction
for (int i = 3; i <= 6; i++)
{
LATB = (1 << i); // Set the corresponding LED pin high
__delay_ms(100); // Delay between each LED
LATB = 0; // Turn off all LED pins
}
}
}
```

3. Repeat the whole process infinitely:

- Call the `knightRiderPattern()` function in an infinite loop to continuously repeat the LED pattern.
- Since the code for toggling the RUN LED is implemented using Timer 1, it will automatically repeat every 3.5 seconds.

```c
void main()
{
// Configure Timer 1 and RUN LED as described in requirement 1

while (1)
{
knightRiderPattern(); // Call the function to create the Knight Rider pattern
}
}
```

Remember to adjust the configuration bits and GPIO pin assignments according to your specific microcontroller model and the Explorer 16 board.