#include #define RED_LED 0x00000400 //set p0.10 as RED LED #define SW3 0x00100000 //set p0.20 as SW3 int main(void) { long tmp; // variable for temporary storage of port 0 status int flag; IO0DIR = RED_LED; // set p0.10 as output tmp = IO0PIN & SW3; // read SW3 (p0.20) while(1) { while(tmp==0) tmp = IO0PIN & SW3; // wait SW3 (p0.20) change to high while(tmp!=0) tmp = IO0PIN & SW3; // wait SW3 (p0.20) change to low if(flag==0) { flag = 1; IO0SET = RED_LED; } else { flag = 0; IO0CLR = RED_LED; } } }