Спойлер
Код: Выделить всё
#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>
#if !defined (F_CPU)
#define F_CPU 8000000
#endif
// --------------
// --- USART0 ---
// --------------
char str[20];
void USART0_Transmit(const unsigned char data)
{
while (!(UCSRA & (1<<UDRE)));
UDR = data;
}
void USART0_TransmitString(const char *data)
{
while (*data) USART0_Transmit(*data++);
}
unsigned char USART0_Receive(void)
{
while (!(UCSRA & (1<<RXC)));
return UDR;
}
char* USART0_ReceiveString(void)//Работает!
{
static char receiverData[20];
unsigned char i = 0;
for(i = 0; i < 20; i++){
receiverData[i] = 0;
}
i = 0;
do{
receiverData[i] = USART0_Receive();
i++;
}while(receiverData[i]);
return receiverData;
}
void USART0_Init(void)
{
// USART0 settings: 9600 baud 8-n-1
// WARNING: real baud = 9615: err = 0,156249999999991%
UBRRH = 0;
UBRRL = 51;
UCSRB = (1<<RXEN) | (1<<TXEN);
UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0);
}
// -------------
// --- ports ---
// -------------
void Ports_Init(void)
{
DDRB = 0; // iiiiiiii
PORTB = 0; // iiiiiiii
DDRC = 0; // -iiiiiii
PORTC = 0; // -iiiiiii
DDRD = 0; // iiiiiiii
PORTD = 0; // iiiiiiii
DDRC = 0;
DDRB = 0;
DDRD = 0;
DDRC |= (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5);
PORTC |= (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5);
DDRB |= 1<<7;
PORTB |= 1<<7;
DDRD |= 1<<5;
PORTD |= 1<<5;
}
// ---------------
// --- ext irq ---
// ---------------
void ExtIrq_Init(void)
{
}
// --------------
// --- main() ---
// --------------
int main()
{
Ports_Init();
ExtIrq_Init();
USART0_Init();
sei(); // enable interrupts
// sample code for USART0
USART0_TransmitString("OK!\r\n");
for (;;)
{
strcpy(str, USART0_ReceiveString() );
USART0_TransmitString(str);
if( strcasecmp(str, "0") == 0) PORTD |= 1<<5;//работает
else if( strcasecmp(str, "1") == 0) PORTD &= ~(1<<5);//работает
else if( strcasecmp(str, "OFF") == 0) PORTD |= 1<<5;
else if( strcasecmp(str, "ON") == 0) PORTD &= ~(1<<5);
}
return 0;
}


only pure true norwegian blackx 
