Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

- Rewrite the software below so the LED pattern changes every 0.1 sec. #define L

ID: 2084410 • Letter: #

Question

-          Rewrite the software below so the LED pattern changes every 0.1 sec.

#define LEDS (*((volatile unsigned long *)0x4000703C))

int main(void) { volatile unsigned long delay;

SYSCTL_RCGC_R I= SYSCTL_GPIOD;               // activate Port D

delay = SYSCTL_RCGC_R;                                     // allow time for clock to stabilize

GPIO_PORTD_DIR_R = 0x0F;                                // make PD3-0 out

GPIO_PORTD_AFSEL_R &= ~0x0F;                      // regular port function

GPIO_PORTD_DEN_R I= 0x0F;                              // enable digital I/O on PD3-0

            while(1) {

                        LEDS = 10;     // 1010, LED is 0101

                        LEDS = 9;       // 1001, LED is 0110

                        LEDS = 5;       // 0101, LED is 1010

                        LEDS = 6;       // 0110, LED is 1001

            }

}

Flowchart 1 Start Initialize Port Output Sequence Flowchart 2 Flowchart 3 Start main Direction to DIR 0x0F Output Port D 1010 Output Port D 1001 Output Output Port D 0110

Explanation / Answer

CODE:

================================================

#define LEDS (*((volatile unsigned long *)0x4000703C))

void delayMillis(int millisec) {
ROM_SysCtlDelay( (ROM_SysCtlClockGet()/(3*1000))*millisec) ;

/* using ROM_SysCtlDelay()&ROM_SysCtlClockGet() rather simply SysCtlDelay()for better accuracy in delay generation. */


}

int main(void) {

volatile unsigned long delay;

SYSCTL_RCGC_R I= SYSCTL_GPIOD;               // activate Port D

delay = SYSCTL_RCGC_R;                                     // allow time for clock to stabilize

GPIO_PORTD_DIR_R = 0x0F;                                // make PD3-0 out

GPIO_PORTD_AFSEL_R &= ~0x0F;                      // regular port function

GPIO_PORTD_DEN_R I= 0x0F;                              // enable digital I/O on PD3-0

            while(1) {

                        LEDS = 10;     // 1010, LED is 0101

delayMillis(100); // creates a delay of 100ms or 0.1s

                        LEDS = 9;       // 1001, LED is 0110

delayMillis(100);

                        LEDS = 5;       // 0101, LED is 1010

delayMillis(100);

                        LEDS = 6;       // 0110, LED is 1001

  delayMillis(100);

            }

}

============================