CODE:
#include <tiny2313.h>
#include <stdio.h>
char BluetoothData;
void main(void)
{
UCSRA=0x00;
UCSRB=0x10;
UCSRC=0x06;
UBRRH=0x00;
UBRRL=0x33;
while (1)
{
BluetoothData=UDR;
PORTB.4=1;
if(BluetoothData=='1')
{
PORTB.2=1;
PORTB.3=0;
}
if(BluetoothData=='2')
{
PORTB.2=0;
PORTB.3=1;
}
if(BluetoothData=='a')
{
PORTB.2=0;
PORTB.3=0;
}
if(BluetoothData=='3')
{
PORTB.5=1;
PORTB.6=0;
}
if(BluetoothData=='4')
{
PORTB.5=0;
PORTB.6=1;
}
if(BluetoothData=='b')
{
PORTB.5=0;
PORTB.6=0;
}
if(BluetoothData=='5')
{
PORTB.1=1;
}
if(BluetoothData=='c')
{
PORTB.1=0;
}
};
}
#include <tiny2313.h>
#include <stdio.h>
char BluetoothData;
void main(void)
{
UCSRA=0x00;
UCSRB=0x10;
UCSRC=0x06;
UBRRH=0x00;
UBRRL=0x33;
while (1)
{
BluetoothData=UDR;
PORTB.4=1;
if(BluetoothData=='1')
{
PORTB.2=1;
PORTB.3=0;
}
if(BluetoothData=='2')
{
PORTB.2=0;
PORTB.3=1;
}
if(BluetoothData=='a')
{
PORTB.2=0;
PORTB.3=0;
}
if(BluetoothData=='3')
{
PORTB.5=1;
PORTB.6=0;
}
if(BluetoothData=='4')
{
PORTB.5=0;
PORTB.6=1;
}
if(BluetoothData=='b')
{
PORTB.5=0;
PORTB.6=0;
}
if(BluetoothData=='5')
{
PORTB.1=1;
}
if(BluetoothData=='c')
{
PORTB.1=0;
}
};
}
На PORTB.1 - Фары, PORTB.5; PORTB.6;PORTB.2;PORTB.3 - двигатели, PORTB.4 - вывод enable L293D.
Но работает не очень хорошо, с перебоями. Включенные фары время от времени выключаются, или включаются самостоятельно. Двигатели иногда не выключаются, или включаются не с первого раза.
В чем дело?Есть ли другие способы приема/обработки UART?