Pages: [1]   Go Down
Author Topic: questions about Arduino.h code....Plz read  (Read 357 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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))) )
the code above is out of the Arduino.h and these lines of code is where i have the the question.
  1. What is the (P)  mean in the code above and what is it reference too? ex. digitalPinToPort(P)  does it mean port?
  2. what does  digitalPinToPort(P),digitalPinToBitMask(P),digitalPinToTimer(P),analogInPinToBit(P) (P), portOutputRegister(P), portInputRegister(P),  and portModeRegister(P) do?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26328
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

P is simply "pin" or even "parameter".

They're all just mapping macros, to allow consistent Arduino pin numbering across various AVR ports, independent of processor.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 70
Posts: 2171
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

read up on c++ macros and defines

the '(p)' is a parameter for the macro, like a function parameter, but not the same.

These macros convert 'virtual' arduino pin numbers to actual avr ports registers and the respective pin bits inside the registers ( 8-bit register can represent 8 unique pins )

Or what AWOL said.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your answer
Logged

Pages: [1]   Go Up
Jump to: