In: Computer Science
**Keil uVision5 - ARM Cortex M0+ - Embedded C programming
Modify the program below so that the Red, Green, and Blue LEDs are switched ON and OFF in a sequence with one second delay for Red and Green LEDs, and 0.5 second delay for the Blue LED.
#include "MKL25Z4.h" void delay(int n); int main (void) { SIM_SCGC5 |= SIM_SCGC5_PORTB(1); /* enable clock to Port B */ PORTB_PCR18 |=PORT_PCR_MUX(1); /* Configure PORTB ,pin 18 as GPIO ; set MUX*/ GPIOB_PDDR=(1UL << 18); /* make PORTB ,pin 18 as output pin */ while (1) { GPIOB_PCOR = (1UL << 18); /* turn ON Red LED for one sec */ delay(10); GPIOB_PSOR = (1UL << 18); /* turn OFF Red LED for one sec*/ delay(10); } } /* Delay function for 100 ms */ void delay(int n) { int i,j; for(i = 0 ; i < n; i++) for (j = 0; j < 349500; j++) {} }
#include "MKL25Z4.h
void delay(int n);
int main (void) {
SIM_SCGC5 = SIM_SCGC5_PORTB(1);
PORTB_PCR18 =PORT_PCR_MUX(1);
GPIOB_PDDR=(1UL << 18);
while (1) {{
GPIOB_PCOR = (1UL << 18);
delay(10);
GPIOB_PSOR = (1UL << 18);
delay(10);
}
{
GPIOB_PCOG = (1UL << 18);
delay(10);
GPIOB_PSOG = (1UL << 18);
delay(10);
}
{
GPIOB_PCOB = (1UL << 18);
delay(5);
GPIOB_PSOB = (1UL << 18);
delay(5);
}
}
}
void delay(int n) {
int i,j;
for(i = 0 ; i < n; i++)
for (j = 0; j < 60; j++)
{delay(60);
return;
}
}