0

我试过这个 IRreceiver 代码。

如果我尝试将它上传到我的 MSP430G2452,我得到一个错误:error: '::main' must return 'int'。论坛上没有人写过这个错误。这可能是什么问题?

#include "msp430g2553.h"

#define T05 300
#define T25 T05*5
#define T35 T05*7
#define T50 T05*10
#define TMAX 65000

#define IR_DETECTOR_PIN BIT1

void reset();

unsigned int rxData = 0; // received data: A4-A0 and C6-C0 0000 AAAA ACCC CCCC
unsigned int bitCounter = 0;

void main(void) {
    WDTCTL = WDTPW + WDTHOLD; // stop WDT
    BCSCTL1 = CALBC1_1MHZ; // load calibrated data
    DCOCTL = CALDCO_1MHZ;

    P1OUT &= ~(BIT0 + BIT6); // P1.0 & P1.6 out (LP LEDs)
    P1DIR |= (BIT0 + BIT6);

    P1REN |= IR_DETECTOR_PIN; // P1.1 pull-up
    P1OUT |= IR_DETECTOR_PIN; // P1.1 pull-up
    P1IE |= IR_DETECTOR_PIN; // P1.1 interrupt enabled
    P1IES |= IR_DETECTOR_PIN; // P1.1 high/low edge
    P1IFG &= ~IR_DETECTOR_PIN; // P1.1 IFG cleared

    CCR0 = TMAX; // interrupt if no edge for T32
    TACTL = TASSEL_2 + MC_1; // SMCLK, up mode

    __bis_SR_register(LPM0_bits + GIE);
    // switch to LPM0 with interrupts
}

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void) {

    if (P1IFG & IR_DETECTOR_PIN) {
        P1IE &= ~IR_DETECTOR_PIN;

        if (bitCounter == 0) {
            P1IES &= ~IR_DETECTOR_PIN; // P1.1 low/high edge
            bitCounter++;
            TACTL |= TACLR;
            TACTL |= MC_1;
            CCTL0 = CCIE;
        } else {
            switch (bitCounter) {
            case 14: // received all bits
                // process received data, for example toggle LEDs
                switch (rxData & 0x001F) { // mask device number
                case 19: // Volume -    0010011 = 19
                    P1OUT ^= BIT0;
                    break;
                case 18: // Volume +    0010010 = 18
                    P1OUT ^= BIT6;
                    break;
                case 21: // Power   0010101 = 21
                    P1OUT |= BIT6;
                    P1OUT |= BIT0;
                    break;
                case 20: // Mute    0010100 = 20
                    P1OUT &= ~BIT6;
                    P1OUT &= ~BIT0;
                    break;
                }
                reset();
                break;
            case 1: // start bit?
                if (TA0R < T35) { // could also add || TA0R > T50
                    reset();
                } else {
                    TACTL |= TACLR;
                    TACTL |= MC_1;
                    bitCounter++;
                }
                break;
            default: // data bit
                rxData >>= 1;
                if (TA0R > T25) {
                    rxData |= 0x0800; // set bit 12 of rxData
                }
                TACTL |= TACLR;
                TACTL |= MC_1;
                bitCounter++; // increase bit counter
                break;
            }
        }
        P1IFG &= ~IR_DETECTOR_PIN;
        P1IE |= IR_DETECTOR_PIN;
    }
}

void reset() {
    CCTL0 &= ~CCIE;
    P1IES |= IR_DETECTOR_PIN; // P1.1 high/low edge
    rxData = 0;
    bitCounter = 0;
}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void) {
    // reset
    P1IE &= ~IR_DETECTOR_PIN;
    reset();
    P1IFG &= ~IR_DETECTOR_PIN;
    P1IE |= IR_DETECTOR_PIN;
}

  [1]: http://forum.43oh.com/topic/288-launchpad-ir-receiver/?p=29591
4

1 回答 1

-1

您的编译器期望 main 函数的返回类型为int

改变

void main(void)

到:

int main()

return 0;在末尾添加main()

于 2013-08-26T10:45:37.330 回答