[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] direct port access
From: |
E. Weddington |
Subject: |
Re: [avr-gcc-list] direct port access |
Date: |
Wed, 22 Jan 2003 14:58:38 -0700 |
On 22 Jan 2003 at 10:57, Marlin Unruh wrote:
> I have some code that was working with the old style io.h. I am tring
> to get the code working with the new style (#define
> PORTD _SFR_IO8(0x12))
>
> void Pdu1_In_Port(unsigned char* buff)
> {
> unsigned char tmp;
> unsigned char * const iobase = (unsigned char*)0x20;
> unsigned char address;
> address = buff[10]; // get address of port
> if(address < SPL) { // exclude SREG and Stack Pointer Registers
> tmp = *(iobase + address); // read i/o space address
> tmp &= ~buff[6]; // inverted mask low byte AND
> tmp |= (buff[6] & buff[8]); // get data low byte
> *(iobase + address) = tmp; // write i/o space
> }
> } // end of Pdu1_In_Port
>
<snip>
Well you didn't say what the above code is actually doing in it's
error.
But this could be a problem:
if(address < SPL) { // exclude SREG and Stack Pointer Registers
SPL is defined as a _SFR_IO8(..., which is not going to be the same
thing as what your address is declared as. Rewrite as:
if(address < &(SPL))
That way you're comparing a memory address to a memory address.
HTH,
Eric
avr-gcc-list at http://avr1.org