2 pins_arduino.h - Pin definition functions for Arduino
3 Part of Arduino - http://www.arduino.cc/
5 Copyright (c) 2007 David A. Mellis
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General
18 Public License along with this library; if not, write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 Boston, MA 02111-1307 USA
22 $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
25 #ifndef Pins_Arduino_h
26 #define Pins_Arduino_h
28 #include <avr/pgmspace.h>
30 #define NUM_DIGITAL_PINS 20
31 #define NUM_ANALOG_INPUTS 6
32 #define analogInputToDigitalPin(p) ((p < 6) ? (p) + 14 : -1)
34 #if defined(__AVR_ATmega8__)
35 #define digitalPinHasPWM(p) ((p) == 9 || (p) == 10 || (p) == 11)
37 #define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
40 static const uint8_t SS = 10;
41 static const uint8_t MOSI = 11;
42 static const uint8_t MISO = 12;
43 static const uint8_t SCK = 13;
45 static const uint8_t SDA = 18;
46 static const uint8_t SCL = 19;
47 static const uint8_t LED_BUILTIN = 13;
49 static const uint8_t A0 = 14;
50 static const uint8_t A1 = 15;
51 static const uint8_t A2 = 16;
52 static const uint8_t A3 = 17;
53 static const uint8_t A4 = 18;
54 static const uint8_t A5 = 19;
55 static const uint8_t A6 = 20;
56 static const uint8_t A7 = 21;
58 #define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0))
59 #define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
60 #define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
61 #define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))
65 // On the Arduino board, digital pins are also used
66 // for the analog output (software PWM). Analog input
67 // pins are a separate set.
69 // ATMEL ATMEGA8 & 168 / ARDUINO
72 // PC6 1| |28 PC5 (AI 5)
73 // (D 0) PD0 2| |27 PC4 (AI 4)
74 // (D 1) PD1 3| |26 PC3 (AI 3)
75 // (D 2) PD2 4| |25 PC2 (AI 2)
76 // PWM+ (D 3) PD3 5| |24 PC1 (AI 1)
77 // (D 4) PD4 6| |23 PC0 (AI 0)
81 // PB7 10| |19 PB5 (D 13)
82 // PWM+ (D 5) PD5 11| |18 PB4 (D 12)
83 // PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM
84 // (D 7) PD7 13| |16 PB2 (D 10) PWM
85 // (D 8) PB0 14| |15 PB1 (D 9) PWM
88 // (PWM+ indicates the additional PWM pins on the ATmega168.)
90 // ATMEL ATMEGA1280 / ARDUINO
94 // 14-21 PA0-PA7 works
95 // 22-29 PH0-PH7 works
96 // 30-35 PG5-PG0 works
97 // 36-43 PC7-PC0 works
98 // 44-51 PJ7-PJ0 works
99 // 52-59 PL7-PL0 works
100 // 60-67 PD7-PD0 works
105 // these arrays map port names (e.g. port B) to the
106 // appropriate addresses for various functions (e.g. reading
108 const uint16_t PROGMEM port_to_mode_PGM[] = {
116 const uint16_t PROGMEM port_to_output_PGM[] = {
124 const uint16_t PROGMEM port_to_input_PGM[] = {
132 const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
155 const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
156 _BV(0), /* 0, port D */
164 _BV(0), /* 8, port B */
170 _BV(0), /* 14, port C */
178 const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
179 NOT_ON_TIMER, /* 0 - port D */
182 // on the ATmega168, digital pin 3 has hardware pwm
183 #if defined(__AVR_ATmega8__)
189 // on the ATmega168, digital pins 5 and 6 have hardware pwm
190 #if defined(__AVR_ATmega8__)
198 NOT_ON_TIMER, /* 8 - port B */
201 #if defined(__AVR_ATmega8__)
209 NOT_ON_TIMER, /* 14 - port C */