pins_arduino.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. pins_arduino.h - Pin definition functions for Arduino
  3. Part of Arduino - http://www.arduino.cc/
  4. Copyright (c) 2007 David A. Mellis
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General
  14. Public License along with this library; if not, write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
  18. */
  19. #ifndef Pins_Arduino_h
  20. #define Pins_Arduino_h
  21. #include <avr/pgmspace.h>
  22. #define NUM_DIGITAL_PINS 20
  23. #define NUM_ANALOG_INPUTS 6
  24. #define analogInputToDigitalPin(p) ((p < 6) ? (p) + 14 : -1)
  25. #if defined(__AVR_ATmega8__)
  26. #define digitalPinHasPWM(p) ((p) == 9 || (p) == 10 || (p) == 11)
  27. #else
  28. #define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
  29. #endif
  30. static const uint8_t SS = 10;
  31. static const uint8_t MOSI = 11;
  32. static const uint8_t MISO = 12;
  33. static const uint8_t SCK = 13;
  34. static const uint8_t SDA = 18;
  35. static const uint8_t SCL = 19;
  36. #define LED_BUILTIN 13
  37. static const uint8_t A0 = 14;
  38. static const uint8_t A1 = 15;
  39. static const uint8_t A2 = 16;
  40. static const uint8_t A3 = 17;
  41. static const uint8_t A4 = 18;
  42. static const uint8_t A5 = 19;
  43. static const uint8_t A6 = 20;
  44. static const uint8_t A7 = 21;
  45. #define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0))
  46. #define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
  47. #define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
  48. #define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))
  49. #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT))
  50. #ifdef ARDUINO_MAIN
  51. // On the Arduino board, digital pins are also used
  52. // for the analog output (software PWM). Analog input
  53. // pins are a separate set.
  54. // ATMEL ATMEGA8 & 168 / ARDUINO
  55. //
  56. // +-\/-+
  57. // PC6 1| |28 PC5 (AI 5)
  58. // (D 0) PD0 2| |27 PC4 (AI 4)
  59. // (D 1) PD1 3| |26 PC3 (AI 3)
  60. // (D 2) PD2 4| |25 PC2 (AI 2)
  61. // PWM+ (D 3) PD3 5| |24 PC1 (AI 1)
  62. // (D 4) PD4 6| |23 PC0 (AI 0)
  63. // VCC 7| |22 GND
  64. // GND 8| |21 AREF
  65. // PB6 9| |20 AVCC
  66. // PB7 10| |19 PB5 (D 13)
  67. // PWM+ (D 5) PD5 11| |18 PB4 (D 12)
  68. // PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM
  69. // (D 7) PD7 13| |16 PB2 (D 10) PWM
  70. // (D 8) PB0 14| |15 PB1 (D 9) PWM
  71. // +----+
  72. //
  73. // (PWM+ indicates the additional PWM pins on the ATmega168.)
  74. // ATMEL ATMEGA1280 / ARDUINO
  75. //
  76. // 0-7 PE0-PE7 works
  77. // 8-13 PB0-PB5 works
  78. // 14-21 PA0-PA7 works
  79. // 22-29 PH0-PH7 works
  80. // 30-35 PG5-PG0 works
  81. // 36-43 PC7-PC0 works
  82. // 44-51 PJ7-PJ0 works
  83. // 52-59 PL7-PL0 works
  84. // 60-67 PD7-PD0 works
  85. // A0-A7 PF0-PF7
  86. // A8-A15 PK0-PK7
  87. // these arrays map port names (e.g. port B) to the
  88. // appropriate addresses for various functions (e.g. reading
  89. // and writing)
  90. const uint16_t PROGMEM port_to_mode_PGM[] = {
  91. NOT_A_PORT,
  92. NOT_A_PORT,
  93. (uint16_t) &DDRB,
  94. (uint16_t) &DDRC,
  95. (uint16_t) &DDRD,
  96. };
  97. const uint16_t PROGMEM port_to_output_PGM[] = {
  98. NOT_A_PORT,
  99. NOT_A_PORT,
  100. (uint16_t) &PORTB,
  101. (uint16_t) &PORTC,
  102. (uint16_t) &PORTD,
  103. };
  104. const uint16_t PROGMEM port_to_input_PGM[] = {
  105. NOT_A_PORT,
  106. NOT_A_PORT,
  107. (uint16_t) &PINB,
  108. (uint16_t) &PINC,
  109. (uint16_t) &PIND,
  110. };
  111. const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
  112. PD, /* 0 */
  113. PD,
  114. PD,
  115. PD,
  116. PD,
  117. PD,
  118. PD,
  119. PD,
  120. PB, /* 8 */
  121. PB,
  122. PB,
  123. PB,
  124. PB,
  125. PB,
  126. PC, /* 14 */
  127. PC,
  128. PC,
  129. PC,
  130. PC,
  131. PC,
  132. };
  133. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
  134. _BV(0), /* 0, port D */
  135. _BV(1),
  136. _BV(2),
  137. _BV(3),
  138. _BV(4),
  139. _BV(5),
  140. _BV(6),
  141. _BV(7),
  142. _BV(0), /* 8, port B */
  143. _BV(1),
  144. _BV(2),
  145. _BV(3),
  146. _BV(4),
  147. _BV(5),
  148. _BV(0), /* 14, port C */
  149. _BV(1),
  150. _BV(2),
  151. _BV(3),
  152. _BV(4),
  153. _BV(5),
  154. };
  155. const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
  156. NOT_ON_TIMER, /* 0 - port D */
  157. NOT_ON_TIMER,
  158. NOT_ON_TIMER,
  159. // on the ATmega168, digital pin 3 has hardware pwm
  160. #if defined(__AVR_ATmega8__)
  161. NOT_ON_TIMER,
  162. #else
  163. TIMER2B,
  164. #endif
  165. NOT_ON_TIMER,
  166. // on the ATmega168, digital pins 5 and 6 have hardware pwm
  167. #if defined(__AVR_ATmega8__)
  168. NOT_ON_TIMER,
  169. NOT_ON_TIMER,
  170. #else
  171. TIMER0B,
  172. TIMER0A,
  173. #endif
  174. NOT_ON_TIMER,
  175. NOT_ON_TIMER, /* 8 - port B */
  176. TIMER1A,
  177. TIMER1B,
  178. #if defined(__AVR_ATmega8__)
  179. TIMER2,
  180. #else
  181. TIMER2A,
  182. #endif
  183. NOT_ON_TIMER,
  184. NOT_ON_TIMER,
  185. NOT_ON_TIMER,
  186. NOT_ON_TIMER, /* 14 - port C */
  187. NOT_ON_TIMER,
  188. NOT_ON_TIMER,
  189. NOT_ON_TIMER,
  190. NOT_ON_TIMER,
  191. };
  192. #endif
  193. // These serial port names are intended to allow libraries and architecture-neutral
  194. // sketches to automatically default to the correct port name for a particular type
  195. // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  196. // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  197. //
  198. // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
  199. //
  200. // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
  201. //
  202. // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
  203. //
  204. // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
  205. //
  206. // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
  207. // pins are NOT connected to anything by default.
  208. #define SERIAL_PORT_MONITOR Serial
  209. #define SERIAL_PORT_HARDWARE Serial
  210. #endif