You are on page 1of 3

#include <LPC214x.

H>

/* LPC21xx definitions */

//void wait (void)


//{
/* wait function */
//int d;
//
//for (d = 0; d < 2000000; d++);
/* only to delay for LED flashes */
//}
#define SWITCH1 (1 << 24)
#define SWITCH2 (1 << 23)
#define LED1 (1 << 13)
#define LED2 (1 << 12)
#define SWITCH_MASK (SWITCH1 | SWITCH2 )
#define LED_MASK (LED1 | LED2)
#define
#define
#define
#define

SW_IO_DIR IODIR0
//to feed input
LED_IO_DIR IODIR1 //to show output
INIT_SWITCHES() (IODIR0 &= ~((1 << 24)|(1 << 23)))//set as input
INIT_LEDS()
(IODIR1 |= ((1 << 13)|(1 << 12))) //set as output

#define LED_SET IOSET //high voltage-3.3v


#define LED_CLR IOCLR //low voltage
#define SW_IO_PIN IOPIN1//to get the current status
#define LED_NUM1 8
#define LED_NUM2 7
void turn_on_led(unsigned char led_num)
{
switch(led_num)
{
case LED_NUM1:
IOSET0 |= LED1;
break;
case LED_NUM2:
IOSET0 |= LED2;
break;
default:
break;
}
}
/**
*****************************************************************************
Function Name : turn_off_led()
Description

Input

: Void

Output

: None

Note
:
******************************************************************************
*/

void turn_off_led(unsigned char led_num)


{
switch(led_num)
{
case LED_NUM1:
IOCLR0|= LED1;
break;
case LED_NUM2:
IOCLR0 |= LED2;
break;
default:
break;
}
}
/**
*****************************************************************************
Function Name : turn_off_all_leds()
Description

Input

: Void

Output

: None

Note
:
******************************************************************************
*/
/*void turn_off_all_leds()
{
IOCLR0 |= LED_MASK;
} */
/**
*****************************************************************************
Function Name : turn_off_all_leds()
Description

Input

: Void

Output

: None

Note
:
******************************************************************************
*/
/*void turn_on_all_leds()
{
LED_SET |= LED_MASK;
} */
int main (void) {
unsigned int sw_mask;
unsigned int index;
INIT_LEDS();
INIT_SWITCHES();

/* LED var */
// configure the gpio's connected by LEDs.
// configure the gpio's connected by Switches.

while (1) {
sw_mask = SW_IO_PIN & SWITCH_MASK;
for(index = 0; index < 3; index++)
{
if(sw_mask & (1 << (index + 17)))
{
turn_on_led(index + 1);
corresponds to specific LED is ON.
}
else
{
turn_off_led(index + 1);
h corresponds to specific LED is OFF.
}
}
//
wait();
}
}

// Read switches
//check the status of switches
// Turn on the LED if a switch

// Turn off the LED if a switc

You might also like