1. 76.
    0
    #include<avr/io.h>
    5. include<avr/interrupt.h>
    6. include<util/delay.h>

    7. define MYUBRR 51
    8. define FIFO 8
    volatile unsigned char string[FIFO];
    volatile unsigned char sayici=0;
    volatile unsigned char sayici2=0;

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

    ISR(USART_RXC_vect){

    PORTA=0xff;
    _delay_ms(500);
    PORTA=0x00;

    }

    int main( void )
    {
    unsigned char a;

    DDRA=0xff;

    USART_Init( MYUBRR );

    sei();

    while(1){
    a=USART_Receive();
    USART_Transmit(a);
    }
    }

    void USART_Init(int ubrr)
    {

    /* Set baud rate */
    UBRRH = 0;
    UBRRL = ubrr;

    UCSRA = 0;

    /* Enable receiver and transmitter */
    UCSRB = (1<<RXEN)|(1<<TXEN)|( 1<<RXCIE);

    /* Set frame format: 8data, 1 stop bit */
    UCSRC = (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);
    }

    void USART_Transmit( unsigned char data )
    {
    /* Wait for empty transmit buffer */
    while ( !( UCSRA & (1<<UDRE)) );

    /* Put data into buffer, sends the data */
    UDR = data;
    }

    unsigned char USART_Receive( void )
    {
    /* Wait for data to be received */
    while ( !(UCSRA & (1<<RXC)) );

    /* Get and return received data from buffer */
    return UDR;
    }
    ···
   tümünü göster