usart

Embed Size (px)

DESCRIPTION

us

Citation preview

  • 7/17/2019 usart

    1/2

    /** USART.c** Created: 21/04/2015 03:37:23 PM* Author: Toshiba*/

    #include

    void USART_Init(unsigned int ubrr);void USART_Transmit(unsigned char data);unsigned char USART_Receive( void );

    int main(void){

    DDRC=0x03;USART_Init(51);

    while(1) {

    unsigned char a=USART_Receive();if(a=='A')PORTC=0x01;

    else if(a=='B')PORTC=0x02;

    elsePORTC=0x00;

    }}

    // func declaration

    //USART init,transmitt, receivervoid USART_Init( unsigned int ubrr){

    /* Set baud rate */UBRRH = (unsigned char)(ubrr>>8);UBRRL = (unsigned char)ubrr;/* Enable receiver and transmitter */UCSRB = (1

  • 7/17/2019 usart

    2/2

    ;/* Get and return received data from buffer */return UDR;

    }