1 | #include "msp430x26x.h"
|
2 |
|
3 | unsigned char RxByte;
|
4 | volatile unsigned char RxData[256];
|
5 | unsigned char TxByte;
|
6 | volatile unsigned int i;
|
7 |
|
8 | void main(void)
|
9 | {
|
10 | WDTCTL = WDTPW + WDTHOLD; // Stop WDT
|
11 | //DCOCTL = CALDCO_8MHZ; // Load 8MHz constants
|
12 | //BCSCTL1 = CALBC1_8MHZ;
|
13 | BCSCTL1 |= XTS ; // ACLK = LFXT1 = HF XTAL
|
14 | BCSCTL3 |= LFXT1S1; // 3 – 16MHz crystal
|
15 |
|
16 | do
|
17 | {
|
18 | IFG1 &= ~OFIFG; // Clear OSCFault flag
|
19 | for (i = 0xFF; i > 0; i--); // Time for flag to set
|
20 | }
|
21 | while (IFG1 & OFIFG); // OSCFault flag still set?
|
22 |
|
23 | BCSCTL2 |= SELM_3; // MCLK = LFXT1 (safe)
|
24 | P1OUT &= ~0x01; // Clear P1.0
|
25 | P1DIR |= 0x01; // P1.0 output
|
26 | P3OUT &= ~(BIT4+BIT5);
|
27 | P3SEL |= 0x30; // Use P3.4/P3.5 for USCI_A0
|
28 | UCA0CTL1 |= UCSWRST; // Set SW Reset
|
29 | UCA0CTL1 = UCSSEL_1 + UCSWRST; // Use SMCLK, keep SW reset
|
30 | UCA0BR0 = 104; // 8MHz/52=153.8KHz
|
31 | UCA0BR1 = 0;
|
32 | UCA0MCTL = UCBRF_1 + UCOS16; // Set 1st stage modulator to 1
|
33 |
|
34 | //UCA0MCTL = UCBRS_7 + UCBRF_0 + UCOS16; // Set 1st stage modulator to 1
|
35 | // 16-times oversampling mode
|
36 | UCA0IRTCTL = UCIRTXPL2 + UCIRTXPL0 + UCIRTXCLK + UCIREN;
|
37 | // Pulse length = 6 half clock cyc
|
38 | // Enable BITCLK16, IrDA enc/dec
|
39 | UCA0CTL1 &= ~UCSWRST; // Resume operation
|
40 | TxByte = 0x53;
|
41 | //TxByte = 0xAB; // TX data and pointer, 8-bit
|
42 | //TxByte = 0x00;
|
43 | IE2 |= UCA0RXIE;
|
44 | while (1)
|
45 | {
|
46 | for (i = 1000; i; i--); // Small delay
|
47 | while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
|
48 | UCA0TXBUF = TxByte; // TX character
|
49 | P1OUT ^= 0x01;
|
50 | //TxByte++;
|
51 |
|
52 | __disable_interrupt();
|
53 | IE2 |= UCA0RXIE; // Enable RX int
|
54 | __bis_SR_register(GIE); // Enter LPM0 w/ interrupts
|
55 | }
|
56 | }
|
57 | #pragma vector = USCIAB0RX_VECTOR
|
58 | __interrupt void USCIAB0RX_ISR(void)
|
59 | {
|
60 | RxByte = UCA0RXBUF; // Get RXed character
|
61 | IE2 &= ~UCA0RXIE; // Disable RX int
|
62 | //TxByte = RxByte;
|
63 | if (TxByte != RxByte) // RX OK?
|
64 | {
|
65 | P1DIR |= 0x01;
|
66 | P1OUT |= 0x01; // LED P1.0 on
|
67 | }
|
68 | //__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
|
69 |
|
70 | }
|