#include<avr/io.h>
#include<stdio.h>
#define F_CPU 16000000
#include<util/delay.h>
#include <avr/interrupt.h>
static int TxChar(char data, FILE *stream);
static FILE device = FDEV_SETUP_STREAM(TxChar, NULL, _FDEV_SETUP_WRITE);
void UART0_Init(unsigned long BaudRate)
{
UCSR0A = 0x00;
UCSR0B = 0x98;
UCSR0C = 0x06;
UBRR0H = 0x00;
UBRR0L = F_CPU / BaudRate / 16 - 1;
}
int TxChar(char data, FILE * stream)
{
while(!(UCSR0A & (1 << UDRE0)));
UDR0 = data;
return 0;
}
int main()
{
UART0_Init(9600);
stdout = &device;
char data = 0b10101010;
int Color = (data & 0xC0 )>>6;
int Col = ( data & 0x38 ) >> 3;
int Row = ( data & 0x07 ) >> 0;
printf("\n\n\n\r");
printf("\n%d\n", Color);
printf("\n%d\n", Col);
printf("\n%d\n", Row);
return 0;
}