pio_example2_dip_switch_lights.c

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

Generated on Wed May 31 07:46:56 2006 for AVR32111 Using the AVR32 PIO Controller by  doxygen 1.4.6