#include <LPC21xx.h>
#define led (1<<22)
#define sw (1<<8)
int main (void)
{ PINSEL0=sw;
IODIR0=0xFFFFFFF; if (sw == 1)
IOSET0 = (1<<22);
else
IOCLR0 = (1<<22);
}
- - - Updated - - -
whats wrong with this code???
Code:
#include <LPC21xx.h>
#define led (1<<22) // Led is bit 22
#define sw (1<<8) // Switch is bit 8
int main (void)
{
IODIR0 &= ~sw; // Set as inputs
IODIR0 |= led; // Set as outputs
while(1)
{
if (IOPIN0 & sw) // Check switch state, reflect to led
IOSET0 = led;
else
IOCLR0 = led;
}
}
#include <LPC21xx.h>
#define led (1<<22) // Led is bit 22
#define sw (1<<8) // Switch is bit 8
int main (void)
{
IODIR0 &= ~sw; // Set as inputs
IODIR0 |= led; // Set as outputs
while(1)
{
if (IOPIN0 & sw) // Check switch state, reflect to led
IOSET0 = led;
else
IOCLR0 = led;
}
}