u8 FING_u8SetSysPra(u8 * Copy_u8ChipAdd,u8 *Copy_u8ParamArr) { u8 Local_u8Count; const u8 Local_u8SysPra[6]={0x01,0x00,0x03,0x0f,0x00,0x13}; u16 Local_u16RxData,Local_u16Param; FING_voidSendHeader(); for(Local_u8Count=3 ; Local_u8Count>=0;Local_u8Count--) { USART_Transmit(Copy_u8ChipAdd[Local_u8Count]) ; } for(Local_u8Count=0;Local_u8Count<6;Local_u8Count++) { USART_Transmit(Local_u8SysPra[Local_u8Count]); } for(Local_u8Count=0 ; Local_u8Count<10;Local_u8Count++) { USART_Receive(&Local_u16RxData); } for(Local_u8Count=0 ; Local_u8Count<16;Local_u8Count++) { USART_Receive(&Local_u16Param); Copy_u8ParamArr[Local_u8Count]=(u8)Local_u16Param ; } return Local_u16RxData ; }
int main(void) { uint16_t cnt=0; uint8_t c,div; DDRA = 0; PORTA = 0xff; DDRB = (1 << 4); //TXD DDRC = 0xff; PORTC = 0; DDRD = 0xfe; USART_Init(8); // 115.2K ADCSRA = 0x87; // init ADC // TCCR0 = 1; // TIMSK = 1; // sei(); for( ; ; ) { _WDR(); if(USART_Ready()) { c = USART_Receive(STD_TIMEOUT); switch(c) { case 'g': div = rhex(); if(USART_Timeout()) break; ADCSRA = 0x80 | div; div = rhex(); if(USART_Timeout()) break; PORTC = div; // gain get_wave(); send_wave(); break; case 'q': div = rhex(); if(USART_Timeout()) break; ADCSRA = 0x80 | div; div = rhex(); if(USART_Timeout()) break; PORTC = div; // gain div = rhex(); // ch if(USART_Timeout()) break; get_sync_wave(div); send_wave(); break; default:; } } if(++cnt > 1000) { PORTB = PINB ^ (1<<4); // blink cnt = 0; } } return 0; }
int main(void) { unsigned char c; /* ----------------- USART Initialization --------------------*/ // BAUD Rate = 9600, F_CPU = 1000000UL, BAUD = F_CPU / (speed * (UBRR+1)) // speed = 16 for standard more (U2X = 0) and speed = 8 for double speed mode (U2X = 1) // So, We can choose UBRR = 6 for standard more (U2X = 0) // or UBRR = 12 for double speed mode (U2X = 1) // Since double speed mode (U2X = 1) provides lower error, we are going // to use it for this configuration. Please check datasheet for more detail // // Set BAUD rate register to generate our desired BAUD 9600 (UBRR = 12) // Enable double speed mode (U2X = 1) // Disable Rx, Tx complete INT, Enable Rx, Tx module // USART as asynchronous mode, No Parity (UPM1:0 = 0), One STOP bit (USBS = 0) // Char Size 8 bit (UCSZ2:0 = 3) /* ------------------------------------------------------------*/ UBRRH = 0; UBRRL = 12; UCSRA |= 0x02; UCSRB |= 0x18; UCSRC |= 0x86; while (1) { // wait until a data receive from PC c = USART_Receive(); // Send the received data back to PC USART_Transmit(c); } }
int main (void) { uint8_t tiles[6] = {0,0,0,0,0,0}, receivedData,i = 0; int quotient; system_init(); ext_usart_clock_init(); ext_usart_pin_init(); ext_usart_init(); configure_console(); printf("Up and running!\r"); while (1) { receivedData = USART_Receive(); quotient = receivedData; i = 0; while(quotient != 0) { tiles[i] = quotient%2; quotient /= 2; i++; } for(int i = 0; i < 6; i++) { printf("%d",tiles[i]); tiles[i] = 0; } printf("\n"); } }
/* Radio control interface */ int menuTask(task* t) { if(USART_HasReceived(0)) { char uInput = USART_Receive(0); switch(uInput) { // Fan case 'f': tempProcess(0x3F); // emulate "?" function button tempProcess(0x32); // emulate "2" function button break; // Enable case 'e': tempProcess(0x3F); // emulate "?" function button tempProcess(0x31); // emulate "2" function button break; default: if(uInput >= '0' && uInput <= '9') { tempProcess(0x30 | (uInput - '0')); } break; } } return 0; }
int main(void) { init_timer(); init_io(); USART_Init(); sei(); fill_cube(0xFF); _delay_us(1500000); int mode = (PIND & (1<<PD3)); if (mode) { while (1) { random_filler(1); random_filler(0); loadbar(); rain(100); send_voxels_rand_z(200); set_edges(); _delay_us(5000000); } } else { int escape = 0; int counter = 0; while (1) { uint8_t byte; byte = USART_Receive(); if (!escape) { if (byte == 0xAB) { // escape character escape = 1; } else if (counter < 64) { tab[counter/8][counter%8] = byte; counter++; } } else { if (byte == 0xCD) { // start character counter = 0; } else if (byte == 0xAB && counter < 64) { tab[counter/8][counter%8] = byte; counter++; } escape = 0; } } } return 0; }
u8 FING_u8HandShake(u8 * Copy_u8ChipAdd) { u8 Local_u8Count ; const u8 Local_u8HndShkArr[7]={0x01,0x00,0x04,0x17,0x00,0x00,0x1C}; u16 Local_u8RxData; TIM0_u8SetTime(500); while(TIM0_u8GetTimFlg()==0); FING_voidSendHeader(); for(Local_u8Count=3 ; Local_u8Count>=0;Local_u8Count--) { USART_Transmit(Copy_u8ChipAdd[Local_u8Count]) ; } for(Local_u8Count=0;Local_u8Count<7;Local_u8Count++) { USART_Transmit(Local_u8HndShkArr[Local_u8Count]); } for(Local_u8Count=0 ; Local_u8Count<10;Local_u8Count++) { USART_Receive(&Local_u8RxData); } TIM0_voiResetTimFlg(); TIM0_voiResetTimer(); return Local_u8RxData ; }
unsigned char receiveData(unsigned char port) { unsigned char temp1 = 2; while(1) { if(USART_HasReceived(port)) { temp1 = USART_Receive(port); return temp1; } } }
__attribute__((noreturn)) void main(void){ cli(); //set-up serial communications DDRD=28;//3 serial pins on d.2 to d.4 d.5 to d.7 contain msbs for flash data d.0 to d.4 is in port C DDRB=62;//serial clocks (B.1 SHCP) (B.2 Latch) (B.3 CE#) (B.4 OE#) (B.5 WE#) UBRR0H=0; UBRR0L=3;//set to 0.5M baud UCSR0A|=2;//double speed aysnc UCSR0B = (1<<RXEN0)|(1<<TXEN0);//Enable receiver and transmitter UCSR0C=6;//async 1 stop bit 8bit char no parity bits _delay_ms(50); StringPgm(PSTR("RDY")); USART_Receive();//wait for handshake char mode = USART_Receive();//wait for mode StringPgm(PSTR("RDY")); serialWrB(readId(0)); uint8_t cap=readId(1); serialWrB(cap); __uint24 capacity=524288L; switch(cap){ case 0xB5: capacity=131072L; case 0xB6: capacity=262144L; break; } if(mode=='W'){ chipErase(); serialWrB('D'); verifyF(capacity); __uint24 x; for (x=0;x<capacity;++x){ pgmB(x,USART_Receive()); serialWrB(readB(x)); } }else if(mode=='R') ReadChip(capacity); while(1); }
int main(void) { mainInit(); printf("test"); int i = 0; uint8_t first; uint8_t second; while(1) { first = 0; second = 0; first = (uint8_t)USART_Receive(); if(first != 0xff && first != 0xaa && first != 0x00) continue; second = (uint8_t)USART_Receive(); if(first == 0xff) SERVO_set(second << 2); if(first == 0xaa) MOTOR_setRef(second); if(first == 0x00 && second == 0x00) SOLENOID_fire(); } }
int main( void ) //Главная функция { USART_Init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); //Скорость соединения 19200 бит/с for(;;) //Вечный цикл { USART_Transmit( USART_Receive() ); //Отправка принятого символа назад } }
int main(void) { DDRB=0xff; // initialize data port(B4 to B7 as o/p pins)... any change in the port will require change of port name in place of PORTB in command and data function defination as well DDRC=0x0f; USART_Init(51); lcd_init(); while(1) { unsigned char a=USART_Receive(); if(a=='A') { command(0x08); string("FORWARD"); PORTC=0x05; } else if(a=='B') { command(0x08); string("BACKWARD"); PORTC=0x0a; } else if(a=='C') { command(0x08); string("LEFT"); PORTC=0x06; } else if(a=='D') { command(0x08); string("RIGHT"); PORTC=0x09; } else if(a=='E') { command(0x08); string("unknown value"); PORTC=0x00; } else { continue; } } }
int main (void) { init_main(); /*wait for first character to be received*/ USART_Receive(0); /*print welcome string*/ USART_printf("Hello there....................\r\n->"); DDRB |= _BV(DDB5); while(1) { /*exec shell*/ shellProcess(); /*exec timer process*/ timing_process(); /*exec led updater*/ ledStringProcess(); /* set pin 5 of PORTB for output*/ // /* set pin 5 high to turn led on */ //PORTB |= _BV(PORTB5); //_delay_ms(BLINK_DELAY_MS*4); /* set pin 5 low to turn led off */ //PORTB &= ~_BV(PORTB5); //_delay_ms(BLINK_DELAY_MS); } return 0; }
u8 FING_u8SetAdd(u8 * Copy_u8ChipOldAdd , u8 * Copy_u8ChipNewAdd) { u8 Local_u8Count,Local_u8CastChkSum ; const u8 Local_u8HndShkArr[4]={0x01,0x00,0x07,0x15}; u16 Local_u16RxData ,Local_u16CastChkSum ; u64 Local_u64ChekSum=0; FING_voidSendHeader(); for(Local_u8Count=3 ; Local_u8Count>=0;Local_u8Count++) { USART_Transmit(Copy_u8ChipOldAdd[Local_u8Count]) ; } for(Local_u8Count=0;Local_u8Count<4;Local_u8Count++) { USART_Transmit(Local_u8HndShkArr[Local_u8Count]); Local_u64ChekSum+=Local_u8HndShkArr[Local_u8Count]; } for(Local_u8Count=3 ; Local_u8Count>=0;Local_u8Count++) { USART_Transmit(Copy_u8ChipNewAdd[Local_u8Count]); Local_u64ChekSum+=Copy_u8ChipNewAdd[Local_u8Count]; } //Cjeck sum calculations Local_u16CastChkSum=(u16)Local_u64ChekSum ; Local_u8CastChkSum=(u8)Local_u64ChekSum ; USART_Transmit(Local_u8CastChkSum); Local_u16CastChkSum>>=8; USART_Transmit(Local_u16CastChkSum); for(Local_u8Count=0 ; Local_u8Count<10;Local_u8Count++) { USART_Receive(&Local_u16RxData); } return Local_u16RxData ; }
int TickFct_D(int state) { // State Transitions switch(state) { case START_D: state = INIT_D; break; // transition to INIT_D state case INIT_D: incoming_data = data_avail = 0; state = WAIT_D; break; // transition to WAIT_D state case WAIT_D: if(USART_HasReceived(0)) { data_avail = 1; // if(!wired) state = READ_D; /*if (USART_IsSendReady(0)) { USART_Send(incoming_data,0); }*/ } else { data_avail = 0; } break; case READ_D: state = WAIT_D; break; default: state = START_D; // error likely happened, restart break; } // State Actions switch(state) { case READ_D: incoming_data = USART_Receive(0); break; default: break; } return state; }
void DataReceive(void) { characBuffer[bufferLength] = USART_Receive(); bufferLength++; if(bufferLength >= 240) { for(int i=0;i<20;i++) characBuffer[i] = 0; bufferLength = 0; } if(bufferLength == 1) { if (characBuffer[0] != '[') { for (int i=0;i<20;i++) { characBuffer[i] = 0; } bufferLength = 0; } } }
int main(void) { port_init(); OledInit (); timer1_init(); adc_init(); USART_Init(0x08); _delay_ms(10); while(1) { USART_Receive();//读取串口数据 Battery_voltage=adc_read(6)/102.40; if (RX_Flag==1) //如果有新数据 { RX_Flag=0; TX_Data=RX_Data; bb++; USART_Transmit(TX_Data); //发送串口数据 } rest(RX_Data); if ((RX_Data==0x00)||(Battery_voltage<7.0)) { off_servo(); if (Battery_voltage<7.0){DisplayChar_16X08(36,2,"~(zzz)~") ;} else{DisplayChar_16X08(36,2,"~(@o@)~") ; } } if ((Battery_voltage>8.0)&&(!(RX_Data==0x00))) {DisplayChar_16X08(36,2,"~(^o^)~") ; } else if ((Battery_voltage>7.0)&&(!(RX_Data==0x00))) {DisplayChar_16X08(36,2,"~(=o=)~") ; } if (RX_Data==0x01)//站立 { open_servo(); robot_stand(0,-90); } if (RX_Data==0x02)//左转 {robot_move(0,0,40,-90,90,100);} if (RX_Data==0x03)//右转 { robot_move(0,0,-40,-90,90,100);} if (RX_Data==0x04)//前进 { robot_move(0,40,0,-90,90,100);} if (RX_Data==0x05)//后退 {robot_move(0,-40,0,-90,90,100);} if (RX_Data==0x06)// {robot_Sur_Place(1,-90,90,100);} if (RX_Data==0x07)// {robot_move(40,0,0,-90,90,100);} if (RX_Data==0x08)// {robot_move(40,0,0,-90,90,100);} if (RX_Data==0x09)// {robot_move(20,20,0,-90,90,100);} //DisplayChar_16X08(36,2,"~(@o@)~") ; Cache_MDigit5(RX_Data,6,0,1 );Cache_MDigit5(Battery_voltage*100,6,88,1 ); // OledDispPicture(0,32,64,512,Expression1);//爱心 // OledDispPicture(0,26,75,600,Expression2);//笑脸 //TODO:: Please write your application code //time_seve++; } }
int main(void) { //setup USART recive UCSR0B = (1<<RXEN0); UCSR0C = (1<<UCSZ00) | (1<<UCSZ01); UBRR0 = 25; // 25 = 2400 baud; 6 = 9600 baud /* Set pins as output, high->output, low->input */ DDRA = 0xFF; /* Pin for LED out */ DDRB = 0xFF; /* Pin for LED out */ DDRC = 0xFF; /* Pin for LED out */ DDRD = 0xFE; /* Pin for LED out */ unsigned char input; unsigned char value; unsigned char control; PORTA = 0xFF; PORTB = 0xFF; PORTC = 0xFF; PORTD = 0xFF; _delay_ms(1000); /* while (1){ clearStates(); lightDisplay(); }*/ /* int i = 0; unsigned int states[4] = {0x27, 0xA0, 0x56, 0xD4}; */ /* while (1) { unsigned char in = USART_Receive(); for (int i = 0; i < 8; i++) { dir[i] = (in>>(7-i))&0x1; } displayDirection(); } */ while(1) { //clearStates(); input = USART_Receive(); //input = 0x27; /* _delay_ms(2000); input = states[i]; i++; i = i%4;*/ control = input & CTRL_MSK; if (input & CMD_BIT) { ctrl[LONG_SIP] = control == LONG_SIP ? ON : OFF; ctrl[LONG_PUFF] = control == LONG_PUFF ? ON : OFF; ctrl[SIP] = control == SIP || ctrl[LONG_SIP] ? ON : OFF; ctrl[PUFF] = control == PUFF || ctrl[LONG_PUFF] ? ON : OFF; } else { clearCtrl(); } value = (input&VAL_MSK) >> 3; if (input & SPD_BIT) { //SPEED clearSpeed(); if (input & NEG_BIT) { //REVERSE spd[0] = ON; } else { //FORWARD switch (value) { default: case 4: spd[4+SPD_OFFSET] = ON; case 3: spd[3+SPD_OFFSET] = ON; case 2: spd[2+SPD_OFFSET] = ON; case 1: spd[1+SPD_OFFSET] = ON; break; case 0: spd[0+SPD_OFFSET] = ON; break; } } displaySpeed(); } else { //DIRECTION clearDir(); if (input & NEG_BIT) { //LEFT switch (value) { default: case 4: dir[DIR_OFFSET+1-4] = ON; case 3: dir[DIR_OFFSET+1-3] = ON; case 2: dir[DIR_OFFSET+1-2] = ON; case 1: dir[DIR_OFFSET+1-1] = ON; break; case 0: break; } } else { //RIGHT switch (value) { default: case 4: dir[4+DIR_OFFSET] = ON; case 3: dir[3+DIR_OFFSET] = ON; case 2: dir[2+DIR_OFFSET] = ON; case 1: dir[1+DIR_OFFSET] = ON; break; case 0: break; } } displayDirection(); } } return 0; }
static int32_t USART1_Receive (void *data, uint32_t num) { return USART_Receive (data, num, &USART1_Resources); }
/** * The main loop which waits for commands via blue tooth and * then acts based on commands received. * * @author Jacob Moyer, * Ed Droesch, * Aaron Pederson, & * Matthew Backes * * @date 12/13/2013 */ void main() { ///Initializes the open_interface struct to be used throughout the program. oi_t *sensor_data = oi_alloc(); oi_init(sensor_data); initializer(); char key =0; ///Waits for commands from the USART connection, ///Then performs the command and returns that the command was performed. while(1) { char message[32] = ""; key = USART_Receive(); ///Returns what the current tape sensor is reading. if (key == 'p') { oi_update(sensor_data); sprintf(message,"sensor->signal =%d\r\n",(int)sensor_data->cliff_frontleft_signal); string_tran(message); } ///Moves the servo motor to the 0 degree position. if(key == 'c') { calibrate_servo(0); } ///Scans 0 - 180 degrees in front of the robot and returns the readings, ///it also guesses where objects are and returns their angle and width. if(key == 'j') { fullScan(); string_tran("Scan Complete.\r\n"); } ///Moves FORWARD_DISTANCE centimeters forward. if(key =='w') { sprintf(message,"Moved %d\r\n",move(sensor_data, FORWARD_DISTANCE,&sensors)); string_tran(message); } ///Moves BACKWARD_DISTANCE centimeters backwards. if(key=='s') { sprintf(message,"Moved %d\r\n",move(sensor_data, BACKWARD_DISTANCE,&sensors)); string_tran(message); } ///Rotates ROTATE_DEGREES counterclockwise. if(key=='a') { turn_CCW(sensor_data,ROTATE_DEGREES); sprintf(message,"Rotated %d\r\n",ROTATE_DEGREES); string_tran(message); } ///Rotates ROTATE_DEGREES clockwise. if(key=='d') { turn_CCW(sensor_data,-ROTATE_DEGREES); sprintf(message,"Rotated %d\r\n",-ROTATE_DEGREES); string_tran(message); } ///Plays the Morrowind theme song. if(key=='r') { play_morrowind(); string_tran("Playing song."); } } }
void mainTick(){ static unsigned char button; static unsigned char pressed; //decrease states for buttonpress button = ~PINA; switch(gameStatus){ case intro: if(GetBit(button,0)){ gameStatus = play; playTime = 0; pressed = 1; currScore = 0; lcdTick(); if(USART_IsSendReady()) USART_Send(0x41); } else if(USART_HasReceived()){ tempMessage = USART_Receive(); if( tempMessage == 0xC1 ){ gameStatus = highscore; playTime = 0; lcdTick(); } else if( tempMessage == 0xC2){ gameStatus = resetHighScore; currHighScore = 0; eeprom_write_byte ((uint8_t*) 46, currHighScore); playTime = 0; lcdTick(); } } else gameStatus = intro; break; case highscore: if(playTime == 500){ gameStatus = intro; lcdTick(); } else gameStatus = highscore; break; case resetHighScore: if(playTime == 500){ gameStatus = intro; lcdTick(); } else gameStatus = resetHighScore; break; case play: if(!(GetBit(button,0) && !pressed) && playTime < 4000 ) gameStatus = play; else if((GetBit(button,0) && !pressed) || playTime == 4000){ gameStatus = gameOver; lcdTick(); playTime = 0; if(currScore > currHighScore){ currHighScore = currScore; eeprom_write_byte ((uint8_t*) 46, currHighScore); } if(USART_IsSendReady()) USART_Send(0x40); } else gameStatus = play; break; case gameOver: if(playTime == 500){ gameStatus = intro; lcdTick(); } else if(playTime < 500) gameStatus = gameOver; else gameStatus = gameOver; break; } switch(gameStatus){ case intro: PORTB = 0; currScore = 0; break; case highscore: playTime++; break; case resetHighScore: playTime++; break; case play: if(!GetBit(button,0)) pressed = 0; playTime++; if(USART_HasReceived()){ tempMessage = USART_Receive(); if(GetBit(tempMessage,7) && !GetBit(tempMessage,6)) if((tempMessage & 0x3F) != currScore) updateScore(tempMessage & 0x3F); } break; case gameOver: playTime++; break; } }
void Tick_Fct(){ distance = read_ultrasonic(); if (USART_HasReceived(0)) { direction = USART_Receive(0); PORTC = direction; } switch(state){//transitions case init: state = start; break; case start: if(direction == 0xFF){ state = wait_impact; }else{ state = controlled; }break; case controlled: if(direction == 0xFF){ state = wait_impact; }else{ count_1 = 0; state = hold_direction; }break; case hold_direction: if(count_1 < 30){ state = hold_direction; }else{ state = reset_direction; } break; case reset_direction: state = controlled; break; case wait_impact: if (direction != 0xFF) { state = controlled; } else if(direction == 0xFF && distance > 30){ state = wait_impact; }else { state = stop_car; count = 0; PORTA = 0x00; } break; case stop_car: if (direction != 0xFF) { state = controlled; } else if(direction == 0xFF && count < 100){ state = stop_car; } else if(direction == 0xFF && !(count < 100)){ state = turn_left; count = 0; } break; case turn_left: if (direction != 0xFF) { state = controlled; } else if(direction == 0xFF && count < 100){ state = turn_left; } else if(direction == 0xFF && !(count < 100)){ state = wait_impact; } break; default: state = init; break; } switch(state){//actions case wait_impact: PORTA = 0x04; break; case stop_car: count++; PORTA = 0x42; break; case turn_left: count++; PORTA = 0x24; break; case start: PORTA = 0x00; break; case controlled: if(direction == 0x0A){ PORTA = 0x00; }else if (direction == 0x01){ PORTA = 0x44;//forward }else if (direction == 0x02){//reverse or backward PORTA = 0x42; }else if (direction == 0x04){//left PORTA = 0x24; }else if(direction == 0x08){//right PORTA = 0x44; } break; case hold_direction: count_1++; break; case reset_direction: PORTA = 0x00; break; default: break; } }
int TickFct_BluetoothReceiver(int state){ switch(state){ case bluetoothWait: if(USART_HasReceived(0) && !bluetoothEnable){ USART_Flush(0); state = bluetoothWait; } else if(USART_HasReceived(0) && bluetoothEnable){ state = bluetoothReceived; position = 0; lastReceivedChar = 0; clearInputPin(); } else{ state = bluetoothWait; } break; case bluetoothReceived: if(!bluetoothEnable){ state = bluetoothWait; } else if(lastReceivedChar != '*'){ state = bluetoothWaitForNext; } else{ state = bluetoothWait; } break; case bluetoothWaitForNext: if(!bluetoothEnable){ state = bluetoothWait; } else if(!USART_HasReceived(0)){ state = bluetoothWaitForNext; } else{ state = bluetoothReceived; } break; default: state = bluetoothWait; break; } switch(state){ case bluetoothWait: break; case bluetoothReceived: while(lastReceivedChar != '*'){ lastReceivedChar = USART_Receive(0); if(lastReceivedChar != '*'){ inputPin[position++] = lastReceivedChar; } else{ inputPin[position] = '\0'; pinInputComplete = 1; } } break; case bluetoothWaitForNext: break; } return state; }
int main(int argc, char *argv[]) { int i=0; int h=0; int bupi=0; cli(); memset(command,'$',58); init(); timer0_init(); timer1_init(); timer3_init(); timer4_init(); timer5_init(); //lcd_init(); //lcd_string("Welcome"); //lcd_move(0,1); //lcdconfig(); //lcd_string("Give me a code:"); //lcd_move(0,2); UART_init(); //adc_init(); //lcdsenddata('F'); //lcd_num(123456); _delay_ms(1500); sei(); while(1) { //-------------------------------------------------scan for input while(mode==0) { while(1)//scan line { if(command[comm]=USART_Receive()) { if((command[comm]==13||command[comm]=='\n'||command[comm]==59)&&(comm<59)) { break; } if(echo==1) { //USART_Transmit('['); // USART_Transmit(comm+48); // USART_Transmit(']'); USART_Transmit(command[comm]); } comm++; } else { } } mode=1; if(echo==1) { USART_String_Transmit("\nTransition to parsing."); } } //-------------------------------------------------parse commands while(mode==1)//parse commands { for(i=0;i<comm;i++)//cycling i till \n-1 { if(command[i]=='N'&&command[i+1]>47&&command[i+1]<58)//GET LINE NUMBER { if(echo) { USART_String_Transmit("\n Getting line number."); } temp_line_number=fetchlong(command,i,'N'); } if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='5')//GET EXTRUDER TEMP { } if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='4')//SET EXTRUDER TEMP FAST SXXX { } if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='9')//SET EXTRUDER TEMP AND WAIT RXXX { } if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='4'&&command[i+3]=='0')//SET BED TEMP FAST SXXX { } if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='9'&&command[i+3]=='0')//WAIT FOR BED TEMP TO HIT RXXX { } if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='7')//FAN OFF { } if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='6')//FAN ON WITH FAN SPEED S255MAX { } if(command[i]=='M'&&command[i+1]=='8'&&command[i+2]=='2'&&command[i+3]==' ')//EXTRUDER TO ABSOLUTE MODE { } if(command[i]=='G'&&command[i+1]=='2'&&command[i+2]=='1'&&command[i+3]==' ')//METRIC VALUES { } if(command[i]=='G'&&command[i+1]=='9'&&command[i+2]=='0'&&command[i+3]==' ')//ABSOLUTE POSITIONING { } if(command[i]=='G'&&command[i+1]=='9'&&command[i+2]=='2'&&command[i+3]==' ')//ZERO EXTRUDED LENGTH WITH E0 otherwise set origin? { } if(command[i]=='G'&&command[i+1]=='0'&&command[i+2]==' ')//MOVE WITHOUT EXTUSION { if(echo) { USART_String_Transmit("\nG0 command."); } line_engine(double_scan_x,double_scan_y,double_scan_z,double_scan_e,i); if((echo==1)&&(xroll==1)&&(yroll=1)) { USART_String_Transmit("\n Xroll=1"); USART_String_Transmit("\n Yroll=1"); } mode==2; } if(command[i]=='G'&&command[i+1]=='1'&&command[i+2]==' ')//MOVE WITH EXTRUSION { } if(command[i]=='Q'&&command[i+1]=='1')//MOTOR TEST { { if(echo) { USART_String_Transmit("\n Motor test on."); //xroll=1; yroll=1; //testval=(threefetchdouble(command,i,'E')/0.01)*16; } } if(command[i]=='Q'&&command[i+1]=='0')//MOTOR TEST { if(echo) { USART_String_Transmit("\n Motor test off."); } //xroll=0; yroll=0; } } mode=2; if(echo) { USART_String_Transmit("\nTransition to set outputs."); } } //-------------------------------------------------setting outputs while(mode==2) { while(zroll==1||eroll==1||xroll==1||yroll==1) { if(USART_Receive()=='.') { zroll=0; eroll=0; xroll=0; yroll=0; USART_String_Transmit("\nSW Emergency stopped, please reset!"); // PINK|=0b00000001; // PINA|=0b00000100; // PINF|=0b00000100; // PIND|=0b10000000; } } if(zroll==0&&eroll==0&&xroll==0&&yroll==0) { if(echo) { USART_String_Transmit("\nTransition to mode 3, reseting parameters."); } mode=3; } } //-------------------------------------------------clear things while(mode==3) { cli(); memset(command,'$',58); comm=0; i=0; double_scan_x=-1.0; double_scan_y=-1.0; double_scan_z=-1.0; double_scan_e=-1.0; if(echo) { USART_String_Transmit("\nParameters reseted returning to scanning mode"); } USART_String_Transmit("\n\rok"); sei(); mode=0; } //------------------------------------------------- while(mode==4) { } } return 0; }