void InterruptHandler( void ) { BYTE bTmp; if ( INTCONbits.INT0IF ) { // devo rever se é isso mesmo.... // realiza a leitura do modem bTmp = getcUART( ); ProcessaProtocolo( bTmp ); INTCONbits.INT0IF = 0; } if ( PIR1bits.TMR2IF ) { IncTickCount( ); PIR1bits.TMR2IF = 0; } while ( PIR1bits.RCIF ) { if ( RCSTAbits.FERR ) { //RCSTAbits.FERR = 0; SerialGetchar(); break; } if ( RCSTAbits.OERR ) { //RCSTAbits.OERR = 0; RCSTAbits.CREN ^= 1; Nop(); RCSTAbits.CREN ^= 1; break; } if ( isrSerialFunc ){ bTmp = SerialGetchar(); (*isrSerialFunc)( bTmp ); } } }
int main(int argc, char* argv[]) { unsigned int ser = SerialOpen(115200); //Open serial port with a 115200 baud rate int a = 0; SerialFlush(ser); //Clear TX and RX buffer, can be called periodically SerialPuts(ser,"Serial communication using the Sensorian Shield.\r\n"); SerialPrintf(ser,"You are using device number %d.\r\n",ser); SerialFlush(ser); while(1) { if(SerialDataAvail(ser)) { a = SerialGetchar(ser); SerialPrintf(ser,"You sent %c.\r\n",(char)(a)); if(a == 'b') break; } } SerialPrintf(ser,"Closing serial port ..."); SerialClose(ser); //Close serial port return 0; }