#ifndef F_CPU
#define F_CPU 8000000UL // 16Mhz clock speed
#endif
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
//#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) -1)
#define LED_ON PORTD |= (1<<PIND6);
#define LED_OFF6 PORTD &= ~(1<<PIND6);
volatile unsigned char string[15],x,i =0;
volatile char Reply_CallReady[15]="apple";
volatile char C;
volatile char data[10];
void UART_init(long USART_BAUDRATE)
{
UCSRB |=(1<<RXEN)|(1<<TXEN)|(1<<RXCIE);//TURN ON TRANSMISSION AND RECEPTION.
UCSRC |=(1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);//USE 8 BIT CHARACTER.
UBRRL |=(BAUD_PRESCALE);//LOAD LOWER 8 BITS OF THE BAUD RATE VALUE.
UBRRH |=(BAUD_PRESCALE>>8);//LOAD UPPER 8 BIT.
}
unsigned char UART_Rxchar()
{
while((UCSRA & (1<<RXC))==0);//wait till data is received.
return(UDR);//RETURN THE BYTE.
}
void UART_Txchar(char ch)
{
while (!(UCSRA & (1<<UDRE)));//wait for empty transmit buffer.
UDR=ch;
}
void UART_sendstring(char *str)
{
unsigned char j=0;
while(str[j]!=0) // send string till null.
{
UART_Txchar(str[j]);
j++;
}
}
void lcd_cmd(char cm)
{
char a=cm;
PORTA=a;
PORTB=(0<<PD0)|(0<<PD1)|(1<<PD2);
_delay_ms(50);
PORTB=(0<<PD0)|(0<<PD1)|(0<<PD2);
}
void lcd_data(char dat)
{
char b=dat;
PORTA=b;
PORTB=(1<<PD0)|(0<<PD1)|(1<<PD2);
_delay_ms(50);
PORTB=(1<<PD0)|(0<<PD1)|(0<<PD2);
_delay_ms(50);
}
unsigned char *UART_RX_STR(x)
{
while (x != '\0')
{
string[i++] = x;
}
return string;
}
ISR(USART_RXC_vect)
{
C=UDR;
}
int main()
{
DDRB=0xFF;
DDRA=0xFF;
UART_init(9600);
while(1)
{
C=UART_Rxchar();
x=C;
if (strcmp(string,Reply_CallReady) ==0)
{
LED_ON;
}
else
{
LED_OFF6;
}
}
}