objective:
(a) Flash the LED at a rate of one hertz.
(b) Each time SW1 is pressed, change the color of the LED in the following order: (Red->Blue->Green repeat)
I am attaching my code that is not showing an error and compiling without errors but there is no output, just the red light stays on.
//∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Included Files ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗// //∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Mapping Registers ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗//
#define SYSCTL_RCGC2 (*(( volatile unsigned long *)0x400FE108))
///∗∗∗∗ Port F ∗∗∗∗/
#define GPIO_PORTF_DATA (*(( volatile unsigned long *)0x400253FC))
#define GPIO_PORTF_DIR (*(( volatile unsigned long *)0x40025400))
#define GPIO_PORTF_AFSEL (*(( volatile unsigned long *)0x40025420))
#define GPIO_PORTF_DEN (*(( volatile unsigned long *)0x4002551C))
#define GPIO_PORTF_PUR (*(( volatile unsigned long *)0x40025510)) // p.677
void init_gpio (void );
// TODO: Add any necessary function declarations
//∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Global Variables ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗//
//∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Main ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗//
void delay(void)
{
int k;
for (k=1; k<=8000000; k++)
{}
}
int main (void)
{
init_gpio ();
GPIO_PORTF_DIR |= 0x02;
GPIO_PORTF_DIR |= 0x04;
GPIO_PORTF_DIR |= 0x08;
GPIO_PORTF_DIR &= ~0x1;
GPIO_PORTF_PUR |= 0x10;
GPIO_PORTF_AFSEL |= 0x00;
GPIO_PORTF_DEN |= 0x1E;
int i=1;
while (1) {
int pressed = !(GPIO_PORTF_DATA & 0x10);
if (i==1)
{
while (pressed!=1)
{
GPIO_PORTF_DATA |= 0x02;
delay();
GPIO_PORTF_DATA &= ~0x02;
}
}
else if (i==2)
{
while (pressed!=1)
{
GPIO_PORTF_DATA |= 0x04;
delay();
GPIO_PORTF_DATA &= ~0x04;
}
}
else if (i==3)
{
while (pressed!=1)
{
GPIO_PORTF_DATA |= 0x08;
delay();
GPIO_PORTF_DATA &= ~0x08;
}
}
else
{
i=0;
}
}
}
//∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Function Definitions ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗//
void init_gpio (void)
{
volatile unsigned long delay_clk ; // Enable Clock Gating for PortF, p.340
SYSCTL_RCGC2 |= 0x00000020;// Wait a few clock cycles
delay_clk = SYSCTL_RCGC2; // See p.227 for more information .
// TODO: Add GPIO Initializations
}
User contributions licensed under CC BY-SA 3.0