Question

Write C code that initializes TM4C Port A, so pins 5, 4 and 3 are output....

Write C code that initializes TM4C Port A, so pins 5, 4 and 3 are output. Comment your code to explain each initialization step clearly. Make the initialization friendly.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ans.................................................

reruired code in c:

Note:

here we take a function that takes a 3-bit parameters from 0 to 7

..................................................................................


#define GPIO_PORTE_DATA_R (((volatile unsigned long )0x40024000))
#define GPIO_PORTE_DIR_R (((volatile unsigned long )0x40024400))
#define GPIO_PORTE_AFSEL_R (((volatile unsigned long )0x40024420))
#define GPIO_PORTE_PUR_R (((volatile unsigned long )0x40024510))
#define GPIO_PORTE_DEN_R (((volatile unsigned long )0x4002451C))
#define GPIO_PORTE_CR_R (((volatile unsigned long )0x40024524))
#define GPIO_PORTE_AMSEL_R (((volatile unsigned long )0x40024528))
#define GPIO_PORTE_PCTL_R (((volatile unsigned long )0x4002452C))
#define SYSCTL_RCGC2_R (((volatile unsigned long )0x400FE108))

// 2. Declarations Section
// Global Variables
unsigned long sw; // input from PF4
unsigned long Out; // outputs to PF3,PF2,PF1 (multicolor LED)

// Function Prototypes
void PortE_Init(void);
void Delay(void);


int main(void){   
PortE_Init(); // Call initialization of port E
while(1){
sw = GPIO_PORTE_DATA_R&0x08; // read PE4 into sw
if(sw == 0x00){ // if switch is pressed
GPIO_PORTE_DATA_R = 0x02; // LED is green
} else{   
GPIO_PORTE_DATA_R = 0x04; // LED is red
}
Delay(); // wait 0.1 sec
GPIO_PORTE_DATA_R = 0x01; // LED is blue
Delay(); // wait 0.1 sec
}
}

// Subroutine to initialize port E pins for input and output
// PE3 is an input from a switch SW
// PE2, PE1, PE0 are outputs to the LED

void PortE_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000010; // 1) E clock
delay = SYSCTL_RCGC2_R; // delay
GPIO_PORTE_CR_R = 0x2F; // allow changes to PE5,3-0
GPIO_PORTE_AMSEL_R = 0x00; // 3) disable analog function
GPIO_PORTE_PCTL_R = 0x00000000; // 4) GPIO clear bit PCTL
GPIO_PORTE_DIR_R |= 0x08; // 5) PE3 input
GPIO_PORTE_DIR_R &=~ 0x07; // 5) PE2,PE1,PE0 output
GPIO_PORTE_AFSEL_R = 0x00; // 6) no alternate function
GPIO_PORTE_PUR_R = 0x08; // enable pullup resistors on PE3
GPIO_PORTE_DEN_R = 0x0F; // 7) enable digital pins PE3-PE0   
}


// Subroutine to wait 0.1 sec

void Delay(void){unsigned long volatile time;
time = 727240*200/91; // 0.1sec
while(time){
time--;
}
}

Add a comment
Know the answer?
Add Answer to:
Write C code that initializes TM4C Port A, so pins 5, 4 and 3 are output....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT