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 1.45 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.
4. To toggle the RUN LED, precisely at 1.45 Seconds interval, you need to use the interrupt mechanism for the Timer1.

Here is an example implementation in C language using the PIC24F Microcontroller and MPLABX IDE:

```c
#include <xc.h>

// Configuration settings
#pragma config FNOSC = FRCDIV // Internal Fast RC oscillator with divided clock
#pragma config FWDTEN = OFF // Disable Watchdog Timer
#pragma config FSOSCEN = OFF // Disable secondary oscillator
#pragma config JTAGEN = OFF // Disable JTAG port

// Function prototypes
void initTimer1(void);
void toggleRunLED(void);
void initLEDs(void);
void initSwitch(void);

// Global variables
unsigned char knightRiderPattern[7] = {0b0000001, 0b0000010, 0b0000100, 0b0001000, 0b0010000, 0b0100000, 0b1000000}; // LED patterns for Knight Rider
unsigned char currentPatternIndex = 0; // Current index of the pattern array
unsigned char direction = 1; // Direction flag for Knight Rider pattern
unsigned int runLEDPeriod = 44100; // 1.45 seconds period for RUN LED
unsigned int runLEDCounter = 0; // Counter for RUN LED toggling
unsigned int timer1InterruptCounter = 0; // Counter for Timer1 interrupts

int main(void) {
// Initialize peripherals
initTimer1();
initLEDs();
initSwitch();

while (1) {
// Knight Rider pattern
if (direction) {
LATB = knightRiderPattern[currentPatternIndex];
currentPatternIndex++;
if (currentPatternIndex >= 7) {
currentPatternIndex = 0;
}
} else {
LATB = knightRiderPattern[currentPatternIndex];
if (currentPatternIndex == 0) {
currentPatternIndex = 6;
} else {
currentPatternIndex--;
}
}

// RUN LED toggling
if (runLEDCounter >= runLEDPeriod) {
toggleRunLED();
runLEDCounter = 0;
}
}

return 0;
}

void __attribute__((__interrupt__, __auto_psv__)) _T1Interrupt(void) {
IFS0bits.T1IF = 0; // Clear Timer1 interrupt flag
timer1InterruptCounter++;
runLEDCounter++;

if (timer1InterruptCounter >= 303) { // 303 Timer1 interrupts = 44100 cycles (1.45 seconds)
toggleRunLED();
timer1InterruptCounter = 0;
}
}

void initTimer1(void) {
T1CONbits.TON = 0; // Disable Timer1
T1CONbits.TCS = 0; // Select internal instruction cycle clock
T1CONbits.TCKPS = 0b00; // Set Timer1 prescale value to 1:1
TMR1 = 0; // Clear Timer1 register
PR1 = 303; // Set period for 1.45 seconds

IPC0bits.T1IP = 1; // Set Timer1 interrupt priority to 1
IFS0bits.T1IF = 0; // Clear Timer1 interrupt flag
IEC0bits.T1IE = 1; // Enable Timer1 interrupt

T1CONbits.TON = 1; // Enable Timer1
}

void toggleRunLED(void) {
LATAbits.LATA0 ^= 1; // Toggle RUN LED (D10)
}

void initLEDs(void) {
TRISAbits.TRISA0 = 0; // Set RUN LED (D10) pin as output
TRISB = 0x0000; // Set all PORTB pins as output
LATB = 0x0000; // Clear all PORTB pins
}

void initSwitch(void) {
TRISBbits.TRISB4 = 1; // Set switch (S3) pin as input
CNPU2bits.CN22PUE = 1; // Enable internal pull-up resistor for switch (S3) pin
}

```

To implement the design on Explorer 16, follow these steps:

1. Set up the hardware:
- Connect LED D10 to a suitable output pin on the microcontroller.
- Connect the 7 LEDs (D9-D3) and switch S3 to appropriate input/output pins.

2. Initialize the Timer1 module:
- Configure Timer1 to operate in timer mode with a prescaler value of 1:256.
- Set the Timer1 period to achieve a time interval of 1.45 seconds. The calculation for 1.45 seconds with 16 MHz clock frequency and 1:256 prescaler is:
Timer1_Period = (1.45 * 16000000) / (256) - 1

3. Configure Timer1 interrupt:
- Enable Timer1 interrupt.
- Set the interrupt priority and enable global interrupts.

4. Implement the interrupt handler:
- In the interrupt handler, toggle the RUN LED (D10) by writing the appropriate logic to the output pin controlling the LED.

5. Implement the Knight Rider pattern:
- Create a variable to store the direction of the pattern (left to right or right to left).
- Read the status of switch S3 to determine the direction.
- Implement a loop that iterates through the LEDs in the pattern using a variable to represent the current LED position.
- Inside the loop, turn on the LED at the current position and delay for a short period of time (e.g., 100 milliseconds).
- Depending on the direction, increment or decrement the current LED position.
- Repeat the loop until reaching the end of the pattern, then reverse the direction and continue.

6. Create an infinite loop:
- After implementing the Timer1 interrupt handler and the Knight Rider pattern, create an infinite loop that continuously executes the pattern.

Here is the C code implementation:

```
#include <p30Fxxxx.h> // Include the appropriate microcontroller header file

// Initialize variables
unsigned int knightPosition = 0;
unsigned int knightDirection = 0;

// Timer1 interrupt handler
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void)
{
// Toggle the RUN LED (D10)
LATBbits.LATB8 ^= 1;

// Clear the Timer1 interrupt flag
IFS0bits.T1IF = 0;
}

int main(void)
{
// Configure the RUN LED (D10) as an output
TRISBbits.TRISB8 = 0;

// Configure the 7 LEDs (D9-D3) and switch S3 as appropriate inputs/outputs
// ...

// Initialize Timer1
T1CONbits.TON = 0; // Disable Timer1
TMR1 = 0; // Clear Timer1 value
PR1 = Timer1_Period; // Set Timer1 period
T1CONbits.TCKPS = 3; // Set Timer1 prescaler to 1:256
IFS0bits.T1IF = 0; // Clear Timer1 interrupt flag
IPC0bits.T1IP = priority; // Set Timer1 interrupt priority
IEC0bits.T1IE = 1; // Enable Timer1 interrupt

// Enable global interrupts
INTCON1bits.NSTDIS = 0;

// Start Timer1
T1CONbits.TON = 1;

while(1)
{
// Read the status of switch S3 and set the direction accordingly
knightDirection = PORTXbits.RXn;

// Implement the Knight Rider pattern
for (knightPosition = 0; knightPosition < 7; knightPosition++)
{
// Turn on the LED at the current position
// ...

// Delay for a short period of time (e.g., 100 milliseconds)
Delay_ms(100);

// Increment or decrement the current LED position based on the direction
if (knightDirection == 0)
{
knightPosition++;
if (knightPosition >= 7)
knightPosition = 0;
}
else
{
if (knightPosition == 0)
knightPosition = 6;
else
knightPosition--;
}
}
}
return 0;
}
```

Note: Replace `PORTXbits.RXn` and `Delay_ms(100)` with the appropriate code to read the switch status and provide a delay function, respectively. Make sure to configure the input/output pins correctly and use the appropriate microcontroller header file.

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

1. Set up the Explorer 16 development board:
- Connect the LEDs (D10, D9-D3) to the appropriate I/O pins on the microcontroller. Refer to the board's documentation for the specific pin mappings.
- Connect the switch (S3) to a digital input pin.

2. Configure Timer1 to toggle the RUN LED at a 1.45-second interval:
- Enable Timer1 and set its prescaler to an appropriate value to achieve the desired time period (1.45 seconds). Refer to the microcontroller's datasheet to determine the prescaler settings.
- Configure Timer1 to generate an interrupt when the timer reaches its period value (1.45 seconds).
- In the Timer1 interrupt service routine (ISR), toggle the state of the RUN LED (D10).

3. Implement the Knight Rider pattern for LEDs D9-D3:
- Determine the direction of the LED pattern based on the state of switch S3.
- Create a variable to track the current LED position in the pattern.
- Use a loop to continuously shift the LED pattern in the desired direction.
- Use appropriate delay functions or timer interrupts to control the speed at which the LEDs transition between positions.

4. Create an infinite loop to continuously repeat the process:
- Place the code for the RUN LED toggle and Knight Rider pattern generation inside an infinite loop.

Here's a sample code snippet in C that demonstrates the implementation:

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

#define RUN_LED LATDbits.LATD10 // Define the RUN LED pin
#define SWITCH_S3 PORTDbits.RD10 // Define the switch S3 pin

// Timer1 configuration
void Timer1_Init() {
T1CONbits.TON = 0; // Disable Timer1
// Configure Timer1 control registers and periods for 1.45s interval
// Set Timer1 interrupt flag to 0
T1CONbits.TON = 1; // Enable Timer1
}

// Interrupt service routine for Timer1
void __interrupt() Timer1_ISR(void) {
if (PIR1bits.TMR1IF) {
PIR1bits.TMR1IF = 0; // Clear Timer1 interrupt flag
// Toggle the state of the RUN LED
RUN_LED = !RUN_LED;
}
}

// Knight Rider pattern generation
void KnightRider() {
int ledPosition = 0;
int direction = (SWITCH_S3 == 0) ? 1 : -1; // Determine the direction based on switch S3

while (1) {
// Set the LED pattern at the current position
// Turn off other LEDs
for (int i = 3; i <= 9; i++) {
LATDbits.LATD(i) = (i == ledPosition) ? 1 : 0;
}

ledPosition += direction; // Move to the next LED position

// Reverse direction at the ends of the LED sequence
if (ledPosition == 9 || ledPosition == 3) {
direction *= -1;
}

// Add appropriate delay here for the desired animation speed
}
}

int main() {
// Set up I/O pins

// Configure Timer1
Timer1_Init();

// Enable global interrupts

// Call the KnightRider function to start the pattern generation

while (1) {
// Main program loop (optional)
}
}
```

Note: This code snippet serves as a general example and may require modifications based on your specific microcontroller and development environment. Make sure to consult the datasheet and relevant documentation for the precise configuration and pin mappings of your microcontroller and development board.