예제 #1
0
bool MOTEapp_getModemResponse(void)
{
    bool terminatorReceived = false;    // Return false; Unless Terminator character (0x0D) is captured
    if (EUSART_DataReady)       // See if Bytes are available
    {
        uint8_t bufferByte = 0; // Restore for read
        bufferByte = EUSART_Read();
        // See what we got
        if (bufferByte == 0x0D)
        {
            modemResonseBuffer[modemBufferIndex] = 0x00; // Add Null terminator
            terminatorReceived = true;
            modemBufferIndex = 0; // Prepare index for next message
        }
        else if ( (bufferByte == 0x00) || (bufferByte == 0x0A) )
        {
            // Do nothing
        }
        else
        {
            modemResonseBuffer[modemBufferIndex] = bufferByte; // Add Byte to Buffer
            // Increment Buffer for next byte
            modemBufferIndex++;
        }
    }
    return terminatorReceived;
}
예제 #2
0
// wait for user acknowledge, return char (absorb '/r')    
char _DEBUG_Ack(void)
{   char c;
    do{ 
        while(!EUSART_DataReady);   // wait 
        c = EUSART_Read();
        DEBUG_putch(c);            // echo
    } while (c == '\r');            // absorb
    return c;
}
예제 #3
0
파일: main.c 프로젝트: araobp/iot_study
void main(void)
{
    // initialize the device
    SYSTEM_Initialize();
    INTERRUPT_GlobalInterruptEnable();
    INTERRUPT_PeripheralInterruptEnable();
    EUSART_Initialize();
    EPWM1_Initialize();

    uint16_t dutyValue;
    uint16_t angle;
    uint8_t c;
    uint8_t buf[32] = {'\0'};
    uint8_t cnt = 0;
    
    // read angle from EEPROM
    angle = (uint16_t)DATAEE_ReadByte(0);
    // printf("read angle from EEPROM: %d\n", angle);
    dutyValue = calc_duty(angle);
    EPWM1_LoadDutyValue(dutyValue);
            
    while (1)
    {
        __delay_ms(500);
        LATCbits.LATC4 ^= 1;

        do {
            c = EUSART_Read();
            if (c == '\n') {
                buf[cnt] = '\0';
                cnt = 0;
                if (strcmp(buf, "w") == 0) {
                    DATAEE_WriteByte(0, (uint8_t)angle);
                    // printf("write the last angle onto EEPROM: %d\n", angle);
                } else {
                    angle = atoi(buf);
                    dutyValue = calc_duty(angle);
                    EPWM1_LoadDutyValue(dutyValue);
                }
            } else {
                buf[cnt++] = c;
            }
        } while (EUSART_DataReady);

        CLRWDT();
    } 
}
예제 #4
0
파일: eusart.c 프로젝트: Edewin/OldCode
char getch(void)
{
    return EUSART_Read();
}