In this project, you are going to add a RUN led to the embedded system that you have designed and developed in project 1. RUN Led is used to indicate continuous running of an electronic system, in general.

Hardware:
Implement the design on Explorer 16 as Project 1. LED D10 will be used as the RUN LED indicator.
Application:
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.

1 answer

Here is an example code in C that fulfills the requirements of the project:

```c
#include <xc.h>

// Configurations
#pragma config FNOSC = PRIPLL // Oscillator Selection
#pragma config POSCMOD = HS // Primary Oscillator Mode
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
#pragma config FPLLODIV = DIV_1 // PLL Output Divider
#pragma config FPBDIV = DIV_8 // Peripheral Bus Clock Divider
#pragma config FWDTEN = OFF // Watchdog Timer
#pragma config JTAGEN = OFF // JTAG Enable

// Function declarations
void initTimer();
void initIO();
void toggleLED();

// Global variables
unsigned int direction = 0; // 0: Left to Right, 1: Right to Left

int main() {
initTimer();
initIO();

while (1) {
// Toggle the RUN LED
toggleLED();

// Toggle the Knight Rider pattern
if (direction == 0) {
LATD <<= 1; // Shift LEDs from Left to Right
if (LATD == 0x08) {
direction = 1; // Switch direction to Right to Left
}
} else {
LATD >>= 1; // Shift LEDs from Right to Left
if (LATD == 0x01) {
direction = 0; // Switch direction to Left to Right
}
}

// Delay for 3.5 seconds
for (unsigned int i = 0; i < 50000; i++) {
for (unsigned int j = 0; j < 7000; j++);
}
}

return 0;
}

void initTimer() {
T1CON = 0x8000; // Enable Timer1, 1:1 prescaler
TMR1 = 0x0000; // Clear Timer1 register
PR1 = 45875; // Set period for 3.5 seconds
IEC0 |= 0x0002; // Enable Timer1 interrupt
IPC1 |= 0x1000; // Set Timer1 interrupt priority to 4
}

void initIO() {
TRISD = 0xFF00; // RD7-RD0 as input, RD15-RD8 as output
ODCD = 0x0000; // Normal output
LATD = 0x0000; // Clear output
TRISF &= 0xFFFE; // RF0 as output (RUN LED)
LATFbits.LATF0 = 1; // Set RUN LED initially
}

void toggleLED() {
LATFbits.LATF0 = !LATFbits.LATF0; // Toggle RUN LED
}

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

Please note that this code assumes you are using the Explorer 16 development board with a compatible microcontroller. You may need to modify the code according to your specific hardware and microcontroller. Also, make sure to configure the oscillator settings and include the necessary header files before using this code.
Similar Questions
  1. Project#2: RUN Led.In this project, you are going to add a RUN led to the embedded system that you have designed and developed
    1. answers icon 1 answer
    1. answers icon 1 answer
  2. Course: Embedded Systems ApplicationsDescription: This course emphasizes a systems approach to real time embedded systems.
    1. answers icon 13 answers
  3. Write a small parapgraph of objective for the following:This is an RTOS based application. That is developing an embedded
    1. answers icon 3 answers
more similar questions