On Fri, Jul 08, 2011 at 07:28:30AM -0700, ho hoh wrote:
> ???? ?????? ??????
> hi
> your code is not right for this application.
> you can follow this code to arrive to your idea:
> if(UCSRA & 0x80)
> {
> data=getchar();
> }
> code written for ATMEGA16.
> http://up.vatandownload.com/images/c2s9tmogjxqtmw3i2kw.jpg
> I saw you "read USART section of your AVR datasheet carefully" and say you again
> , read your AVR datasheet carefully , you will find your answer.
This is a terrible thing to do: mixing direct access to the USART
registers with canned library routines. Also don't write 0x80, use the
symbolic label from the datasheet. The actual bit may change with a
different flavor of AVR and by using the symbolic label your code stands
a better chance of porting without changes.
If you are going to play with USART bits directly then skip getchar():
if( UCSRA & (1<<RXC) )
data = UDR0;
else
data = -1; // indicate nothing available
The above is all one has to do to read a character from an initialized
USART.
--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.Message
Re: [AVR-Chat] time of getchar
2011-07-08 by David Kelly
Attachments
- No local attachments were found for this message.