<snipped>
>>// main loop
>>while(1)
>>{
>>//if(bit_is_set(UCSRA,RXC)) outp(inp(UDR),UDR); // read in
character
>>cmd();
>>}
>>
>>return 0;
>>}
>>
>>void cmd(void)
>>{
>>if(bit_is_set(UCSRA,RXC)) outp(inp(UDR),UDR); // read in
character
>>}
>>
If you take a look at the outp and inp macros in iomacros.h, you'll
notice that they're pretty gnarly. Try unnesting the calls:
void cmd(void)
{
volatile unsigned char ch;
if(bit_is_set(UCSRA,RXC))
{
ch = inp(UDR);
outp(ch, UDR);
}
return;
}
This code is untested; however, with convoluted macros such as those,
it is always best to use them in the most simplest manner. I put in the
volatile just in case the optimizer decided to do something flaky with the
variable.
I downloaded the Beta 2 version of AVR GCC for the ATmega128
which includes an optional set of new headers to allow direct assignment
to the registers instead of the inp() and outp() macros. These headers are
great! This is the standard way to access registers on practically all
other compilers and I'm surprised that they weren't done this way until
now (I'm relatively new to the GCC compiler, but have been doing embedded
software for over 7 years).
HTH,
Eric Weddington |