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) {
TRISA = 0x00;
LATA = 0x00;

while(1) {
int i;
int j;

// Right to Left sequence
for(i=0; i<8; i++) {
LATA |= (1 << i);
delayFunc();
}

// Left to Right sequence
for(j=7; j>=-1; j--) {
LATA |= (1<<j);
delayFunc();
}

// Left to Right sequence if SW3 is pressed
if(PORTDbits.RD6 == 0) {
LATA = 0x00;
for(j=8; j>=-1; 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;
}
}

}

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.

Can you make very simple code, please?

Certainly! Here's a simplified version of the code that incorporates the requirements:

```c
#define _XTAL_FREQ 16000000 // Oscillator frequency

#include <xc.h>

// Function prototypes
void interrupt ISR();
void delayFunc();

unsigned int count1 = 200;
unsigned int count2 = 200;
unsigned char pattern = 0x18;
unsigned char direction = 1;

void main(void) {
TRISA = 0xFF; // Set PORTA as output
LATA = 0x00; // Initialize PORTA as LOW

INTCONbits.GIE = 1; // Enable global interrupts
T1CON = 0x31; // Set Timer1 in 16-bit mode with 1:8 prescaler and internal clock source
TMR1H = 0xFF; // Set initial Timer1 register values
TMR1L = 0x7E;

while(1) {
if(!PORTDbits.RD6){
pattern = 0x18;
direction = 1;
}
else{
pattern = 0xC0;
direction = -1;
}

T1CONbits.TMR1ON = 1; // Start Timer1
while(T1CONbits.TMR1ON); // Wait for Timer1 to overflow

LATA = pattern; // Update LEDs

delayFunc(); // Delay between pattern transition
}

return -1;
}

// Timer1 interrupt service routine
void interrupt ISR() {
if (PIR1bits.TMR1IF) // Check if Timer1 overflowed
{
T1CONbits.TMR1ON = 0; // Stop Timer1
PIR1bits.TMR1IF = 0; // Clear Timer1 overflow flag
TMR1H = 0xFF; // Reset Timer1 register values
TMR1L = 0x7E;
LATAbits.LATA0 ^= 1; // Toggle the RUN LED (D10)
}
}

void delayFunc() {
for(int j = 0; j < count1; j++) {
for(int k = 0; k < count2; k++) {
asm("nop"); // No operation
}
}
}
```

Note that this code assumes that the proper configuration bits have been set based on the hardware setup and specific microcontroller being used.

Sure, here is a simplified version of the code that implements the requested functionality:

```c
#include <xc.h>

#define _XTAL_FREQ 8000000 // define the frequency of the microcontroller

void initialize(void);

void main(void) {
initialize(); // initialize the microcontroller

while (1) {
// Toggle RUN LED at 1.45 second interval
__delay_ms(1450); // delay for 1.45 seconds
LATAbits.LATA0 ^= 1; // toggle RUN LED (D10)

// Knight Rider pattern
if (PORTDbits.RD6 == 0) { // check if switch (S3) is open
for (int i = 0; i < 8; i++) {
LATA = (1 << (9 - i)); // set LED pins according to pattern from Left to Right direction
__delay_ms(250); // delay for 250 milliseconds
}
} else { // switch (S3) is closed
for (int i = 0; i < 8; i++) {
LATA = (1 << (3 + i)); // set LED pins according to pattern from Right to Left direction
__delay_ms(250); // delay for 250 milliseconds
}
}
}

return;
}

void initialize(void) {
// Configure TRIS registers for LED pins
TRISAbits.TRISA0 = 0; // RUN LED (D10)
TRISAbits.TRISA1 = 0; // LED D9
TRISAbits.TRISA2 = 0; // LED D8
TRISAbits.TRISA3 = 0; // LED D7
TRISAbits.TRISA4 = 0; // LED D6
TRISAbits.TRISA5 = 0; // LED D5
TRISBbits.TRISB0 = 0; // LED D4
TRISBbits.TRISB1 = 0; // LED D3

// Configure PORTD as input for switch (S3)
TRISDbits.TRISD6 = 1;

// Initialize LED pins to turn off all LEDs
LATA = 0x00;
LATB = 0x00;

// Configure Timer1 for interrupt at 1.45 second interval
T1CONbits.TMR1ON = 0; // stop Timer1
T1CONbits.TMR1CS = 0; // use internal clock (Fosc/4)
T1CONbits.T1CKPS = 0b11; // 1:8 prescaler
TMR1H = 0x80; // initial value for Timer1 high byte
TMR1L = 0x00; // initial value for Timer1 low byte
PIE1bits.TMR1IE = 1; // enable Timer1 interrupt
INTCONbits.PEIE = 1; // enable peripheral interrupts
INTCONbits.GIE = 1; // enable global interrupts
T1CONbits.TMR1ON = 1; // start Timer1
}

void __interrupt() isr() {
if (PIR1bits.TMR1IF == 1) { // check if Timer1 interrupt flag is set
PIR1bits.TMR1IF = 0; // clear Timer1 interrupt flag

// Toggle RUN LED (D10)
LATAbits.LATA0 ^= 1;
}
}
```

Please note that this code assumes the necessary header files are included and the microcontroller's configuration bits are properly set. Also, make sure to check the pin assignments and adjust them accordingly for your specific hardware setup.

Sure! Here's a simplified version of the code that meets your requirements:

```c
#include <xc.h>

// Function prototypes
void init(void);
void delay(unsigned int milliseconds);

// Global variables
unsigned int toggleDelay = 2000; // Toggle delay in milliseconds

void main(void) {
init(); // Initialize the microcontroller

while(1) {
// Toggle the RUN LED
LATAbits.LATA0 = !LATAbits.LATA0;

// Delay for 1.45 seconds
delay(1450);

// Check the status of switch S3
if(PORTDbits.RD6 == 0) {
// Right to left direction
for(int i = 6; i >= 0; i--) {
LATAbits.LATA1 = 1 << i; // Set LED pattern
delay(toggleDelay);
}
} else {
// Left to right direction
for(int i = 0; i <= 6; i++) {
LATAbits.LATA1 = 1 << i; // Set LED pattern
delay(toggleDelay);
}
}
}
}

void init(void) {
// Configure I/O ports
TRISA = 0b00000001; // RA0 as output (RUN LED), RA1-RA7 as outputs (LED pattern)
TRISD = 0b01000000; // RD6 as input (Switch S3)

// Configure Timer1 for interrupt
T1CONbits.TMR1ON = 0; // Disable Timer1
T1CONbits.T1CKPS = 0b11; // Prescaler 1:8
T1CONbits.T1OSCEN = 0; // Oscillator disabled
T1CONbits.TMR1CS = 0; // Internal clock (Fosc/4)
TMR1H = 0xF6; // Set initial value for Timer1 (65536 - 50000)
TMR1L = 0xEE; // (assuming Fosc = 8MHz)
PIE1bits.TMR1IE = 1; // Enable Timer1 interrupt
INTCONbits.GIE = 1; // Enable global interrupts

// Configure interrupts
INTCONbits.PEIE = 1; // Enable peripheral interrupts
INTCONbits.GIE = 1; // Enable global interrupts

// Start Timer1
T1CONbits.TMR1ON = 1;
}

void __interrupt() isr(void) {
if(PIR1bits.TMR1IF) { // Timer1 interrupt flag is set
// Clear Timer1 interrupt flag
PIR1bits.TMR1IF = 0;

// Reload Timer1 for 1.45 seconds delay
TMR1H = 0x5B;
TMR1L = 0x8C;
}
}

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

Note: This code assumes that the microcontroller you are using has the necessary peripherals (Timer1, ports) as mentioned in your requirements. You may need to make some adjustments based on your specific microcontroller and its pin configuration.