Question: 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
- 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
Get step-by-step solutions from verified subject matter experts
