C:
#define F_CPU 16000000UL
#include<string.h>
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <stdio.h>
void UART_init()
{
UCSRB |= (1 << RXEN)|(1<<TXEN);
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
UBRRL = 0x67;
}
unsigned char UART_RxChar()
{
while ((UCSRA & (1 << RXC)) == 0);
return(UDR);
}
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 (j<=2)
{
UART_TxChar(str[j]);
j++;
}
}
int main(void)
{
static char buff[4];
int i=0,j,k=0;
DDRD =(1<<PD5);
UART_init();
TCCR1A = 0x82;
TCCR1B = 0x1B;
ICR1H = 0x13;
ICR1L = 0x87;
while(1)
{
while(i<=3)
{
buff[I] = UART_RxChar();
if(buff[3] == '!')
{
break;
}
i++;
}
UART_SendString(buff); // for testing whether it is taking the value entered in serial monitor app or not
memset(buff,0, sizeof(buff));
i=0;
_delay_ms(1500);
}
}
Last edited by a moderator: