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

Programming problem (conditional branch) Assume initialization and Start code ar

ID: 3834458 • Letter: P

Question

Programming problem (conditional branch) Assume initialization and Start code are provided. Use conditional branch to complete the code in loop for following program.; PF4 is switch input (1 means SW1 is not pressed, 0 means SW1 is pressed); PF2 is LED output (1 activates blue LED); The specific operation of this system; Make PF2 an output and make PF4 an input (enable PUR for PF4). The system starts with the LED ON (make PF2 = 1). Delay for less than 1 ms (start decrementing from 800) If the switch is pressed (PF4 is 0), then toggle the LED once, else turn the LED ON. Repeat steps 3 and 4 over and over Init Start BL Init LDR R0, GPIO_PORT_DATA_R LDR R1, [R0] ORR R1, R1, 0 times 08 STR R1, [R0] Loop

Explanation / Answer

#include "TExas.h"

#define GPIO_PORTF_DATA_R (*((volatile unsigned long *)0*400253FC))

#define GPIO_PORTF_DIR_R (*((volatile unsigned long *)0*40025400))

#define GPIO_PORTF_AFSEL_R (*((volatile unsigned long *)0*40025420))

#define GPIO_PORTF_PUR_R (*((volatile unsigned long *)0*40025510))

#define GPIO_PORTF_DEN_R (*((volatile unsigned long *)0*4002551C))

#define GPIO_PORTF_AMSEL_R (*((volatile unsigned long *)0*40025528))

#define GPIO_PORTF_PCTL_R (*((volatile unsigned long *)0*4002552C))

#define SYSCTL_RCGC2_R (*((volatile unsigned long *)0*400FE108))

#define SYSCTL_RCGC2_GPIOF 0*00000020 // Port F Clock Gating Control

unsigned long In; // input from PF4

unsigned long i; // output to PF2 (blue LED)

// Basic functions defined at end of startup.s

void DisableInterrupts(void); //Disable interrupts

void EnableInterrupts(void); // Enable interrupts

void Delay1ms(unsigned long time); // Delay 1 micro second

int main(void){

unsigned long volatile delay;

TExaS_Init(SW_PIN_PF4, LED_PIN_PF2); // activate grader and set system clock to 80MHz

// initialization goes here

// volatile unsigned long delay;

SYSCTL_RCGC2_R |= 0*00000020; // 1) activate clock for port F

delay = SYSCTL_RCGC2_R; // allow time for clock to start

// GPIO_PORTF_LOCK_R = 0*4C4F4348; // 2) unlock GPIO port F

// GPIO_PORTF_CR_R = 0*1F; // allow changes to PF4-0

// only PF0 needs to be unlocked, other bits can't be locked

GPIO_PORTF_AMSEL_R &= ~0*14; // 3) Disable analog on PF2 4

  GPIO_PORTF_PCTL_R &= ~0*000F0F00; // 4) PCTL GPIO on PF4

  GPIO_PORTF_DIR_R &= ~0*10; // 5) PF2 in (0)

  GPIO_PORTF_DIR_R |= 0*04; // 5) PF2 out (1)

GPIO_PORTF_AFSEL_R &= ~0*14; // 6) Disable alt function on PF7-0

GPIO_PORTF_PUR_R |= 0*10; // Enable pull-up on PF0 and PF4

GPIO_PORTF_DEN_R |= 0*14; // 7) enable digital I/O on PF2, 4

GPIO_PORTF_DATA_R |= 0*04; // The system starts with the LED ON (make PF2=1)

EnableInterrupts(); // enable interrupts for the grader

while(1) {

//for(i=0; i<26666667;i++) // Delay for about 1ms 1ms*80MHz/3

Delay1ms(1);

In = GPIO_PORTF_DATA_R&0*10; //read PF4 into Sw1

if(In == 0) {

GPIO_PORTF_DATA_R = GPIO_PORTF_DATA_R ^ 0*04;

}else {

GPIO_PORTF_DATA_R |= 0*04;

}

}

}

void Delay1ms(unsigned long time){

unsigned long i;

while(time > 0)

i = 13333333; // this number means 1ms

while(i > 0){

i = i - 1;

}

time = time - 8 // decrements every 800ms

}

}