Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following piece of code which is for the initialization of switiches and leds: Please explain each line of code by adding comments next to

  1. The following piece of code which is for the initialization of switiches and leds:
  • Please explain each line of code by adding comments next to it.

Ex: void Switch_Init() // function initialization for switches

  • Mention which ports and corresponding bits are being used for switches and leds respectively. (Please observe the DIR registers carefully)

Ex: PortD bit 0 (PD0) for Led0.

Void Switch_Init()

{

volatile unsigned long loop1;

SYSCTL_RCGC2_R|=SYSCTL_RCGC2_GPIOG;

loop1=SYSCTL_RCGC2_R;

GPIO_PORTG_DIR_R &=~0x78;

GPIO_PORTG_AFSEL_R &=0x00;

GPIO_PORTG_DEN_R |=0x78;

GPIO_PORTG_PUR_R |=0x78;

}

Void Led_Init()

{

volatile unsigned long loop2;

SYSCTL_RCGC2_R|=SYSCTL_RCGC2_GPIOD;

Loop2=SYSCTL_RCGC2_R;

GPIO_PORTD_DIR_R |=0x0F;

GPIO_PORTG_AFSEL_R &=0x00;

GPIO_PORTD_DEN_R |=0x0F;

}

int main()

{

Switch_Init();

Led_Init();

//

//Do stuff

//

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions