I am using an AtTiny167 for a project. The pins have labels like PA7 and PB2. I understand internally how these work, but I don't know how the Arduino library converts a digital pin number such as 0 to a PA or PB bit number to act upon the pin. How is this done? joe
How is this done?
Take a look at Arduino.h. Notice that there are statements like:
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) #define analogInPinToBit(P) (P) #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) ) #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
Write some code to test these macros, to see what they actually do.
Notice, too, that the file includes pins_arduino.h near the bottom. Take a look at that file, too.