pio_example2_dip_switch_lights.c

Go to the documentation of this file.
00001 #include <avr32/morgan.h>
00002 #include <avr32/pio.h>
00003 
00004 /* colors */
00005 #define black 0x00
00006 #define red 0x01
00007 #define green 0x04
00008 #define yellow 0x05
00009 #define blue 0x10
00010 #define purple 0x11
00011 #define light_blue 0x14
00012 #define white 0x15
00013 
00014 char color_array[8]={black,purple,blue,light_blue,green,yellow,red,white};
00015 
00016 #define INPUT_BITMASK   0x0000ff00
00017 #define OUTPUT_BITMASK  0x000000ff
00018 
00028 int main( void )
00029 {
00030   avr32_pio_t *piob = (void *) AVR32_PIOB;
00031   char input, output;
00032 
00033   /* SET PIO */
00034   piob->pdr = 0x00000000; /* Enable entire PORTB for PIO controlled operation */
00035   piob->oer = OUTPUT_BITMASK; /* Use PORTB[15..8] as output */
00036   piob->odr = INPUT_BITMASK; /* Use PORTB[7..0] as input */
00037   piob->ifer = INPUT_BITMASK; /*Glitch enable on input */
00038   piob->codr = 0xFFFFffff; /* Clear all appropriate pins */
00039 
00040   while(1){
00041         /* read input and output */
00042         input = (~(piob->pdsr >> 8) & OUTPUT_BITMASK);
00043     output = (piob->pdsr) & OUTPUT_BITMASK;
00044 
00045         /* check if a change has occured */
00046     if( input != output){
00047                 /* Clear the output data */
00048                 piob->codr = OUTPUT_BITMASK;
00049                 /* Set output data according to the input */
00050                 piob->sodr = input;
00051     } //if
00052   }//while
00053 }//main

Generated on Thu May 10 14:14:48 2007 for AVR321000 Communication with the AVR32 USART by  doxygen 1.5.1