Write an application (in C) which implement the sequence on Explorer 16 board 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.

3 answers

Here's a possible implementation of the requested application:

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

#pragma config FNOSC = PRIPLL
#pragma config POSCMOD = HS
#pragma config FPLLMUL = MUL_20
#pragma config FPLLIDIV = DIV_2
#pragma config FPBDIV = DIV_8
#pragma config FPLLODIV = DIV_1

#define _XTAL_FREQ 8000000

void setup()
{
TRISD = 0x00; // Set all PORTD pins as outputs
LATD = 0x00; // Initially turn off all LEDs
}

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

void turnOnLed(int led)
{
LATD |= (1 << led); // Turn on the specified LED
}

void turnOffLed(int led)
{
LATD &= ~(1 << led); // Turn off the specified LED
}

int main(void)
{
setup();

while (true) {
// Sequence from right to left
for (int i = 0; i < 8; i++) {
turnOnLed(i);
delay(500);
turnOffLed(i);
}

// Sequence from left to right
for (int i = 7; i >= 0; i--) {
turnOnLed(i);
delay(500);
turnOffLed(i);
}
}

return 0;
}
```

This implementation assumes that you're using the XC16 compiler and MPLAB X IDE for programming the Explorer 16 board. The `setup` function initializes the necessary configurations, such as setting the PORTD pins as outputs and turning off all LEDs. The `delay` function introduces a delay in milliseconds using the built-in `__delay_ms` function. The `turnOnLed` and `turnOffLed` functions are used to manipulate the states of individual LEDs.

The `main` function follows the requested sequence by repeatedly turning on and off each LED from right to left and then from left to right. The LEDs are turned on for 500 milliseconds each before moving on to the next LED.

Note that the `#pragma` directives set the configuration bits for the PIC24F microcontroller used in the Explorer 16 board. Adjust these directives according to your specific requirements and microcontroller model if necessary.
Can you write the code under Main code and Delay code?
Certainly! Here's the updated code with the main code and delay code separated:

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

#pragma config FNOSC = PRIPLL
#pragma config POSCMOD = HS
#pragma config FPLLMUL = MUL_20
#pragma config FPLLIDIV = DIV_2
#pragma config FPBDIV = DIV_8
#pragma config FPLLODIV = DIV_1

#define _XTAL_FREQ 8000000

void setup()
{
TRISD = 0x00; // Set all PORTD pins as outputs
LATD = 0x00; // Initially turn off all LEDs
}

void turnOnLed(int led)
{
LATD |= (1 << led); // Turn on the specified LED
}

void turnOffLed(int led)
{
LATD &= ~(1 << led); // Turn off the specified LED
}

int main(void)
{
setup();

while (true) {
// Sequence from right to left
for (int i = 0; i < 8; i++) {
turnOnLed(i);
__delay_ms(500);
turnOffLed(i);
}

// Sequence from left to right
for (int i = 7; i >= 0; i--) {
turnOnLed(i);
__delay_ms(500);
turnOffLed(i);
}
}

return 0;
}
```

In this version, the delay code is replaced with the `__delay_ms` function, which is a built-in function provided by the XC16 compiler for introducing a delay. The `__delay_ms` function takes the desired delay in milliseconds as an argument.
Similar Questions
  1. 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.
    1. answers icon 3 answers
    1. answers icon 7 answers
  2. Hardware:Implement the design on Explorer 16 as Project 1. LED D10 will be used as the RUN LED indicator. Application: Write an
    1. answers icon 1 answer
  3. Critical Observation/Thinking (One paragraph) of the following:Implement the design on Explorer 16 as Project 1. LED D10 will be
    1. answers icon 1 answer
more similar questions