The maximum values aren't the same.
PORTA is only 3 bits (PB0, PB1, PB2), so its maximum value is 0x7, or 0b111.
PORTB is 8 bits, so its maximum value is 0xFF, or 0b11111111
PORTD is 7 bits, so its maximum value is 0x7F, or 0b1111111
You can add them in either hex or decimal, whichever you prefer. I can convert hex to binary much easier than I can convert decimal to binary, so I use hex.
Think of the values like this: each bit represents one pin. The pins are numbered from highest to lowest, from left to right. So in the case of PORTA, PA2 is controlled by 0bX00 (the bit with the X in it), PA1 is controlled by 0b0X0, and PA0 is controlled by 0b00X. This holds true for PORTB and PORTD as well, they just have more bits.
So, say I wanted to light alternating lights on PORTB, starting on PB0 and finishing on PB6. That corresponds to:
- Code: Select all
PORTB = 0x55
or
0b01010101
If I wanted to do the same on PORTA, I'd do:
- Code: Select all
PORTA = 0x5
or
0b101
And PORTD:
- Code: Select all
PORTD = 0x55
or
0b1010101
PORTA has the smaller value because setting it above 0x7 will either a)do nothing or b) cause an overflow (not sure which).
Unfortunately, C doesn't allow for inputing values in binary, so you'll have to choose hex or decimal.