; led_sw3.s :Testing GPIO_0 for input/output to be run on the LPC2131 board ;(ver. 2012 onward) ; ;Exercise1 : run this program, you should see: ; When you press the button (sw3), the LED(D1) is on, otherwise LED(D1) is off. ; Try to understand the function of every statement of this program ; ;Exercise2: Modified the program so your output is reversed: ; When you press the button (sw3), the LED(D1) is off, otherwise LED(D1) is on. ; ;Exercise3: Modified the program, so you you can use sw4 (P0.11) to control LED D2 (P0.21) ; as in exercise 1. ;Exercise4: Modified the program, so when you press sw3 once , ; the LED(D1) will toggle (change state from on_to_off or off_to_on) ; ; Note: LED(D1) is at GPIO P0.10, sw3 is at GPIO P0.20 (also for EINT3 external interrupt input) ; 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 AREA |.data|, DATA, READWRITE IO0DIR EQU 0xE0028008 ; pin direction IO0SET EQU 0xE0028004 ; pin value set IO0CLR EQU 0xE002800C ; pin value clear IO0PIN EQU 0xE0028000 ; pin value read & write RED_LED EQU 0x00000400; 0100,0000,0000B p0.10=RED LED SW3 EQU 0x00100000; 0001,0000,0000,0000,0000,0000B,p0.20 is SW3 AREA |.text|, CODE, READONLY; User Initial Stack & Heap EXPORT __main __main ; set p0.22(red led) as output using the IO0DIR register LDR R1, =RED_LED LDR R0, =IO0DIR STR R1,[R0]; loop LDR R3, =IO0PIN; target at the IO0PIN register LDR R3, [R3]; load IO0PIN value to R3 register ; if the switch is depressed, corresponding pin value is 0 TST R3, #SW3;test on pin 20 of IO0PIN to see if SW3 is depressed BEQ onled ;if IO0PIN[20]=0, go to onled to light the led ;otherwise LEDoff offled LDR R1, =RED_LED LDR R0, =IO0CLR STR R1,[R0] B loop ;------ON LED--------- ; write 1 in the 22nd bits of IO0SET to turn on the LED onled LDR R1, =RED_LED LDR R0, =IO0SET STR R1,[R0] B loop END