SAM D10 Xplained Mini Board

GPIO Portpins einrichten

* Project GPIO_02

* GPIO example SAM D10 Xplained board

* Toggle the green and red LED if pushbutton1 or pushbutton2 pressed

* LED green  @ PA10

* LED red           @ PA11

* Pushbutton 1      @ PA30

* Pushbutton 2      @ PA31

*/

  

/* More info @ Quick Start Guide for PORT - Basic

 * http://asf.atmel.com/docs/3.24.2/saml21/html/asfdoc_sam0_port_basic_use_case.html

*/

  

#include                                                                   // Include the Atmel Software Framework files

  

#define GREEN_LED    PIN_PA10                                               // ext. green LED

#define RED_LED            PIN_PA11                                               // ext. red LED

#define BUTTON_1     PIN_PA30                                               // ext. Pushbutton 1

#define BUTTON_2     PIN_PA31                                               // ext. Pushbutton 2

  

void configure_port_pins(void);                                            // Function prototype

  

void configure_port_pins(void)                                             // Function to config the port pins

{

       struct port_config config_port_pin;                                  // Create a PORT module pin configuration struct, which can be filled out to adjust the configuration of a single port pin

       port_get_config_defaults(&config_port_pin);                   // Initialize the pin configuration struct with the module's default values

        

       /* Config the pins connected to the green & red LED */

       config_port_pin.direction = PORT_PIN_DIR_OUTPUT;       // LEDs as output

       port_pin_set_config(GREEN_LED, &config_port_pin);      // config green LED @ PA10

       port_pin_set_config(RED_LED, &config_port_pin);        // config red LED @ PA11

        

       /* if you want to set 2 or more pins with one command use the funktion port_group_set_config() */

       //port_group_set_config(&PORTA, 0xC00, &config_port_pin);            // 0xC00 = Bitmask for Pin 10 and 11 ( 1100 0000 0000 )

        

       /* Config the pushbuttons */

       config_port_pin.direction = PORT_PIN_DIR_INPUT;        // Pushbutton as input

       config_port_pin.input_pull = PORT_PIN_PULL_UP;         // Pushbutton 1 on internal pull up resistor

       port_pin_set_config(BUTTON_1, &config_port_pin);       // config pushbutton 1 @ PA30

        

       config_port_pin.input_pull = PORT_PIN_PULL_DOWN;       // Pushbutton 2 on internal pull down resistor

       port_pin_set_config(BUTTON_2, &config_port_pin);       // config pushbutton 2 @ PA31

}

  

int main (void)

{

       system_init();                                                                    // Initialize system driver...

       delay_init();                                                              // Initialize delay routines...

       configure_port_pins();                                                     // configure the port pins

        

       while(1)

       {

              if(port_pin_get_input_level(BUTTON_1) == 0)                   // if button 1 pressed --> green LED is blinking

              {

                     port_pin_toggle_output_level(GREEN_LED);        // LED toggling

                     delay_s(0.5);                                                        // wait 0.2 seconds

              }

               

              else if(port_pin_get_input_level(BUTTON_2) == 1)       // if button 2 pressed --> red LED is blinking

              {

                     port_pin_toggle_output_level(RED_LED);                 // LED toggling

                     delay_s(0.2);                                                        // wait 0.2 seconds

              }

       }

}

AVR-Mikrocontroller Programmierung in C

ne555.at

avr-programmierung.com

Heimo & Patrick Gaicher