Xmega Application Note


port_example.c File Reference


Detailed Description

XMEGA I/O Port driver example source.

This file contains an example application that demonstrates the I/O Port driver. It shows how to set up the I/O Ports as described in the examples in the "Getting Started" section of the application note document.

Application note:
AVR1313: Using the XMEGA I/O pins and External Interrupts
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
1569
Date
2008-04-22 13:03:43 +0200 (ti, 22 apr 2008)

Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file port_example.c.

#include "avr_compiler.h"
#include "port_driver.h"

Include dependency graph for port_example.c:

Go to the source code of this file.

Functions

void Example1 (void)
 Getting started example 1.
void Example2 (void)
 Getting started example 2.
void Example3 (void)
 Getting started example 3.
void Example4 (void)
 Getting started example 4.
 ISR (PORTC_INT0_vect)
 Interrupt service routine for Example4().
void main (void)


Function Documentation

void Example1 ( void   ) 

Getting started example 1.

This function implements the "Basic Digital I/O" example from the "Getting Started" section in the application note.

This function will continously read input from 8 switches connected to PORTC and output the pin state to 8 LEDs connected to PORTD.

Definition at line 81 of file port_example.c.

References PORT_GetPortValue, PORT_SetOutputValue, PORT_SetPinsAsInput, and PORT_SetPinsAsOutput.

Referenced by main().

00082 {
00083         /* Configure data direction for PORTC and PORTD. */
00084         PORT_SetPinsAsInput( &PORTC, 0xFF );
00085         PORT_SetPinsAsOutput( &PORTD, 0xFF );
00086 
00087         /* Continously copy the value from PORTC to PORTD. */
00088         do {
00089                 uint8_t temp = PORT_GetPortValue( &PORTC );
00090                 PORT_SetOutputValue( &PORTD, temp );
00091         } while (true);
00092 }

void Example2 ( void   ) 

Getting started example 2.

This function implements the "Configuring Several Pins in One Operation" example from the "Getting Started" section in the application note.

This function configures pins 0-3 on PORTC for Wired-AND with pull-up operation.

Definition at line 103 of file port_example.c.

References PORT_ConfigurePins().

00104 {
00105         PORT_ConfigurePins( &PORTC,
00106                             0x0F,
00107                             false,
00108                             false,
00109                             PORT_OPC_WIREDANDPULL_gc,
00110                             PORT_ISC_BOTHEDGES_gc );
00111 }

Here is the call graph for this function:

void Example3 ( void   ) 

Getting started example 3.

This function implements the "Mapping Real Ports to Virtual Ports" example from the "Getting Started" section in the application note.

This function maps PORTC to Virtual port 0 and PORTD to Virtual PORT1, and performs the same task as in Example1() using virtual ports.

Definition at line 122 of file port_example.c.

References PORT_GetPortValue, PORT_MapVirtualPort0(), PORT_MapVirtualPort1(), PORT_SetDirection, and PORT_SetOutputValue.

00123 {
00124         /* Map the ports. */
00125         PORT_MapVirtualPort0( PORTCFG_VP0MAP_PORTC_gc );
00126         PORT_MapVirtualPort1( PORTCFG_VP1MAP_PORTD_gc );
00127 
00128         /* Configure VPORT0 as input and VPORT1 as output. */
00129         PORT_SetDirection( &VPORT0, 0x00 );
00130         PORT_SetDirection( &VPORT1, 0xFF );
00131 
00132         /* Continously copy the value from PORTC to PORTD using the
00133          * virtual ports.
00134          */
00135         do {
00136                 uint8_t temp = PORT_GetPortValue( &VPORT0 );
00137                 PORT_SetOutputValue( &VPORT1, temp );
00138         } while (true);
00139 }

Here is the call graph for this function:

void Example4 ( void   ) 

Getting started example 4.

This function implements the "Configuring an I/O Pin for Interrupt Generation" example from the "Getting Started" section in the application note.

This function configures PORTC interrupt0 as a medium level interrupt, triggered by the rising edge of PC0. The interrupt service routine toggles the output on PORTD.

Definition at line 151 of file port_example.c.

References PORT_ConfigureInterrupt0(), PORT_ConfigurePins(), PORT_SetPins, PORT_SetPinsAsInput, and PORT_SetPinsAsOutput.

00152 {
00153         /* Configure PC0 as input, triggered on rising edge. */
00154         PORT_ConfigurePins( &PORTC,
00155                             0x01,
00156                             false,
00157                             false,
00158                             PORT_OPC_TOTEM_gc,
00159                             PORT_ISC_RISING_gc );
00160 
00161         PORT_SetPinsAsInput( &PORTC, 0x01 );
00162 
00163         /* Configure PORTD as output with the pattern 0x55. */
00164         PORT_SetPinsAsOutput( &PORTD, 0xFF );
00165         PORT_SetPins( &PORTD, 0x55 );
00166 
00167         /* Configure Interrupt0 to have medium interrupt level, triggered by pin 0. */
00168         PORT_ConfigureInterrupt0( &PORTC, PORT_INT0LVL_MED_gc, 0x01 );
00169 
00170         /* Enable medium level interrupts in the PMIC. */
00171         PMIC.CTRL |= PMIC_MEDLVLEN_bm;
00172 
00173         /* Enable the global interrupt flag. */
00174         sei();
00175 }

Here is the call graph for this function:

ISR ( PORTC_INT0_vect   ) 

Interrupt service routine for Example4().

When initialized using Example4(), this ISR is called on every rising edge on PC0.

Definition at line 183 of file port_example.c.

References PORT_TogglePins.

00184 {
00185         PORT_TogglePins( &PORTD, 0xFF );
00186 }

void main ( void   ) 

Definition at line 60 of file port_example.c.

References Example1().

00061 {
00062         Example1();
00063         /*Example2();*/
00064         /*Example3();*/
00065         /*Example4();*/
00066 
00067         while(true){
00068 
00069         }
00070 }

Here is the call graph for this function:

@DOC_TITLE@
Generated on Wed Apr 23 08:22:07 2008 for AVR1313 Using the XMEGA I/O Pins and External Interrupts by doxygen 1.5.5