Implement the design on Explorer 16 as Project 1. 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.

Add the 3.5 seconds timer to this code

#define _XTAL_FREQ 8000000 // Specify the oscillator frequency

unsigned int count1 = 200;
unsigned int count2 = 200;

int main(void){
TRISA = 0x00; // Set PORTA as output
TRISDbits.TRISD6 = 1; // Set SW3 input

while(1) {
int i;
int j;
// Toggle RUN LED (D10) every 3.5 seconds using Timer1
LATDbits.LATD0 = !LATDbits.LATD0;
delayFunc();

// Knight Rider pattern from Left to Right direction
for(i = 0; i <= 6; i++) {
LATA = (1 << i);
delayFunc();
}

// Knight Rider pattern: Left to Right or Right to Left depending on SW3 state
if (PORTDbits.RD6 == 0) {
for(j = 7; j >= 0; j--) {
LATA = (1 << j);
delayFunc();
}
} else {
for(j = 0; j <= 7; j++) {
LATA = (1 << j);
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;
}
}
}

#include <xc.h>

#include <pic.h>

#define _XTAL_FREQ 8000000 // Specify the oscillator frequency

unsigned int count1 = 200;
unsigned int count2 = 200;

void delayFunc(void);

int main(void)
{
TRISA = 0x00; // Set PORTA as output
TRISDbits.TRISD6 = 1; // Set SW3 input
TRISDbits.TRISD0 = 0; // Set RD0 as output

while(1) {
int i;
int j;
// Toggle RUN LED (D10) every 3.5 seconds using Timer1
LATDbits.LATD0 = !LATDbits.LATD0;
__delay_ms(3500);

// Knight Rider pattern from Left to Right direction
for(i = 0; i <= 6; i++) {
LATA = (1 << i);
delayFunc();
}

// Knight Rider pattern: Left to Right or Right to Left depending on SW3 state
if (PORTDbits.RD6 == 0) {
for(j = 7; j >= 0; j--) {
LATA = (1 << j);
delayFunc();
}
} else {
for(j = 0; j <= 7; j++) {
LATA = (1 << j);
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;
}
}
}

To implement the 3.5 seconds timer interval using Timer1 module in the code, you can make the following changes:

1. Begin by including the necessary header files:

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

2. Configure the Timer1 module to generate an interrupt every 3.5 seconds:

```c
void timer1_init() {
T1CONbits.T1CKPS = 0b11; // 1:8 prescaler value
T1CONbits.RD16 = 1; // 16-bit mode enabled

// Calculate the timer value based on the desired delay interval
unsigned int timer_value = 62500; // Assuming 8MHz oscillator frequency

// Load the timer value into TMR1 registers
TMR1H = (timer_value >> 8) & 0xFF;
TMR1L = timer_value & 0xFF;

PIE1bits.TMR1IE = 1; // Enable Timer1 interrupt
INTCONbits.PEIE = 1; // Enable peripheral interrupts
INTCONbits.GIE = 1; // Enable global interrupts

T1CONbits.TMR1ON = 1; // Start Timer1
}
```

3. Create an interrupt service routine (ISR) for Timer1:

```c
void __interrupt(low_priority) timer1_isr(void) {
if (PIR1bits.TMR1IF == 1) {
// Toggle the RUN LED (D10)
LATDbits.LATD0 ^= 1;

// Reset interrupt flag
PIR1bits.TMR1IF = 0;

// Reload the timer value for the next interval
unsigned int timer_value = 62500; // Assuming 8MHz oscillator frequency
TMR1H = (timer_value >> 8) & 0xFF;
TMR1L = timer_value & 0xFF;
}
}
```

4. Modify the `main` function to initialize the Timer1 module and remove the existing delay function:

```c
int main(void){
TRISA = 0x00; // Set PORTA as output
TRISDbits.TRISD6 = 1; // Set SW3 input

timer1_init(); // Initialize Timer1

while(1) {
int i;
int j;

// Knight Rider pattern from Left to Right direction
for(i = 0; i <= 6; i++) {
LATA = (1 << i);
__delay_ms(500);
}

// Knight Rider pattern: Left to Right or Right to Left depending on SW3 state
if (PORTDbits.RD6 == 0) {
for(j = 7; j >= 0; j--) {
LATA = (1 << j);
__delay_ms(500);
}
} else {
for(j = 0; j <= 7; j++) {
LATA = (1 << j);
__delay_ms(500);
}
}
}
return -1;
}
```

Note: Make sure to set the correct oscillator frequency `_XTAL_FREQ` according to your microcontroller's configuration.

With these changes, the LED D10 (RUN LED) will toggle at every 3.5 seconds. The rest of the code remains the same, with the Knight Rider pattern in the specified directions. The process repeats infinitely.

To implement the design on Explorer 16 as Project 1 with a 3.5-second timer and LED D10 as the RUN LED indicator, you can use the following code:

```c
#define _XTAL_FREQ 8000000 // Specify the oscillator frequency

unsigned int count1 = 200;
unsigned int count2 = 200;

void delayFunc(void); // Function declaration

int main(void) {
TRISA = 0x00; // Set PORTA as output
TRISDbits.TRISD6 = 1; // Set SW3 input

while (1) {
int i;
int j;

// Toggle RUN LED (D10) every 3.5 seconds using Timer1
LATDbits.LATD0 = !LATDbits.LATD0;
__delay_ms(3500);

// Knight Rider pattern from Left to Right direction
for (i = 0; i < 7; i++) {
LATA = (1 << i);
__delay_ms(500);
}

// Knight Rider pattern: Left to Right or Right to Left depending on SW3 state
if (PORTDbits.RD6 == 0) {
for (j = 7; j >= 0; j--) {
LATA = (1 << j);
__delay_ms(500);
}
} else {
for (j = 0; j <= 7; j++) {
LATA = (1 << j);
__delay_ms(500);
}
}
}

return -1;
}

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

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

In this code, the `__delay_ms()` function is used to create the 3.5-second delay for the RUN LED and the 500ms delay for the Knight Rider pattern. The `delayFunc()` function is not being used in this code and can be removed.