Hex address numbers for AVR port pins

Hi there,

I'm using a TFT shield on a Mega. But I want to add other features that need the timer pins it normally mates to. So I need to divert some of the shield pins to other Mega pins.

Here's the library section that already maps those shield pins for Mega:

//################################### MEGA2560 ##############################
#elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)       //regular UNO shield on MEGA2560
#define RD_PORT PORTF
#define RD_PIN  0
#define WR_PORT PORTF
#define WR_PIN  1
#define CD_PORT PORTF
#define CD_PIN  2
#define CS_PORT PORTF
#define CS_PIN  3
#define RESET_PORT PORTF
#define RESET_PIN  4

#define EMASK         0x38
#define GMASK         0x20
#define HMASK         0x78
#define write_8(x)   {  PORTH &= ~HMASK; PORTG &= ~GMASK; PORTE &= ~EMASK; \
                        PORTH |= (((x) & (3<<0)) << 5); \
                        PORTE |= (((x) & (3<<2)) << 2); \
                        PORTG |= (((x) & (1<<4)) << 1); \
                        PORTE |= (((x) & (1<<5)) >> 2); \
                        PORTH |= (((x) & (3<<6)) >> 3); \
					 }

#define read_8()      ( ((PINH & (3<<5)) >> 5)\
                      | ((PINE & (3<<4)) >> 2)\
                      | ((PING & (1<<5)) >> 1)\
                      | ((PINE & (1<<3)) << 2)\
                      | ((PINH & (3<<3)) << 3)\
                      )
#define setWriteDir() { DDRH |=  HMASK; DDRG |=  GMASK; DDRE |=  EMASK;  }
#define setReadDir()  { DDRH &= ~HMASK; DDRG &= ~GMASK; DDRE &= ~EMASK;  }
#define write8(x)     { write_8(x); WR_STROBE; }
#define write16(x)    { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst)   { RD_STROBE; dst = read_8(); RD_IDLE; }
#define READ_16(dst)  { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }

#define PIN_LOW(p, b)        (p) &= ~(1<<(b))
#define PIN_HIGH(p, b)       (p) |= (1<<(b))
#define PIN_OUTPUT(p, b)     *(&p-1) |= (1<<(b))

I'd like to change PH3,4,5,6 across to PA3,4,5,6

It seems to begin with the hex addresses where EMASK, GMASK & HMASK are defined.

Firstly - how or where do I find the hex value of all Mega port pins?

I'm hoping if I can find those, it will just be a case of re-mathing the mask offsetting in the read & write functions up there.

Any further advice or unseen catastrophes to point me to?

Thank you!

J

Then you only have to replace HMASK by AMASK and PORTH by PORTA. The values stay all the same in above change.

Remember that you can no more use some of the ADC 1-7 pins which map to port A. See the data sheet for details: 13. I/O-orts.

I don't think that's sufficent. There are more registers of the H-port addressed that have to be changed ( at least PINH and DDRH , as I can see at a first glance ).

Right, I missed to scroll down :frowning:
Find & Replace almost all 'H' by 'A'.

Thanks fellas.

I tried changing all H designations to A and wouldnt compile in sketch where it did fine before. I'll have to check other library files to see where 'PORTH' and friends were defined in the first place. Does that sound like a possible option?

Indeed, you have to change this in all files of the library - if it shows up in more than one file.

It may help to add
#define PORTH PORTA
etc. to a common header file of the library.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.