avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] Fwd: First step


From: Максим Денисов
Subject: [avr-libc-dev] Fwd: First step
Date: Mon, 08 Feb 2010 00:00:22 +0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.7) Gecko/20100111 Thunderbird/3.0.1



-------- Original Message --------
Subject:        First step
Date:   Sun, 07 Feb 2010 23:34:20 +0600
From:   Максим Денисов <address@hidden>
To:     address@hidden



Hello everyone! Help make the first steps in the avr-libs.

I can not accept data from USART

# define F_CPU 20000000UL

# include<avr/io.h>
# include<avr/interrupt.h>


void port_init (void) (
 PORTA = 0x00;
 DDRA = 0x00;
 PORTB = 0x00;
 DDRB = 0x00;
 PORTD = 0x00;
 DDRD = 0x00;
)


/ / Desired baud rate: 2400
/ / Actual: baud rate: 2399 (0.0%)
void usart_init (void)
(
 UCSRB = 0x00; / / disable while setting baud rate
 UBRRH = 0x02; / / set baud rate upper
 UBRRL = 0x08; / / set baud rate lower
 UCSRA = 0x00;
 UCSRC = 0x06;
 UCSRB = 0x98; / / enable
)


void init_devices (void)
(
 cli (); / / disable all interrupts
 port_init ();
 usart_init ();

 MCUCR = 0x00;
 GIMSK = 0x00;
 TIMSK = 0x00;
 sei (); / / re-enable interrupts
)


void usart_transmit (unsigned char data) (

        while (! (UCSRA&  (1<<UDRE)))
                ;

        UDR = data;
)

unsigned char usart_receive (void) (

        while (! (UCSRA&  (1<<RXC)))
                ;

        return UDR;
)


int main (void) (
unsigned char data;
        init_devices ();

        data = usart_receive ();
        usart_transmit ('+');


        return 0;
)

when sending data from the computer it does not respond.

but the following code works correctly and I get the data from the
controller.


int main (void) (

        init_devices ();

        usart_transmit ('+');

        return 0;
)

why can not I accept this?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]