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.

Can you write a short program?

Certainly! Here's a short C program that implements the requirements you mentioned:

```c
#include <xc.h> // Include the necessary header file for your microcontroller

void configureTimer1(); // Function to configure Timer 1 module
void configureIO(); // Function to configure Input/Output pins

int main() {
configureTimer1(); // Configure Timer 1 module
configureIO(); // Configure Input/Output pins

while (1) { // Infinite loop
// Toggle the RUN LED (D10) every 3.5 seconds
while (TMR1 < 14000) {} // Wait for 3.5 seconds (adjust the value based on your microcontroller frequency and prescaler)
TMR1 = 0; // Reset Timer 1 register
LATAbits.LATA4 = !LATAbits.LATA4; // Toggle the RUN LED (D10)

// Knight Rider pattern from Left to Right direction
if (PORTBbits.RB4 == 0) { // Check if switch (S3) is open
LATA = 0b0000111; // Turn on LEDs D9-D3 (adjust the values based on your circuit)
while (TMR1 < 14000) {} // Wait for 3.5 seconds
TMR1 = 0; // Reset Timer 1 register
LATA = 0; // Turn off all LEDs
}

// Knight Rider pattern from Right to Left direction
else { // Switch (S3) is closed
LATA = 0b1000000; // Turn on LED D3 (adjust the value based on your circuit)
while (TMR1 < 14000) {} // Wait for 3.5 seconds
TMR1 = 0; // Reset Timer 1 register
LATA = 0; // Turn off all LEDs
}
}

return 0;
}

void configureTimer1() {
T1CONbits.T1CKPS = 3; // Set Timer 1 prescaler to 1:8 (adjust the value based on your requirements)
T1CONbits.TMR1CS = 0; // Set Timer 1 clock source as Internal Clock (adjust the value based on your requirements)
T1CONbits.TMR1ON = 1; // Enable Timer 1 module
}

void configureIO() {
TRISAbits.TRISA4 = 0; // Configure pin RA4 as Output for the RUN LED (D10)
TRISBbits.TRISB4 = 1; // Configure pin RB4 as Input for the switch (S3)
TRISA = 0; // Configure all pins of PORTA as Output for the LEDs D9-D3
}
```

Before compiling and running this program, make sure you have the necessary header file for your microcontroller included (in this case, it's `xc.h`) and adjust the values based on your specific microcontroller and circuit configuration.

This program continuously toggles the RUN LED (D10) every 3.5 seconds using Timer 1 module. If the switch (S3) is open, it lights up the Knight Rider pattern from Left to Right (LEDs D9-D3). If the switch (S3) is closed, it lights up the Knight Rider pattern from Right to Left (LEDs D3-D9). The whole process repeats infinitely.

Make sure to replace the specific pin names (`LATAbits.LATA4`, `PORTBbits.RB4`, etc.) with the corresponding pin names for your microcontroller and circuit. Additionally, adjust the LED patterns and timing values based on your requirements.

Sure! Here's a short program in C that implements the mentioned requirements:

```c
#include <xc.h>

// Configuration bits
#pragma config FOSC = INTIO67 // Internal Oscillator
#pragma config PLLCFG = OFF // PLL x4 Enable
#pragma config PRICLKEN = ON // Primary Clock Enable
#pragma config WDTEN = OFF // Watchdog Timer Disable
#pragma config MCLRE = EXTMCLR // Master Clear Enable

// Function prototypes
void init(void);
void toggle_LED(void);
void knight_rider_pattern(void);

// Global variables
unsigned char led_direction = 0; // 0 for Left to Right, 1 for Right to Left

// Interrupt service routine for Timer1 overflow
void interrupt ISR(void)
{
if (TMR1IF) {
TMR1IF = 0; // Clear Timer1 interrupt flag
toggle_LED(); // Toggle RUN LED
knight_rider_pattern(); // Update Knight Rider pattern
}
}

// Initialize the microcontroller
void init(void)
{
// Set up Timer1
T1CON = 0b00110000; // Timer1 ON, 1:8 Prescaler
TMR1H = 0; // Clear Timer1 high register
TMR1L = 0; // Clear Timer1 low register
TMR1IE = 1; // Enable Timer1 interrupt
PEIE = 1; // Enable peripheral interrupts
GIE = 1; // Enable global interrupts

// Set up I/O pins
TRISAbits.RA7 = 0; // Configure RA7 as output (RUN LED)
TRISBbits.RB0 = 0; // Configure RB0 as output (Knight Rider LED D9)
TRISBbits.RB1 = 0; // Configure RB1 as output (Knight Rider LED D8)
TRISBbits.RB2 = 0; // Configure RB2 as output (Knight Rider LED D7)
TRISBbits.RB3 = 0; // Configure RB3 as output (Knight Rider LED D6)
TRISCbits.RC0 = 0; // Configure RC0 as output (Knight Rider LED D5)
TRISCbits.RC1 = 0; // Configure RC1 as output (Knight Rider LED D4)
TRISCbits.RC2 = 0; // Configure RC2 as output (Knight Rider LED D3)

// Initialize LED states
PORTAbits.RA7 = 0; // Turn off RUN LED
PORTB = 0; // Turn off Knight Rider LEDs
PORTC = 0; // Turn off Knight Rider LEDs
}

// Toggle RUN LED
void toggle_LED(void)
{
PORTAbits.RA7 ^= 1; // Toggle RUN LED
}

// Update Knight Rider pattern
void knight_rider_pattern(void)
{
if (led_direction == 0) {
PORTB <<= 1; // Shift Knight Rider LEDs Left
if (PORTCbits.RC2) {
PORTC <<= 1; // Shift Knight Rider LEDs Left
PORTCbits.RC0 = 1; // Turn on Knight Rider LED D3
}
else {
PORTC <<= 1; // Shift Knight Rider LEDs Left
PORTCbits.RC2 = 1; // Turn on Knight Rider LED D5
}
}
else {
PORTC >>= 1; // Shift Knight Rider LEDs Right
if (PORTCbits.RC0) {
PORTB >>= 1; // Shift Knight Rider LEDs Right
PORTCbits.RC2 = 0; // Turn on Knight Rider LED D3
}
else {
PORTB >>= 1; // Shift Knight Rider LEDs Right
PORTCbits.RC0 = 0; // Turn on Knight Rider LED D5
}
}
__delay_ms(3500); // Delay 3.5 seconds
}

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

while(1) {
// Check the state of switch S3
if (PORTAbits.RA4) {
led_direction = 0; // Left to Right
}
else {
led_direction = 1; // Right to Left
}
}
}
```

Please note that this code assumes you are using the XC8 compiler for PIC microcontrollers. The specific microcontroller used on the Explorer 16 board is not mentioned, so you may need to modify some details according to the specific microcontroller you are using.

Also note that the __delay_ms() function is used to provide the 3.5-second delay. The actual delay value may vary depending on the clock frequency of the microcontroller. You may need to adjust this delay value accordingly.

Certainly! Here's a short program in C that implements the design on the Explorer 16 using the Microcontroller's Timer 1 module:

```c
#include <xc.h>

// Define the LED pins
#define RUN_LED LATDbits.LATD10
#define LED1 LATDbits.LATD9
#define LED2 LATDbits.LATD8
#define LED3 LATDbits.LATD7
#define LED4 LATDbits.LATD6
#define LED5 LATDbits.LATD5
#define LED6 LATDbits.LATD4
#define LED7 LATDbits.LATD3

// Define the switch pin
#define SWITCH PORTDbits.RD7

void init();
void toggle_RUN_LED();
void knight_rider_pattern();

void init()
{
// Set the direction of LED and switch pins
TRISD = 0x7F; // Set RD7 as input, RD10-RD3 as output

// Set the initial states of LED pins
LATD = 0x00; // Turn off all LEDs initially

// Configure Timer1 for 3.5 seconds interval
T1CON = 0x8030; // Enable Timer1, System clock as source, prescaler 1:256

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

// Enable global interrupts
INTCONbits.MVEC = 1; // Enable multi-vector interrupts
__builtin_enable_interrupts();
}

void toggle_RUN_LED()
{
// Toggle the RUN LED state
RUN_LED = !RUN_LED;
}

void knight_rider_pattern()
{
static unsigned char ledPattern = 0x04; // Initial pattern starting from LED3 to LED9
static unsigned char direction = 1; // Direction: 1 for Left to Right, 0 for Right to Left
unsigned char shiftAmount = (direction == 1) ? 1 : -1;

// Shift the pattern left or right
ledPattern = ((ledPattern << shiftAmount) | (ledPattern >> (7 - shiftAmount))) & 0xFE;

// Update the LED states based on the shifted pattern
LED1 = (ledPattern & 0x01);
LED2 = (ledPattern & 0x02) >> 1;
LED3 = (ledPattern & 0x04) >> 2;
LED4 = (ledPattern & 0x08) >> 3;
LED5 = (ledPattern & 0x10) >> 4;
LED6 = (ledPattern & 0x20) >> 5;
LED7 = (ledPattern & 0x40) >> 6;
}

void __attribute__((interrupt, auto_psv)) _T1Interrupt(void)
{
// Clear the Timer1 interrupt flag
IFS0bits.T1IF = 0;

// Toggle the RUN LED
toggle_RUN_LED();

// Check the state of the switch
if (SWITCH == 0)
{
// Switch is open, continue Left to Right Knight Rider pattern
knight_rider_pattern();
}
else
{
// Switch is closed, reverse direction for Right to Left Knight Rider pattern
knight_rider_pattern();
knight_rider_pattern();
}
}

int main()
{
init();

// Infinite loop
while (1)
{
// Do nothing here, the pattern and RUN LED will be controlled by interrupts
}

return 0;
}
```

Please note that this code assumes you are using the Microchip XC16 compiler and that the Explorer 16 development board uses a Microcontroller with Timer 1 module capable of generating a 3.5-second interval. The LED pins (D10, D9-D3) and the switch pin (D7) are also assumed to be connected correctly to the Microcontroller. Adjust the code as needed to match your particular setup.