Xmega Application Note


port_example.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00051 #include "avr_compiler.h"
00052 #include "port_driver.h"
00053 
00054 void Example1( void );
00055 void Example2( void );
00056 void Example3( void );
00057 void Example4( void );
00058 
00059 
00060 void main( void )
00061 {
00062         Example1();
00063         /*Example2();*/
00064         /*Example3();*/
00065         /*Example4();*/
00066 
00067         while(true){
00068 
00069         }
00070 }
00071 
00072 
00081 void Example1( void )
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 }
00093 
00094 
00103 void Example2( void )
00104 {
00105         PORT_ConfigurePins( &PORTC,
00106                             0x0F,
00107                             false,
00108                             false,
00109                             PORT_OPC_WIREDANDPULL_gc,
00110                             PORT_ISC_BOTHEDGES_gc );
00111 }
00112 
00113 
00122 void Example3( void )
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 }
00140 
00141 
00151 void Example4( void )
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 }
00176 
00177 
00183 ISR(PORTC_INT0_vect)
00184 {
00185         PORT_TogglePins( &PORTD, 0xFF );
00186 }
00187 
@DOC_TITLE@
Generated on Wed Apr 23 08:22:06 2008 for AVR1313 Using the XMEGA I/O Pins and External Interrupts by doxygen 1.5.5