after hundred of trials i found that i have a problem with my uart driver which i copied from the data sheet, i'm trying to make the most simple send and receive commands but it's not working. i would highly appreciate it if anyone can help me cuz i'm about to get mad.
UART DRIVER
Code:
#include <avr/io.h>
#include "BASICTYPES.h"
#define BAUD_PRESCALE 25
void UART_Init(void)
{
UBRRL = BAUD_PRESCALE;
UBRRH = (u8)(BAUD_PRESCALE>>8);
UCSRB=(1<<TXEN)|(1<<RXEN);
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}
void UART_SendByte(u8 Data)
{
while(! (UCSRA & (1<<UDRE)));
UDR=Data;
}
u8 UART_ReciveData(void)
{
while(!(UCSRA & (1<<RXC)));
return UDR;
}
void USART_Flush( void )
{
unsigned char dummy;
while ( UCSRA & (1<<RXC) ) dummy = UDR;
}
first uc
Code:
int main(void)
{
keypad_init();
LCD_init();
UART_Init();
_delay_ms(100);
while(1)
{
UART_SendByte(k);
_delay_ms(100);
l=UART_ReciveData();
if (l==CORRECT_PASSWORD)
{
LCD_print("yes");
}
else if(l==WRONG_PASWORD)
{
LCD_print("no");
}
}
}
second uc
Code:
int main(void)
{
UART_Init();
_delay_ms(100);
while(1)
{
g=UART_ReciveData();
_delay_ms(100);
if (g==5)
{
UART_SendByte(CORRECT_PASSWORD);
}
else
{
UART_SendByte(WRONG_PASWORD);
}
}
}