Compiling for atmega16 - pin file question

Hi - I followed the steps from here and other tutorials to add an ATMega 16 to the boards in the IDE.
(I downloaded the binary (exported compiled binary) using an AVR ISPMkii programmer under Atmel Studio) - (The Arduino compiler is much friendlier for coding.)
I managed to program a blink sketch, but am trying to understand why Digital 6, is physical pin 20, according to the article at the above url. (it does work that way if I run the code.
The pin file is from here.
This file has these initial definitions:

static const uint8_t SS   = 12;
static const uint8_t MOSI = 13;
static const uint8_t MISO = 14;
static const uint8_t SCK  = 15;

static const uint8_t SDA = 17;
static const uint8_t SCL = 16;
static const uint8_t LED_BUILTIN = 13; // We don't have a built-in LED, but still ..

static const uint8_t A0 = 24;
static const uint8_t A1 = 25;
static const uint8_t A2 = 26;
static const uint8_t A3 = 27;
static const uint8_t A4 = 28;
static const uint8_t A5 = 29;
static const uint8_t A6 = 30;
static const uint8_t A7 = 31;

But these don't seem to agree with any atmega16 package. Further down the dip package pins are drawn graphically correctly. (I am using the Dip package)
I do see that physical pin 20 = PD6 (hence, I suppose digital 6), but I can't quite decode this from the pin file.
Thanks and regards

The Arduino pin number is the index of the arrays in that file.

The digital_pin_to_port_PGM array maps Arduino pin numbers to ports. Check the value of digital_pin_to_port_PGM[6]:


So we now know Arduino pin 6 is PORTD.

The digital_pin_to_bit_mask_PGM array maps the Arduino pin number to bit of the port. Check the value of digital_pin_to_bit_mask_PGM[6]:


In this case it is bit 6, but there is no reason it could not be any other bit number, so don't place any special significance on the match between Arduino pin number and bit number.

1 Like

Ok ,great. Thanks for the info

You are welcome. I'm glad if I was able to be of assistance.