//-------------------------------------------------------------- //led_sw1.c ( version 2013 b) //exercise: Modied this program so it can run on your new lopc2131 board using the // Input:sw3, output :LED (D1) // //; Note: LED(D1) is at GPIO P0.10, sw3 is at GPIO P0.20(for EINT3 //ext.interrupt) //; Note: LED(D2) is at GPIO P0.11, sw4 is at GPIO P0.21 //; Note: LED(D3) is at GPIO P0.12, sw5 is at GPIO P0.22 //; Note: LED(D4) is at GPIO P0.13, sw6 is at GPIO P0.23 //-------------------------------------------------------------- #include //define IO0PIN ,IO0DIR.. Etc // see http://www.keil.com/dd/docs/arm/philips/lpc21xx.h #define RED_LED 0x00400000 //set p0.22 as RED LED #define SW1 0x00100000 //set p0.20 as SW1 int main(void) { long tmp; // variable for temp storage of port 0 status IO0DIR = RED_LED; // set p0.22 as output while(1) { tmp =IO0PIN & SW1;//read SW1(p0.20)depressed=0 if(tmp==0) // What happens “if (tmp!=0)” is used? IO0SET = RED_LED; //if SW1 pressed LED is on else IO0CLR = RED_LED; // otherwise off the LED } }