Atmel Evaluation Board using the SAM7SE Microcontroller AT91SAM7SE-EK AT91SAM7SE-EK Data Sheet

Product codes
AT91SAM7SE-EK
Page of 24
15
6295A–ATARM–27-Mar-07
Application Note
AT91C_BASE_PIOA->PIO_PER = (LED_A | LED_B);
/* Disable pull-ups */
AT91C_BASE_PIOA->PIO_PPUDR = (LED_A | LED_B);
3.2.6.4
Controlling LEDs
LEDs are turned on or off by changing the level on the PIOs to which they are connected. After
those PIOs have been configured, their output values can be changed by writing the pin IDs in
the Set Output Data Register (SODR) and the Clear Output Data Register (CODR) of the PIO
controller.
In addition, a register indicates the current level on each pin (Pin Data Status Register, PDSR).
It can be used to create a toggle function, i.e. when the LED is ON according to PDSR, then it is
turned off, and vice-versa.
/* Turn LED off */
AT91C_BASE_PIOA->PIO_SODR = LED_A;
/* Turn LED on */
AT91C_BASE_PIOA->PIO_CODR = LED_A;
3.2.6.5
Configuring Buttons
As stated previously, the two PIOs connected to the switches on the board shall be inputs. Also,
a “state change” interrupt is configured for both buttons. This triggers an interrupt when a button
is pressed or released.
After the PIOC control has been enabled on the PIOs (by writing PER), they are configured as
inputs by writing their IDs in ODR. Conversely to the LEDs, it is necessary to keep the pull-ups
enabled.
Enabling interrupts on the two pins is simply done in the Interrupt Enable Register (IER). How-
ever, the PIO controller interrupt must be configured as described in 
3.2.6.6
Interrupt Handler
The interrupt handler for the PIO controller must first check which button has been pressed.
PDSR indicates the level on each pin, so it can show if each button is currently pressed or not.
Alternatively, the Interrupt Status Register (ISR) reports which PIOs have had their status
changed since the last read of the register.
In the example software, the two are combined to detect a state change interrupt as well as a
particular level on the pin. This corresponds to either the press or the release action on the
button.
As said in the application description (
), each button enables or disables
the blinking of one LED. Two variables are used as boolean values, to indicate if either LED is
blinking. When the status of the LED which is toggled by the Timer Counter is modified, the TC
clock is either stopped or restarted by the interrupt handler as well.
Note that the interrupt must be acknowledged in the PIOC. This is done implicitly when ISR is
read by the software. However, conversely to the Timer Counter (see 
), since the ISR value is actually used in several operations, there is no need to worry about
the compiler inadvertantly