00001
00051 #include "avr_compiler.h"
00052 #include "IR_driver.h"
00053 #include "usart_driver.h"
00054
00055
00057 #define USART USARTC0
00058
00059
00061 bool success;
00062
00063
00077 void main(void)
00078 {
00079
00080
00081 uint8_t sendData;
00082 uint8_t receivedData;
00083
00084
00085
00086
00087 PORTC.DIRSET = PIN3_bm;
00088
00089 PORTC.DIRCLR = PIN2_bm;
00090
00091
00092 USART_Format_Set(&USART, USART_CHSIZE_8BIT_gc, USART_PMODE_DISABLED_gc, false);
00093
00094
00095
00096
00097
00098
00099
00100
00101 USART_Baudrate_Set(&USART, 12 , 0);
00102
00103
00104 USART_SetMode(&USARTC0, USART_CMODE_IRDA_gc);
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 USART_Rx_Enable(&USART);
00115 USART_Tx_Enable(&USART);
00116
00117
00118
00119 success = true;
00120
00121 sendData = 255;
00122 while(sendData) {
00123
00124 do{
00125
00126
00127 }while(!USART_IsTXDataRegisterEmpty(&USART));
00128 USART_PutChar(&USART, sendData);
00129
00130 uint16_t timeout = 1000;
00131
00132 do{
00133
00134 timeout--;
00135 }while(!USART_IsRXComplete(&USART) && timeout!=0);
00136 receivedData = USART_GetChar(&USART);
00137
00138
00139 if (receivedData != sendData){
00140 success = false;
00141 }
00142 sendData--;
00143 }
00144
00145
00146 USART_Rx_Disable(&USART);
00147 USART_Tx_Disable(&USART);
00148
00149
00150 if(success){
00151 while(true);
00152 }else{
00153 while(true);
00154 }
00155 }