; *********************************************************************** ; * * ; * Polling the Push-button Switches * ; * * ; *********************************************************************** ; Author: John Zaitseff ; Date: 28th May, 2003 ; Version: 1.2 ; This file contains the source code for pb-poll.elf. This program polls ; the push-button switches S2 and S3 on the Expansion Board and sets the ; left or right LEDs on if either switch is pressed. .include "header-v3.s" ; Include definitions needed for this program .text ; Executable code follows _start: .global _start ; "_start" is required by the linker .global main ; "main" is our main program b main ; Start running the main program ; ----------------------------------------------------------------------- ; The main program ; This very simple program polls the push-button switches S2 and S3. If ; S2 is being pressed, the left LEDs are turned on; if S3 is being ; pressed, the right LEDs are turned on. ; One slight optimisation: all register values are initialised at the ; start (the first three lines in "main"), so that continual loading and ; reloading of registers is not necessary. Note also that the Port B ; address is formed by adding "portB" (the offset 0x04) to the "iobase" ; address (in register R0). main: ; Entry to the function "main" ldr r0, =iobase ; R0 = base of the Microcontroller I/O space mov r2, #left_leds ; Use R2 when turning on the left set of LEDs mov r3, #right_leds ; Use R3 when turning on the right set of LEDs poll_loop: ldrb r1, [r0, #portB] ; Read the microcontroller's Port B tst r1, #portB_pbs2 ; Check if push-button S2 is pressed strneb r2, [r0, #portA] ; If it is, turn on the left LEDs tst r1, #portB_pbs3 ; Check if push-button S3 is pressed strneb r3, [r0, #portA] ; If it is, turn on the right LEDs b poll_loop ; Do this forever (or until stopped) .end