- Main Page
- Data Structures
- Files

# pio_example.c

Go to the documentation of this file.

    00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
    00021 /* Copyright (C) 2006-2008, Atmel Corporation All rights reserved.
    00022  *
    00023  * Redistribution and use in source and binary forms, with or without
    00024  * modification, are permitted provided that the following conditions are met:
    00025  *
    00026  * 1. Redistributions of source code must retain the above copyright notice,
    00027  * this list of conditions and the following disclaimer.
    00028  *
    00029  * 2. Redistributions in binary form must reproduce the above copyright notice,
    00030  * this list of conditions and the following disclaimer in the documentation
    00031  * and/or other materials provided with the distribution.
    00032  *
    00033  * 3. The name of ATMEL may not be used to endorse or promote products derived
    00034  * from this software without specific prior written permission.
    00035  *
    00036  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
    00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00038  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
    00039  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00040  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00041  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00042  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00044  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00045  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00046  */
    00047
    00048
    00049 #include "pio.h"
    00050
    00051 #ifdef __GNUC__
    00052   #include <avr32/io.h>
    00053 #elif __ICCAVR32__
    00054   #include <avr32/ioap7000.h>
    00055 #else
    00056   #error No known compiler used
    00057 #endif
    00058
    00059 #define INPUT_MASK 0x000000ff
    00060 #define OUTPUT_MASK 0x000000ff
    00061
    00062 #define SUCCESS 0
    00063
    00064
    00074 int main( void )
    00075 {
    00076   volatile avr32_pio_t *piob = &AVR32_PIOB;
    00077   volatile avr32_pio_t *pioc = &AVR32_PIOC;
    00078   unsigned int input, output;
    00079
    00080   pioc->per = OUTPUT_MASK;
    00081   piob->per = INPUT_MASK;
    00082
    00083   pioc->oer = OUTPUT_MASK;
    00084   pioc->puer = OUTPUT_MASK;
    00085   pioc->codr = OUTPUT_MASK;
    00086   piob->codr = INPUT_MASK;
    00087
    00088   while(1){
    00089     input = ( piob->pdsr & INPUT_MASK); /* get input */
    00090     output = ( pioc->pdsr & OUTPUT_MASK); /* get output */
    00091
    00092     if ( output != input){
    00093       pioc->codr = OUTPUT_MASK;  /* clear output */
    00094       pioc->sodr = (~input & OUTPUT_MASK); /* set output from input */
    00095     }
    00096
    00097   }
    00098 }