00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00016 #include <msp430xG461x.h>
00017 #include "irda.h"
00018
00019 void InitUCA_UART(void)
00020 {
00021
00022
00023 UCA0CTL0 = 0x0;
00024
00025
00026 UCA0CTL1 = UCSSEL1;
00027
00028
00029
00030
00031
00032
00033 UCA0BR0 = 0x41;
00034 UCA0BR1 = 0x03;
00035 UCA0MCTL = 0x04;
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 UCA0IRTCTL = UCIREN + UCIRTXPL5;
00055
00056
00057 P4SEL |= 0xc0;
00058 P4DIR |= 0x40;
00059
00060
00061 P7SEL &= ~0x80;
00062 P7DIR |= 0x80;
00063 P7OUT |= 0x80;
00064 }
00065
00066 void IRDAEnable(void)
00067 {
00068
00069 P7OUT &= ~0x80;
00070 }
00071
00072 void IRDADisable(void)
00073 {
00074
00075 P7OUT |= 0x80;
00076 }
00077
00078 void WriteByteUCA_UART(unsigned char data)
00079 {
00080
00081
00082 while(UCA0STAT&UCBUSY);
00083 UCA0TXBUF = data;
00084 }
00085
00086 unsigned char ReadByteUCA_UART(void)
00087 {
00088
00089 while(UCA0STAT&UCBUSY);
00090 return (UCA0RXBUF);
00091 }
00092
00093
00094 void InitIRDA(void)
00095 {
00096
00097 InitUCA_UART();
00098
00099
00100 IRDAEnable();
00101 }
00102
00103 unsigned char TestIRDA(void)
00104 {
00105
00106
00107 unsigned char i;
00108 unsigned char sample;
00109 unsigned char success;
00110
00111 sample = 32;
00112 success = 0;
00113
00114 InitIRDA();
00115
00116
00117 for(i=0; i<sample; i++)
00118 {
00119
00120 WriteByteUCA_UART(0x55);
00121
00122 if(ReadByteUCA_UART() == 0x55)
00123 {
00124 success++;
00125 break;
00126 }
00127 }
00128
00129
00130 for(i=0; i<sample; i++)
00131 {
00132
00133 WriteByteUCA_UART(0x11);
00134
00135 if(ReadByteUCA_UART() == 0x11)
00136 {
00137 success++;
00138 break;
00139 }
00140 }
00141
00142 for(i=0; i<sample; i++)
00143 {
00144 WriteByteUCA_UART(0xA0);
00145
00146 if(ReadByteUCA_UART() == 0xA0)
00147 {
00148 success++;
00149 break;
00150 }
00151 }
00152
00153 for(i=0; i<sample; i++)
00154 {
00155
00156 WriteByteUCA_UART(0x66);
00157
00158 if(ReadByteUCA_UART() == 0x66)
00159 {
00160 success++;
00161 break;
00162 }
00163 }
00164
00165 if(success == 4)
00166 return 0;
00167 else
00168 return 1;
00169 }
00170