#define F_CPU 8000000UL
#include<avr/io.h>
#include<util/delay.h>
#include"LCD.h"
#define BAUD 9600
#define MYUBRR (((F_CPU / (BAUD* 16UL))) - 1)
void uart_init();
void transmit( unsigned char data );
unsigned int usart_getch();
uint8_t mybyte;
unsigned char count=0;
int main(void)
{
DDRB|=0xFF;
DDRA|=0xF0;
lcd_init();
uart_init();
while(1)
{
mybyte=usart_getch(); // get data from serial port
lcd_cmd(0xC0);
lcd_data1(mybyte); // write data to LCD
transmit(mybyte); // send data back to the PC (HyperTerminal)
}
return 0;
}
void uart_init()
{
/* Set baud rate */
UBRRH = (uint8_t)(MYUBRR>>8);
UBRRL = (uint8_t)MYUBRR;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
}
void transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) );
/* Put data into buffer, sends the data */
UDR = data;
}
unsigned int usart_getch()
{
while ((UCSRA & (1 << RXC)) == 0);
// Do nothing until data have been received and is ready to be read from UDR
return(UDR); // return the byte
}