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

Show the circuit diagram to interface a switch to PA6 and an LED to PC3. Write s

ID: 3737884 • Letter: S

Question

Show the circuit diagram to interface a switch to PA6 and an LED to PC3. Write software that initializes the ports. In the body of the main program, toggle the LED on and off if the switch is pressed, and turn the LED off if the switch is not pressed

Systick Cortex M4 Svstem Bus Interface NVIC GPIO Port A GPIO Port B PA7 PA6 PA5/SSIOTx PA4/SSIORx PA3/SSIOFss PA2SS?OC?k PA1/UOTx PAO/UORx PB7 PB6 PB5 PB4 PB3/12COSDA PB2/12COSCL PBl PB0 Four UARTs Four CAN 2.0 SSIs GPIO Port C GPIO Port D PC7 PC6 PC5 PC4 PC3/TDO/SWO PC2/TDI PC1/TMS/SWDIO PCO/TCK/SWCLK PD7 PD6 PD5 PD4 PD3 PD2 PDI PDO Twelve Timers USB 2.0 Six 64-bit wide GPIO Port E GPIO Port F PE5 PE4 ??? PE2 PEI PEO Two Analog Comparators ADC 2 channels 12 inputs 12 bits PF4 PF3 PF2 PFI PF0 Two PWM Modules Advance Performance Bus Ad er uS

Explanation / Answer

#define PA6 (*((volatile unsigned long *)0x40004080))

void Switch_Init(void){ volatile unsigned long delay;

SYSCTL_RCGC2_R |= 0x00000001; // 1) activate clock for Port A

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

// 2) no need to unlock GPIO Port A

GPIO_PORTA_AMSEL_R &= ~0x20; // 3) disable analog on PA6

GPIO_PORTA_PCTL_R &= ~0x00F00000; // 4) PCTL GPIO on PA6

GPIO_PORTA_DIR_R &= ~0x20; // 5) direction PA6 input

GPIO_PORTA_AFSEL_R &= ~0x20; // 6) PA6 regular port function

GPIO_PORTA_DEN_R |= 0x20; // 7) enable PA6 digital port

}

unsigned long Switch_Input(void){

return PA6; // return 0x20(pressed) or 0(not pressed)

}

unsigned long Switch_Input2(void){

return (GPIO_PORTA_DATA_R&0x20); // 0x20(pressed) or 0(not pressed)

}

It includes an initialization, which is called once, and a second function that can be called to read the current position of the switch. Writing software this way is called an abstraction, because it separates what the switch does (Init, On, Off) from how it works . The first input function uses the bit-specific address to get just PA6, while the second reads the entire port and selects bit 6 using a logical AND.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote