10.2 Source Code
BLUETOOTH CONTROLLED SOLAR POWERED ROBOT VEHICLE
# define F_CPU 8000000UL#include <avr/io.h>
#include <util/delay.h>
unsigned char rx_char();
void tx_char (unsigned char);
static unsigned char b;
int main()
{
DDRA = 0X00;
PORTA = 0XFF;
DDRB = 0XFF;
PORTB = 0X00;
DDRC = 0XFF;
PORTC = 0X38; //Turn ON the BUZZER for 1sec & Turn OFF the both LED's
_delay_ms (1000);
PORTC = 0X00; // Turn ON the both LED's for 1sec & Turn OFF the BUZZER
_delay_ms (1000);
PORTC = 0X30; // Turn OFF the BUZZER & both LED's
// UART_init...
UBRRL = 51;
UBRRH = 0;
UCSRB = 0X18;
UCSRC = 0X86;
_delay_ms(125);
While (1)
40
{
unsigned char I;
I= rx_char ();
Switch (I)
{
case 'F':
case 'f': PORTC = 0X30;
while ( (UCSRA & 0X80) == 0X80)
{
unsigned char a;
a = (PINA & 0X01);
if (a == 0x00)
{
if (b == 0x00)
{
PORTB = 0X06;
PORTC = 0X20;
_delay_ms (1000);
PORTC = 0X30;
b = 0x01;
}
else
{
PORTB = 0X09;
PORTC = 0X10;
_delay_ms (1000);
41
PORTC = 0X30;
b = 0x00;
}
}
else
{
while ( (a == 0x01) && ((UCSRA & 0X80) == 0X80) )
{
PORTB = 0X05;
}
}
}
break;
case 'B':
case 'b': PORTB = 0X0A;
PORTC = 0X38;
break;
case 'R':
case 'r': PORTB = 0X06;
PORTC = 0X20;
break;
case 'L':
case 'l': PORTB = 0X09;
PORTC = 0X10;
break;
case 'S':
42
case ’s’: PORTC = 0X30;
PORTB = 0X00;
break;
default: PORTB = 0X00;
PORTC = 0X30;
}
}
}
unsigned char rx_char()
{
while((UCSRA&0X80)==0X00);
return(UDR);
}
void tx_char(unsigned char data)
{
while((UCSRA&0X20)==0X00);
UDR=data;
}
if u like the post just say thank u in comment box.
No comments:
Post a Comment
its cool