I am facing an issue in getting 2 LEDs glow one after another or at the same time. However, they work separately only one at a time. The problem comes when I try to achieve this in the same program. Only the first LED starts filckering not the other one. Following is my code:
#define GPFSEL1 0x20200004
#define GPFSEL2 0x20200008
#define GPSET0 0x2020001C
#define GPCLR0 0x20200028
#define SET_PIN18_OUTPUT (0x01 << 24) // GPFSEL1
#define SET_PIN23_OUTPUT (0x01 << 9) // GPFSEL2
#define SET_PIN24_OUTPUT (0x01 << 12) // GPFSEL2
#define SET_GPION(x) (0x01 << x)
#define CLEAR_GPION(x) (0x01 << x)
#define NUM_OF_LEDS 3
//-------------------------------------------------------------------------
typedef unsigned int* UINT32_P;
void dummy(volatile unsigned int val)
{
val++;
}
void setBit(unsigned int regAdd, unsigned char bit)
{
unsigned int temp;
temp = *(UINT32_P)(regAdd);
temp |= (0x1 << bit);
*(UINT32_P)(regAdd) = temp;
}
void clearBit(unsigned int regAdd, unsigned char bit)
{
unsigned int temp;
temp = *(UINT32_P)(regAdd);
temp &= ~(1 << bit);
*(UINT32_P)(regAdd) = temp;
}
int notmain ( void )
{
unsigned int ra;
setBit(GPFSEL1, 24); // Configure PIN 18 to output
setBit(GPFSEL2, 12); // Configure PIN 24 to output
while(1)
{
// L1 - -
setBit(GPSET0, 18);
setBit(GPSET0, 24);
for(ra=0;ra<0x100000;ra++) dummy(ra);
// - L2 -
setBit(GPCLR0, 18);
setBit(GPCLR0, 24);
for(ra=0;ra<0x100000;ra++) dummy(ra);
for(ra=0;ra<0x100000;ra++) dummy(ra);
}
return(0);
}