/* * bil.c * * Created: 2014-04-10 14:38:25 * Author: digpi14 */ #include #include #define FORWARDCOMMAND 'W' #define LEFTCOMMAND 'A' #define RIGHTCOMMAND 'D' #define BACKWARDCOMMAND 'S' #define FORWARD 0b00011000 #define BACKWARD 0b00000110 #define LEFT 0b00001010 #define RIGHT 0b00010100 void setupPorts(){ //Sätter 0-1,3 till Output DDRA = 0b00001011; //PA3 ger etta till strömomgörare PORTA = 0b00001001; //Sätter 1-4 till Output(In till H-bryggan) DDRB = 0b00011110; PORTB = 0b00000000; //Har en Outputpå 0 DDRC = 0b00000001; PORTC = 0b00000001; } void Reset(){ PORTB = 0b00000000; } void Backward(){ //IN1 & IN3 (Framåt motor 1 & 2) PORTB = 0b00000000; PORTB = 0b00000110; } void Forward(){ PORTB = 0b00000000; PORTB = 0b00011000; } void Left(){ PORTB = 0b00000000; PORTB = 0b00001010; } void Right(){ PORTB = 0b00000000; PORTB = 0b00010100; } void pressedButtonsHandler(char data){ switch(data){ case FORWARDCOMMAND: Forward(); break; case LEFTCOMMAND: Left(); break; case RIGHTCOMMAND: Right(); break; case BACKWARDCOMMAND: Backward(); break; default: Reset(); break; } } unsigned char USART_Receive ( void ) { while (! (UCSRA & (1<