task main() { // Setup the two UART ports //configureSerialPort(uartOne, uartUserControl); //configureSerialPort(uartTwo, uartUserControl); setBaudRate(uartOne, baudRate115200); setBaudRate(uartTwo, baudRate115200); while (getChar(uartTwo) != -1) // Purge existing chars from buffer {} StartTask(UARTReceive); while (true) { // Loop forever transmitting the characters 0, 1, 2, ..., 255, 0, 1, 2, .... for (int i = 0; i < 20; ++i) { ++nTotalXmitChars; xmitChar = nTotalXmitChars % 256; sendChar(uartOne, xmitChar); } while (!bXmitComplete(uartOne)) { wait1Msec(1); } } }
void vexLcdSendMessage( LcdData *lcd, short line ) { // create message short i, cs; short timeout; // bounds check line variable if( ( line < 0 ) || (line > 1) ) return; // Header for LCD communication lcd->txbuf[0] = 0xAA; lcd->txbuf[1] = 0x55; lcd->txbuf[2] = 0x1e; lcd->txbuf[3] = 0x12; lcd->txbuf[4] = (lcd->flags & VEX_LCD_BACKLIGHT) ? 0x02 + line : line; // fill with spaces for(i=0;i<16;i++) lcd->txbuf[ 5+i ] = 0x20; // Copy data transmit buffer if(!line) { for(i=0;(i<16)&&(lcd->line1[i]!=0);i++) lcd->txbuf[ 5+i ] = lcd->line1[i]; } else { for(i=0;(i<16)&&(lcd->line2[i]!=0);i++) lcd->txbuf[ 5+i ] = lcd->line2[i]; } // calculate checksum cs = 0; for(i=4;i<21;i++) cs = cs + lcd->txbuf[i]; lcd->txbuf[21] = 0x100 - cs; // send to port for(i=0;i<22;i++) { // wait for transmit complete or timeout // Under normal circumstances this should not be needed, there is // a transmit buffer larger than most messages // timeout here is set at about 200uS (from experimentation) timeout = 0; while( !bXmitComplete(lcd->port) && (timeout < 20) ) timeout++; // send char sendChar( lcd->port, lcd->txbuf[i] ); } }
void RobotC_WriteBuf( int port, char *data, int data_len ) { int i; int timeout; for(i=0;i<data_len;i++) { // wait for transmit complete or timeout // Under normal circumstances this should not be needed, there is // a transmit buffer larger than most messages // timeout here is set at about 200uS (from experimentation) timeout = 0; while( !bXmitComplete(port) && (timeout++ < 20) ) ; // send char sendChar(port, data[i]); } }