Part A:

Write an application (in C) on the Explorer 16 board which implement the sequence as below:
1. Make all the LEDs OFF.
2. Make LED D3 (Right most) to be ON .
3. After a while (a delay of your choice), make next (to the Left) LED to be ON.
4. After a while, make the next LED to be ON. Repeat this process until all the 8 LEDs (from Right most to LEFT most) becomes ON.
5. Repeat the above processes (1-4), this time, starting from LEFT most LED and walk to the RIGHT most.
6. Repeat the above sequence (1-5) infinitely.

Part B:
Utilize SW3 of the explorer 16 board to change the direction of the Knight Rider Pattern designed in Part A. Any time, if SW3 is pushed down and hold, the above pattern starts from LEFT to RIGHT and when SW3 is released, the pattern walks from RIGHT to LEFT (as in Part A).

Here is an example implementation in C for the Explorer 16 board:

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

#define LEDS_MASK 0xFF00
#define SW3_MASK 0x0100

void delay() {
int i;
for(i = 0; i < 50000; i++) {
// Delay loop
}
}

void init() {
// Configure LATD as output for LEDs
TRISD = 0;
// Configure TRISB15 as input for SW3
TRISB |= 0x8000;
}

int main(void) {
init();

int direction = 1; // 1 for right to left, -1 for left to right
int led = 1; // Mask for current LED

while(1) {
LATD = LEDS_MASK & led; // Turn on only the selected LED

if((PORTB & SW3_MASK) == 0) {
// SW3 is pressed, change direction
direction = -direction;
delay(); // Debounce delay
}

delay(); // Wait for some time

LATD = 0; // Turn off all LEDs
led = led << direction; // Shift the LED mask in the selected direction

if(direction == -1 && led == 0x0100) {
// Reaching leftmost LED, change direction
direction = 1;
} else if(direction == 1 && led == 0x8000) {
// Reaching rightmost LED, change direction
direction = -1;
}
}

return 0;
}
```

Please note that the implementation assumes that the LEDs are connected to the D0-D7 pins of the board and the SW3 switch is connected to the B15 pin. The code sets up the necessary configurations, including using the `LATD` register to control the LED states and the `PORTB` register to read the state of the SW3 switch. The main loop goes through the steps described in Part A, toggling the LEDs one by one in the selected direction and handling the SW3 switch to change the direction if necessary.

is the code above for part A) or Part b)?

The code above is for Part A) of the requested functionality, where the LED sequence starts from the rightmost LED and walks to the leftmost LED, then repeats in an infinite loop.

To implement Part B) and utilize SW3 to change the direction of the sequence, you would need to modify the code as follows:

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

#define LEDS_MASK 0xFF00
#define SW3_MASK 0x0100

void delay() {
int i;
for(i = 0; i < 50000; i++) {
// Delay loop
}
}

void init() {
// Configure LATD as output for LEDs
TRISD = 0;
// Configure TRISB15 as input for SW3
TRISB |= 0x8000;
}

int main(void) {
init();

int direction = 1; // 1 for right to left, -1 for left to right
int led = 1; // Mask for current LED

while(1) {
LATD = LEDS_MASK & led; // Turn on only the selected LED

if((PORTB & SW3_MASK) == 0 && direction == 1) {
// SW3 is pressed and direction is right to left
direction = -direction;
delay(); // Debounce delay
}
else if((PORTB & SW3_MASK) != 0 && direction == -1) {
// SW3 is released and direction is left to right
direction = -direction;
delay(); // Debounce delay
}

delay(); // Wait for some time

LATD = 0; // Turn off all LEDs
led = led << direction; // Shift the LED mask in the selected direction

if(direction == -1 && led == 0x0100) {
// Reaching leftmost LED, change direction
direction = 1;
}
else if(direction == 1 && led == 0x8000) {
// Reaching rightmost LED, change direction
direction = -1;
}
}

return 0;
}
```

In this modified code, the SW3 switch is checked in two places: once to change the direction from right to left to left to right (when SW3 is pressed while the direction is right to left), and again to change the direction back from left to right to right to left (when SW3 is released while the direction is left to right). This change ensures that the LED sequence direction can be controlled by the SW3 switch as specified in Part B).

To write an application in C for the Explorer 16 board that implements the sequence described in Part A and also utilizes SW3 to change the direction of the pattern as described in Part B, you can follow these steps:

Part A:

1. Set up the necessary configuration for the Explorer 16 board and initialize the required peripherals, in this case, the LEDs and any necessary delay functions.

2. Create a loop that repeats infinitely to continuously perform the pattern:

3. Make all LEDs OFF by setting their corresponding pins to a logic high state.

4. Set LED D3 (Right most) to be ON by setting its corresponding pin to a logic low state.

5. After a delay of your choice, make the next (to the left) LED to be ON by setting its corresponding pin to a logic low state.

6. Repeat step 5 for each subsequent LED, moving from right to left.

7. Repeat the above steps 3-6, but this time starting from the left most LED and walking to the right most.

Part B:

8. Set up an interrupt service routine (ISR) for the SW3 button on the Explorer 16 board.

9. Create a flag variable (directionFlag) that is initially set to 0 to indicate the pattern starts from RIGHT to LEFT.

10. Inside the ISR, check if SW3 button is pushed down and held. If it is, toggle the directionFlag between 0 and 1 to indicate the change in pattern direction.

11. Modify the main loop in the Part A to check the value of the directionFlag before executing the pattern. If directionFlag is 0, execute the pattern as described in Part A. If directionFlag is 1, reverse the pattern direction by starting from the left most LED and walking to the right most.

12. Repeat the above steps 3-11 infinitely.

Please note that implementing the code and compiling it for the Explorer 16 board requires familiarity with the specific hardware and the development environment you might be using.

To implement the given sequence on the Explorer 16 board in C programming language, you can follow the steps below:

Part A:

1. Include necessary header files:

```
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
```

2. Define the configurations for the LEDs and the switch SW3:

```c
#define LED_PORT LATB // Port B
#define LED_MASK 0xFF // Mask for all 8 LEDs
#define SWITCH_PORT PORTGbits.RG6 // Port G, RG6 for SW3
#define SWITCH_TRIS TRISGbits.TRISG6 // TRISE for SW3
```

3. Initialize the LEDs and switch:

```c
void initLEDs()
{
LED_PORT = 0x00; // Make all LEDs OFF initially
TRISB = 0x00; // Set all PORTB pins as output
}

void initSwitch()
{
SWITCH_TRIS = 1; // Set SW3 as input
CNCONGbits.ON = 1; // Enable CN on port G
CNENGbits.CNIEG6 = 1; // Enable CN for RG6
IPC8bits.CNIP = 7; // Set priority level for CN interrupt
IEC1bits.CNGIE = 1; // Enable CN interrupts
IFS1bits.CNGIF = 0; // Clear CN interrupt flag
}
```

4. Implement the main function to create the desired pattern:

```c
int main(void)
{
initLEDs(); // Initialize the LEDs
initSwitch(); // Initialize the switch

bool rightToLeft = true; // Flag to track the direction of the pattern
uint8_t ledMask = 1; // Mask for current LED to be turned ON

while (1)
{
if (rightToLeft)
{
// Turn ON LEDs from right to left
for (int i = 0; i < 8; i++)
{
LED_PORT = LED_PORT | ledMask; // Turn ON current LED
ledMask = ledMask << 1; // Shift the mask to the left
__delay_ms(500); // Delay for a while
}

ledMask = ledMask >> 1; // Reset the ledMask for next iteration
}
else
{
// Turn ON LEDs from left to right
for (int i = 0; i < 8; i++)
{
LED_PORT = LED_PORT | ledMask; // Turn ON current LED
ledMask = ledMask >> 1; // Shift the mask to the right
__delay_ms(500); // Delay for a while
}

ledMask = ledMask << 1; // Reset the ledMask for next iteration
}

rightToLeft = !rightToLeft; // Toggle the direction of the pattern
}

return 0; // This line is not necessary as the microcontroller will run forever
}
```

Part B:

To utilize SW3 for changing the direction of the pattern, you need to modify the interrupt service routine to handle the PRESS and RELEASE events of SW3.

1. Update the interrupt service routine to handle the SW3 events:

```c
void __attribute__((__interrupt__, __auto_psv__)) _CNInterrupt(void)
{
IFS1bits.CNGIF = 0; // Clear CN interrupt flag

if (SWITCH_PORT == 0)
{
// SW3 is pressed down, change direction to LEFT to RIGHT
rightToLeft = false;
}
else
{
// SW3 is released, change direction to RIGHT to LEFT
rightToLeft = true;
}
}
```

2. Modify the `main` function to handle the changes in direction:

```c
int main(void)
{
// Same code as Part A, up to the while(1) loop

while (1)
{
if (rightToLeft)
{
// Same code as Part A, up to the first for loop
}
else
{
// Same code as Part A, up to the second for loop
}

// Same code as Part A, after the for loop

// Additional delay for better responsiveness to switch changes
__delay_ms(100);
}

// Same code as Part A, up to the return 0 statement
}
```

That's it! Compile and program the code onto your Explorer 16 board, and it should implement the desired Knight Rider pattern with the ability to change the direction using SW3.