#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;
}

'OpenSTUDY > AVR' 카테고리의 다른 글

CLCD CGRAM  (0) 2011.12.25
ESD110V2  (0) 2011.11.23
I2C (TWI)  (0) 2011.10.18
SPI  (0) 2011.10.15
I2C  (0) 2011.10.15

+ Recent posts