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

Knight rider code:
unsigned int count1 = 200;
unsigned int count2 = 200;

void main(void) {
while (1)
{

bool sw = PORTDbits.RD6;

if( toggleDirection ) {
LATA <<= 1;
}
else {
LATA >>= 1;
}

if( LATA == 0x80 ) toggleDirection = false;
if( LATA == 0x01 ) toggleDirection = true;

if( !sw ) {
if( !pressed ) {
if( toggleDirection ){
toggleDirection = false;
LATA = 0x80;
}
else {
toggleDirection = true;
LATA = 0x01;
}
pressed = true;
}
}
else {
pressed = false;
}

delayFunc();

}
return -1;
}
}

void delayFunc(void)
{
int j,k;
int a;

for(j = 0; j < count1; j++)
{
for(k=0; k < count2; k++)
{
a = 0;
}
}

}

Using the knight rider code above, do the following:
Write an simple 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 implementation of the requirements outlined:

```C
#include <xc.h>

#define _XTAL_FREQ 16000000

unsigned int count1 = 200;
unsigned int count2 = 200;
bool toggleDirection = true;
bool pressed = false;

void main(void) {
TRISAbits.TRISA7 = 0; // Set pin A7 (RUN LED) as output
TRISB = 0xFF; // Set all pins in PORTB as input
TRISD = 0xFF; // Set all pins in PORTD as input

// Configure Timer1
TMR1 = 0; // Clear Timer1 register
T1CONbits.TMR1CS = 0; // Set Timer1 source as internal instruction cycle clock
T1CONbits.T1CKPS = 0b11; // Set Timer1 prescaler as 1:8
T1CONbits.TMR1ON = 1; // Enable Timer1

// Configure interrupt for Timer1
PIE1bits.TMR1IE = 1; // Enable Timer1 interrupt
INTCONbits.GIE = 1; // Enable global interrupts

while(1) {
bool sw = PORTDbits.RD6;

if(toggleDirection) {
LATA <<= 1;
} else {
LATA >>= 1;
}

if(LATA == 0x80) toggleDirection = false;
if(LATA == 0x01) toggleDirection = true;

if(!sw) {
if(!pressed) {
if(toggleDirection) {
toggleDirection = false;
LATA = 0x80;
} else {
toggleDirection = true;
LATA = 0x01;
}
pressed = true;
}
} else {
pressed = false;
}
}

return -1;
}

void __interrupt() isr(void) {
if(PIE1bits.TMR1IE && PIR1bits.TMR1IF) {
// Toggle RUN LED (D10) using pin A7
LATAbits.LATA7 ^= 1;

// Load Timer1 with initial value to achieve 1.45 second delay
TMR1 = 3036; // 65536 - (1.45s / (1 / (16MHz / 4) / 8))

// Clear Timer1 interrupt flag
PIR1bits.TMR1IF = 0;
}
}
```

Note: This implementation assumes that the LED pattern is connected to pins RA7 (RUN LED) to RA1 (D3). If the pattern is connected to different pins, please update the code accordingly. Additionally, make sure to configure the correct port for the switch (S3) input.

To implement the design on Explorer 16 as Project 1 with the given knight rider code, follow these steps:

Step 1: Set up the hardware
1. Connect the Explorer 16 development board to your computer.
2. Connect the LEDs D3-D10 to the corresponding I/O pins on the board. For example, connect LED D3 to the RB0 pin, D4 to RB1, and so on. Make sure to connect them in the correct order for the desired pattern.
3. Connect switch S3 to the RD6 pin on the board.

Step 2: Set up the software environment
1. Launch your preferred Integrated Development Environment (IDE) or text editor for programming in C.
2. Create a new project for the Microcontroller you are using and set it up with the necessary compiler and linker options.
3. Include the necessary libraries or header files for your Microcontroller to work with the Explorer 16 development board and Timer1 module.
4. Define the necessary configuration settings for your Microcontroller and board setup. This may include the oscillator settings and I/O pin configurations.

Step 3: Write the code
1. Copy the provided knight rider code into your main.c file.
2. Modify the code according to the requirements:
- Remove the unused variable declarations "count1" and "count2".
- Add the necessary definitions for configuring Timer1 as an interrupt source and setting the desired interval of 1.45 seconds.
- Update the code to use the new LED configuration (D9-D3 instead of D10) and switch S3 for changing the direction of the pattern.
- Add the necessary interrupt service routine (ISR) for Timer1 to toggle the RUN LED.

Your code should look like this:

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

#define _XTAL_FREQ 16000000 // Crystal oscillator frequency

volatile bool toggleDirection = false;
volatile bool pressed = false;

// Interrupt Service Routine for Timer1
void __interrupt() isr(void) {
if (TMR1IF) {
// Toggle the RUN LED (D10)
LATDbits.LATD10 ^= 1;

// Clear the Timer1 interrupt flag
TMR1IF = 0;
}
}

void main(void) {
// Configure the I/O pins
TRISD |= (1 << 6); // Set RD6 as input for switch S3
TRISAbits.TRISA9 = 0; // Set RA9 (D10) as output for RUN LED
TRISB &= 0b1111111100011111; // Set RB5-RB3 as outputs for LEDs D9-D3

// Configure Timer1 for interrupt every 1.45 seconds
T1CONbits.TMR1CS = 0; // Set Timer1 to use internal clock (Fosc/4)
T1CONbits.T1CKPS = 0b11; // Set Timer1 prescaler to 1:8
TMR1H = 0x8F; // Load Timer1 high byte with 0x8F
TMR1L = 0xFF; // Load Timer1 low byte with 0xFF
TMR1IE = 1; // Enable Timer1 interrupt
PEIE = 1; // Enable Peripheral Interrupt
GIE = 1; // Enable Global Interrupt

while (1) {
bool sw = PORTDbits.RD6;

if (toggleDirection) {
LATB = (LATB << 1) | 0b00000100;
} else {
LATB = (LATB >> 1) | 0b10000000;
}

if (LATB == 0b11111000) toggleDirection = false;
if (LATB == 0b00000100) toggleDirection = true;

if (!sw) {
if (!pressed) {
if (toggleDirection) {
toggleDirection = false;
LATB = 0b11111000;
} else {
toggleDirection = true;
LATB = 0b00000100;
}
pressed = true;
}
} else {
pressed = false;
}
}

return -1;
}

Step 4: Build and program the Microcontroller
1. Build your project to compile the code and check for any errors or warnings.
2. If there are no errors or warnings, program the Microcontroller with the generated binary file.

Step 5: Test the application
1. Verify that the LEDs are connected correctly and are lighting up according to the desired pattern.
2. Switch on S3 to change the direction of the pattern and verify that it updates accordingly.
3. Observe that the RUN LED (D10) toggles at every 1.45-second interval accurately.
4. Repeat the testing process to ensure the application operates as expected in an infinite loop.

Congratulations! You have implemented the knight rider pattern on the Explorer 16 development board as Project 1, toggling the RUN LED at a specific interval using the Timer1 module.

To implement the given design on the Explorer 16 as Project 1, follow these steps:

1. Set up the necessary hardware connections:
- Connect LED D10 (RUN LED) to a GPIO pin on the microcontroller.
- Connect switch S3 to another GPIO pin on the microcontroller.
- Connect LEDs D9-D3 in series with appropriate current-limiting resistors to GPIO pins on the microcontroller.

2. Configure Timer 1 as an interrupt-based timer to achieve precise timing:
- Set the timer's prescaler, period, and interrupt enable registers according to the desired 1.45-second interval. Refer to the microcontroller's datasheet or reference manual for specific instructions.

3. Implement the main function with the following logic:
- Initialize the necessary variables to keep track of LED patterns, switch status, and toggle direction.
- Enter an infinite loop to continuously repeat the process.
- Check the status of the switch connected to S3 (PORTDbits.RD6).
- If the switch is open (sw = false), update the toggle direction and set the LED pattern accordingly.
- If the switch is closed (sw = true), update the toggle direction and set the LED pattern accordingly.
- Implement a delay function (delayFunc) to introduce a delay between LED pattern updates.
- Call the delay function to introduce the required delay.

4. Implement the delay function (delayFunc):
- Use nested loops to introduce a delay based on the provided count1 and count2 variables.
- Use a dummy variable (a) to prevent the compiler from optimizing out the loops.

5. Enable and configure the interrupt mechanism for Timer 1:
- Set up the interrupt service routine (ISR) for Timer 1.
- In the ISR, toggle the RUN LED (D10) based on the desired interval.
- Clear the interrupt flag for Timer 1 in the interrupt service routine.

6. Build and program the microcontroller with the developed code.

By following these steps, you should be able to implement the given design on the Explorer 16 as Project 1.