コード例 #1
0
ファイル: Asuro.cpp プロジェクト: rchicoli/asurino
void Asuro::Init(void)
{  
  pinMode(rforward, OUTPUT);
  pinMode(rreverse, OUTPUT);
  pinMode(lforward, OUTPUT);
  pinMode(lreverse, OUTPUT);
  pinMode(frontled, OUTPUT);
  pinMode(statusledred, OUTPUT);
  pinMode(statusledgreen, OUTPUT);
  pinMode(odometricled, OUTPUT);
  pinMode(irtxled, OUTPUT);

  // fix analog-to-digital converter timing (for 8 MHz clock)
  ADCSRA &= ~ADPS0;
  setTimer2();
}
コード例 #2
0
int main() {
    CFGCONbits.JTAGEN = 0; // turn off JTAG, get back those pins for IO use
    // set PIC32to max computing power
    DEBUGLED = 0;
    // enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();
    INTEnableInterrupts();
    PIC32MX250_setup_pins();
    SYSTEMConfigPerformance(SYS_FREQ);

    setTimer2(OUTPUT_FREQ); //
    setupTimer3(BUFFER_FREQ);
    initPWM(); //Initializing PWM on OC3.

    // Initialize texture buffer and index to zero

    int i;
    tBuff.Index = 0; //init to zero
    tBuff.On = 0; //turn off
    tBuff.Length0 = 0; //start with zero length
    tBuff.Length1 = 0; //start with zero length
    tBuff.Front = 0;
    for (i = 0; i < MAX_BUFFER_LENGTH; i++) {
        tBuff.Buff0[i] = 0; //init entire buffer to zero
        tBuff.Buff1[i] = 0; //init entire buffer to zero
    }


    // Initialize the USB host
    ConnectionInit();
    DEBUGLED = 1;

    //Main USB State Machine
    while (1) {
        // Keep the USB connection running;
        // Handle incoming data and manage outgoing data.
        ConnectionTasks();
        // Main state machine
        switch (state) {
            case STATE_INIT:

                state = STATE_WAITING;
                h = INVALID_CHANNEL_HANDLE;
                break;

            case STATE_WAITING:
                DEBUGLED = 0;
                if (ADBAttached()) {
                    state = STATE_CONNECTING;
                }
                break;

            case STATE_CONNECTING:

                if (ADBConnected()) {
                    // Open a channel to the Android device
                    // See "adb.h" in libadb for more details
                    // (I don't think the name tcp:4545 matters)
                    h = ADBOpen("tcp:4545", &ADBCallback);

                    if (h != INVALID_CHANNEL_HANDLE) {
                        state = STATE_CONNECTED;
                        WriteCoreTimer(0);
                        // Send plaintext and let the recipient do formatting
                        ADBWrite(h & 0xFF, "Hello from TPAD!", 17);
                    }
                }
                break;

            case STATE_CONNECTED:
                DEBUGLED = 1;

                if (!ADBAttached()) {
                    state = STATE_INIT;
                }
                if (ADBChannelReady(h)) {

                    // Execute tasks that rely on the Android-PIC32 connection
                    // Here we will just wait for messages to come in and be handled below
                }
                // Timeout timer. If the coretimer is not reset by a keepalive command from the Android, the PIC will reset the USB communications
                if (ReadCoreTimer() > 200000000) {
                    state = STATE_INIT;
                }

                break;
        } // end state machine
    } // end while loop

    return 0;
}