avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] direct port access


From: Marlin Unruh
Subject: [avr-gcc-list] direct port access
Date: Wed, 22 Jan 2003 10:57:03 -0700
User-agent: KMail/1.4.3

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

buff[6] contains a mask byte sent from the master MCU
buff[8] contains the data sent from the master MCU
buff[10] is the address of the io sent from the master MCU

the buff (buffer) contains the incoming message, and buff[10] contains the io 
address. I am using the tmp register to first read the io space then apply 
the mask and data so as not to change any thing other than to bits maching 
the mask.

should it work with no changes? It's not working at this point. 
I am transfering the address over a CAN BUS to another MCU to change port 
values. That is the reason behind needing to do this.

Marlin

avr-gcc-list at http://avr1.org



reply via email to

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