void _open_log_wait_cmd_ack() { char ack; while(1) { ack = uart1GetByte(); if( ack == '>' ) { break; } } }
void uartTest(void) { int c; // print a little intro message so we know things are working rprintfStr("\r\n\n\nWelcome to the uart library test program!\r\n"); rprintfStr("Press any key...\r\n"); // read in serial port traffic from UART1 // and echo it back in hex and/or ascii format as appropriate while(1) { if((c = uart1GetByte()) != -1) { // we got a byte rprintf("Ascii code: 0x%x ", c); // see if it's printable if((c >= 0x20) && (c < 0x7F)) { uart1SendByte(c); } rprintfStr("\r\n"); } } }
void open_log_reset() { OPEN_LOG_RESET_PORT &= ~(1<<OPEN_LOG_RESET_PIN); _delay_ms(100); OPEN_LOG_RESET_PORT |= (1<<OPEN_LOG_RESET_PIN); // wait for the device to acknowledge before returning while(1) { char ack; ack = uart1GetByte(); if( ack == '<' ) { break; } } }
void open_log_write_test(void) { open_log_reset(); _delay_ms(1000); open_log_command_mode(); // put in command mode and wait until ack _delay_ms(1000); uartSendString_P(1,"new temps.txt\r"); while(1) { u16 ack = uart1GetByte(); if( ack == '>' ) { break; } } uartSendString_P(1,"append temps.txt\r"); uartSendString_P(1,"Hello World!\r"); }
void control() { unsigned right_rotHi = 0; unsigned right_rotLo = 0; int rightCount = 0; unsigned left_rotHi = 0; unsigned left_rotLo = 0; int leftCount = 0; int right_rotState =a2dConvert8bit(0);//right rotations //int se1 =a2dConvert8bit(1); int right_direction =a2dConvert8bit(3);//right direction, forward = low, reverse = hi int left_direction =a2dConvert8bit(7);//left direction, forward = hi, reverse = low int left_rotState =a2dConvert8bit(8);//left rotations //int se5 =a2dConvert8bit(9); while( uart1GetByte() != 'x') { if( 0 <= right_rotState && 10 > right_rotState ) //if rotState is low { right_rotLo++; } if( 250 < right_rotState && 255 >= right_rotState ) //if rotState is high { right_rotHi++; } if( 0 <= left_rotState && 10 > left_rotState) //if rotState is low { left_rotLo++; } if( 250 < left_rotState && 255 >=left_rotState) //if rotState is high { left_rotHi++; } //--------------------------- if( right_rotLo > 0 && right_rotHi > 0)//if the encoder has seen both white and black { if( 0 <= right_direction && right_direction < 10) { rightCount++; } if( 250 < right_direction && right_direction <= 255) { rightCount--; } right_rotLo = 0; right_rotHi = 0; } if( left_rotLo > 0 && left_rotHi > 0)//if the encoder has seen both white and black { if( 0 <= left_direction && left_direction < 10) { leftCount--; } if( 250 < left_direction && left_direction <= 255) { leftCount++; } left_rotLo = 0; left_rotHi = 0; } rprintf(" %d, %d, %d, %d \n %d %d %d %d \n",left_rotLo,left_rotHi, left_direction,leftCount,right_rotLo,right_rotHi,right_direction,rightCount); rprintf("LEFT DIR:%d, LEFT DST:%d, RIGHT DIR:%d, RIGHT DST:%d\n,",left_direction,leftCount,right_direction, rightCount); right_rotState =a2dConvert8bit(0);//right rotations right_direction =a2dConvert8bit(3);//right direction, forward = low, reverse = hi left_direction =a2dConvert8bit(7);//left direction, forward = hi, reverse = low left_rotState =a2dConvert8bit(8);//left rotations } /* unsigned right_rotHi = 0; if( 250 < left_direction && left_direction <= 255) {leftCount++;} left_rotLo = 0; left_rotHi = 0; } //rprintf(" %d, %d, %d, %d \n %d %d %d %d \n",left_rotLo,left_rotHi, left_direction,leftCount,right_roLo,right_rotHi,right_direction,rightCount); //rprintf("LEFT DIR:%d, LEFT DST:%d, RIGHT DIR:%d, RIGHT DST:%d\n,",left_direction,leftCount,right_direction, rightCount); right_rotState =a2dConvert8bit(0);//right rotations right_direction =a2dConvert8bit(3);//right direction, forward = low, reverse = hi left_direction =a2dConvert8bit(7);//left direction, forward = hi, reverse = low left_rotState =a2dConvert8bit(8);//left rotations } int control_PID( ) { } void update_motors() { //Right 607-640 braking range //left 613-633 braking range if(motorLeftSpeed<613||motorLeftSpeed>633) { wheel_Left(motorLeftSpeed); } if(motorRightSpeed<607||motorRightSpeed>640) { wheel_Right(motorRightSpeed); } }*/ }
void control(void) { reset_timer5(); uartFlushReceiveBuffer(1); a2dSetReference(ADC_REFERENCE_256V); delay_us(100); PORT_OFF(PORTB,7); while(1) { char read = uart1GetByte(); if(read == 'U') { //Rangefinder only for the Hand! We only have 3 uart ports! uart0SendByte(0x22); //sends 4 bytes with the command to read distance (0x22) uart0SendByte(0x00); uart0SendByte(0x00);uart0SendByte(0x22);delay_us(50); uart0GetByte(); //we don't care about this byte rprintf("%d\r\n", 255*uart0GetByte() + uart0GetByte()); uart0GetByte(); //we don't care about this byte } else if(read == 'L') { rprintf("%d\r\n", 255 - a2dConvert8bit(0)); } else if(read == 'R') { rprintf("%d\r\n", 255 - a2dConvert8bit(1)); } else if(read == 'D') { int buff='#'; uart2SendByte('#'); uart2SendByte('o'); uart2SendByte('s'); uart2SendByte('#'); uart2SendByte('f'); delay_ms(60); // Do not change this delay or you'll get in trouble! while(1) { buff = uart2GetByte(); if(buff==10 || buff==13 || buff==-1) { uart1SendByte('\r'); uart1SendByte('\n'); break; } uart1SendByte(buff); } while((buff=uart2GetByte()) != -1); } else if(read == 'E') { int buff='#'; uart3SendByte('#'); uart3SendByte('o'); uart3SendByte('s'); uart3SendByte('#'); uart3SendByte('f'); delay_ms(60); // Do not change this delay or you'll get in trouble! while(1) { buff = uart3GetByte(); if(buff==10 || buff==13 || buff==-1) { uart1SendByte('\r'); uart1SendByte('\n'); break; } uart1SendByte(buff); } while((buff=uart3GetByte()) != -1); } else if(read == 'M') { int buff='#'; uart2SendByte('#'); uart2SendByte('o'); uart2SendByte('t'); uart2SendByte('#'); uart2SendByte('f'); delay_ms(60); // Do not change this delay or you'll get in trouble! while(1) { buff = uart2GetByte(); if(buff==10 || buff==13 || buff==-1) { uart1SendByte('\r'); uart1SendByte('\n'); break; } uart1SendByte(buff); } while((buff=uart2GetByte()) != -1); } else if(read == 'N') { int buff='#'; uart3SendByte('#'); uart3SendByte('o'); uart3SendByte('t'); uart3SendByte('#'); uart3SendByte('f'); delay_ms(60); // Do not change this delay or you'll get in trouble! while(1) { buff = uart3GetByte(); if(buff==10 || buff==13 || buff==-1) { uart1SendByte('\r'); uart1SendByte('\n'); break; } uart1SendByte(buff); } while((buff=uart3GetByte()) != -1); } else if(read == 'P') { PORT_ON(PORTB,6); } else if(read == 'p') { PORT_OFF(PORTB,6); } else if(read == 'Q') { PORT_ON(PORTB,7); } else if(read == 'q') { PORT_OFF(PORTB,7); } else if(read == 'X') { PORT_ON(PORTB,4); } else if(read == 'x') { PORT_OFF(PORTB,4); } else if(read == 'Y') { PORT_ON(PORTB,5); } else if(read == 'y') { PORT_OFF(PORTB,5); } delay_us(50); } }