pio_example1_rainbow_lights.c

Go to the documentation of this file.
00001 #include <avr32/io.h>
00002 #include "pio_defines.h"
00003 
00004 #define CPU_HZ          27000000
00005 #define NoCOLORS        8
00006 
00007 /* leds */
00008 #define left 0
00009 #define right 1
00010 
00011 /* colors */
00012 #define black 0x00
00013 #define red 0x01
00014 #define green 0x04
00015 #define yellow 0x05
00016 #define blue 0x10
00017 #define purple 0x11
00018 #define light_blue 0x14
00019 #define white 0x15
00020 
00021 int color_array[NoCOLORS]={black,purple,blue,light_blue,green,yellow,red,white};
00022 
00023 void delay( void );
00024 int rgb_leds(struct avr32_pio_t * pio, int pos, int color);
00025 
00026 
00034 int main( void )
00035 {
00036   int i,j;
00037   avr32_pio_t *piob = (void *) AVR32_PIOC_ADDRESS;
00038 
00039   piob->per = 0x000000ff;
00040   piob->oer = 0x000000ff;
00041   piob->idr = 0x000000ff;
00042 
00043 
00044 
00045   while(1){
00046     for(i=0; i<NoCOLORS; i++){
00047       rgb_leds(piob, left, i);
00048       for(j=0; j<NoCOLORS; j++){
00049         rgb_leds(piob, right,j);
00050         delay();
00051       }
00052       delay();
00053     }
00054   }
00055 }
00061 void delay( void )
00062 {
00063   unsigned long i;
00064   for (i=0; i<100000; i++);
00065 }
00072 int rgb_leds(struct avr32_pio_t * pio, int pos, int col_pos)
00073 {
00074         if( (pos>1) | (pos<0) | (col_pos>NoCOLORS) | (col_pos<0) )
00075                 return PIO_INVALID_ARGUMENT;
00076 
00077         pio->codr = 0x00000015<<pos;
00078         pio->sodr = color_array[col_pos]<<pos;
00079 
00080         return 0;
00081 }

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