Bluetooth_controlled_robot:
Code:
#include <avr/io.h>
#define F_CPU 8000000ul
#include<util/delay.h>
#define forward 0x14
#define backward 0x28
#define left 0x10
#define right 0x04
#define stop 0x00;
#define motor PORTC
char str[3],i=0;
void serialinit()
{
UCSRB=0x18;
UCSRC=0x86;
UBRRL=0x33;
}
void send(char p)
{
UDR=p;
while(!(UCSRA & (1<<UDRE)));
}
void txstring(char *ptr)
{
while(*ptr)
{
send(*ptr);
ptr++;
}
}
void rxdata()
{
while(!(UCSRA & (1<<RXC)));
char temp=UDR;
str[i++]=temp;
}
int main(void)
{
DDRC=0xff;
serialinit();
while(1)
{
rxdata();
if(str[i-1]=='1')
{
motor=forward;
txstring("Moving Forward\r\n");
i=0;
}
else if(str[i-1]=='2')
{
motor=left;
txstring("Moving left\r\n");
i=0;
}
else if(str[i-1]=='3')
{
motor=right;
txstring("Moving right\r\n");
i=0;
}
else if(str[i-1]=='4')
{
motor=backward;
txstring("Moving Reverse\r\n");
i=0;
}
else if(str[i-1]=='5')
{
motor=stop;
txstring("Stop\r\n");
i=0;
}
}
}
0 comments:
Post a Comment
if you have any doubt please let me know