I am going to write a program for an existing ATmega32 processor and was trying to understand the pin number assignments. As an example the blink program has the following code.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
But the key word is "MOST" and it is a pin number which has a mapping to a processor I/O pin. On the UNO the LED is on pin 19/PB5. I wanted to understand why this was 13 and wanted a way to use an more understandable translation from code to hardware. For example:
// LED connected to PB5.
// give it a name:
int led = PB5;
PB5 is defined in one of the iomXX.h files that depend on the processor.
This would work if PB5 was mapped to the processor's pin used for port B bit 5, but it is not. It is assigned the value of 5.
PA5, PB5, PC5 and PD5 are all assigned the value of 5.
I analyzed the pins_arduino.h files to understand the pin mapping so I could define a value for the pins that would map to the processor's pins. For example on a ATmega32 the following definitions give variable names to the pins. This is not the pin on the microprocessor, but the pin number that the Arduino IDE uses to communicate with the functions like digitalWrite(8,HIGH) with set PinB0 high.
static const uint8_t PinB0 = 8;
static const uint8_t PinB1 = 9;
static const uint8_t PinB2 = 10;
static const uint8_t PinB3 = 11;
static const uint8_t PinB4 = 12;
static const uint8_t PinB5 = 13;
static const uint8_t PinB6 = 14;
static const uint8_t PinB7 = 15;
Using these definitions I can write code that I use to wire up my LED.
// LED connected to PinB5.
// give it a name:
int led = PinB5;
So here is my question. I really wanted the variable name to be PB0, not PinB0 since that is the name the datasheet uses, but that name is already defined in iom32.h.
What is the reason that PBx is defined in iom32.h?
Is there some combination of the pin assignments in iom32.h that I should be using that give me the mapping to the pin number, or is there some documentation that defines the mapping?