Ejemplo n.º 1
0
void PutsString(const rom char *str)
{
    if (!WaitToReadySerial()) return;
    strcpypgm2ram(uartOutBuffer, (const far rom char*)str);
    WriteSerial(uartOutBuffer);
    if (!WaitToReadySerial()) return;
}
Ejemplo n.º 2
0
void PrintIRBuffer(const rom char *title)
{
    WORD t;
    BYTE hilo;
    WORD byteOrWord; // 0:未設定
    WORD pos;
    char separator[2] = {'\0','\0'};

    PutsString("");  // なぜかこの出力がないと1発目が化ける

    PutsString(title);

    hilo = 1;
    pos = 0;
    byteOrWord = 0;
    while (1) {
        if (!WaitToReadySerial()) return;
        t = ReadBuffer(&pos,&byteOrWord);
        if (t==BUFF_EOF)
            break;
        sprintf(uartOutBuffer, (far rom char*)"%s%c%u",
                separator,
                hilo ? 'H' : 'L',
                t);
        WriteSerial(uartOutBuffer);
        hilo=!hilo;
        separator[0] = ',';
    }
    if (!WaitToReadySerial()) return;
    sprintf(uartOutBuffer, (far rom char*)"\r\n");
    WriteSerial(uartOutBuffer);
    if (!WaitToReadySerial()) return;
}
Ejemplo n.º 3
0
void ReadIR(void)
{
    WORD t;
    BYTE hilo;
    BYTE exit;
    WORD byteOrWord; // 0:未設定
    WORD pos;

    if (enableReadIR==0)
        return;

    if (IR_PORT == 1)
        return;

    // なにか信号があった

    WriteTimer0(0);
    INTCONbits.TMR0IF = 0;
    hilo = 0;

    pos = 0;
    byteOrWord = 0;
    exit = 0;
    while (exit==0) {
        LED1_PORT = !hilo;
        do {
            t = ReadTimer0();
            if (INTCONbits.TMR0IF || (t > MAX_WAIT_CYCLE)) {
                t = MAX_WAIT_CYCLE;
                INTCONbits.TMR0IF = 0;
                exit=1;
                break;
            }
        } while (IR_PORT == hilo);
        WriteTimer0(0);
        exit += WriteBuffer(t,&pos,&byteOrWord);
        hilo = !hilo;
    }
    LED1_PORT = 0;
    WriteEOF(pos);

    if (!WaitToReadySerial())
        return;
    PrintIRBuffer("received,");
}
void PutsStringCPtr(char *str)
{
  if (!WaitToReadySerial()) return;
  putsUSBUSART(str);
  if (!WaitToReadySerial()) return;
}
/*********************************************************************
* Function: void APP_DeviceCDCBasicDemoTasks(void);
*
* Overview: Keeps the demo running.
*
* PreCondition: The demo should have been initialized and started via
*   the APP_DeviceCDCBasicDemoInitialize() and APP_DeviceCDCBasicDemoStart() demos
*   respectively.
*
* Input: None
*
* Output: None
*
********************************************************************/
void APP_DeviceCDCBasicDemoTasks()
{
    /* If the user has pressed the button associated with this demo, then we
     * are going to send a "Button Pressed" message to the terminal.
     */
    if(BUTTON_IsPressed(BUTTON_DEVICE_CDC_BASIC_DEMO) == true)
    {
        /* Make sure that we only send the message once per button press and
         * not continuously as the button is held.
         */
        if(buttonPressed == false)
        {
            /* Make sure that the CDC driver is ready for a transmission.
             */
            if(mUSBUSARTIsTxTrfReady() == true)
            {
                putrsUSBUSART(buttonMessage);
                buttonPressed = true;
            }
        }
    }
    else
    {
        /* If the button is released, we can then allow a new message to be
         * sent the next time the button is pressed.
         */
        buttonPressed = false;
    }

    /* Check to see if there is a transmission in progress, if there isn't, then
     * we can see about performing an echo response to data received.
     */
    if( USBUSARTIsTxTrfReady() == true)
    {
      uint8_t numBytesRead;
      numBytesRead = getsUSBUSART(readBuffer, sizeof(readBuffer));

      if (numBytesRead > 0) {
        switch(readBuffer[0]) {
        case 0x10:
          {
            unsigned char size = readBuffer[1];
            debug_flag2 = !debug_flag2;
            PORTCbits.RC1 = debug_flag2;
            writeBuffer[0] = 0x90;
            writeBuffer[1] = 4;
            writeBuffer[2] = numBytesRead;
            writeBuffer[3] = readBuffer[1];
            writeBuffer[4] = readBuffer[2];
            writeBuffer[5] = readBuffer[3];
            writeBuffer[1] = 4+size;
            for (unsigned char i = 0; i<size; i++) {
              writeBuffer[i+6] = readBuffer[4 + i];
            }
            if (WaitToReadySerial())
              putUSBUSART(writeBuffer, writeBuffer[1]+2);
            WaitToReadySerial();
          }
          {
            unsigned char size = readBuffer[1];
            i2c_start(0x50, 0);
            // address in big-endian format
            i2c_send(readBuffer[3]); // address MSB
            i2c_send(readBuffer[2]); // address LSB
            for (unsigned char i = 0; i<size; i++) {
              i2c_send(readBuffer[4 + i]);
            }
            i2c_stop();
            __delay_ms(10);
          }
          break;
        case 0x11:
          {
            unsigned char size = readBuffer[1];
            unsigned char data;
            unsigned char i;
            i2c_start(0x50, 0);
            // address in big-endian format
            i2c_send(readBuffer[3]); // address MSB
            i2c_send(readBuffer[2]); // address LSB
            i2c_start(0x50, 1);
            for (i=0; i<size-1; i++) {
              writeBuffer[i+2] = i2c_receive(ACK);
            }
            writeBuffer[i+2] = i2c_receive(NOACK);
            i2c_stop();
            __delay_ms(10);
            writeBuffer[0] = 0x12;
            writeBuffer[1] = size;
            putUSBUSART(writeBuffer, writeBuffer[1]+2);
          }
          break;
        }
      }

      //if (debug_flag) {
      //  debug_flag = 0;
      //  writeBuffer[0] = 9;
      //  writeBuffer[1] = 1;
      //  writeBuffer[2] = debug_data;
      //  putUSBUSART(writeBuffer, writeBuffer[1]+2);
      //}
    }
    CDCTxService();
}
Ejemplo n.º 6
0
void PutsStringCPtr(char *str)
{
    if (!WaitToReadySerial()) return;
    WriteSerial(str);
    if (!WaitToReadySerial()) return;
}