Created
December 10, 2013 13:03
-
-
Save anonymous/7890269 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define F_CPU 16000000UL //Set the frequency of the microcontroller to 16 mhz. If the frequency is different, the corresponding value should be set | |
#include <avr/io.h> | |
#include <util/delay.h> | |
#define USART_BAUDRATE 9600 //Rate of data transfer | |
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) | |
void main() { | |
DDRB = 0xff; | |
char data; | |
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry | |
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes | |
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register | |
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register | |
for (;;) { // Loop forever | |
while ((UCSRA & (1 << RXC)) == 0) {}; // Do nothing until data have been received and is ready to be read from UDR | |
data = UDR; // Fetch the received byte value into the variable "ByteReceived" | |
if(data=='w')//forward condition | |
PORTB=0b00000101; // Both wheels rotate in forward direction and bot is moved forward | |
else if(data=='s')//Backward condition | |
PORTB=0b00001010; | |
else if(data=='a')//Left condition | |
PORTB=0b00001001; | |
else if(data=='d')//Right condition | |
PORTB=0b00000110; | |
else//Default condition | |
PORTB=0b00001111; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment