You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

pins_arduino.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. static const uint8_t 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. #ifdef ARDUINO_MAIN
  50. // On the Arduino board, digital pins are also used
  51. // for the analog output (software PWM). Analog input
  52. // pins are a separate set.
  53. // ATMEL ATMEGA8 & 168 / ARDUINO
  54. //
  55. // +-\/-+
  56. // PC6 1| |28 PC5 (AI 5)
  57. // (D 0) PD0 2| |27 PC4 (AI 4)
  58. // (D 1) PD1 3| |26 PC3 (AI 3)
  59. // (D 2) PD2 4| |25 PC2 (AI 2)
  60. // PWM+ (D 3) PD3 5| |24 PC1 (AI 1)
  61. // (D 4) PD4 6| |23 PC0 (AI 0)
  62. // VCC 7| |22 GND
  63. // GND 8| |21 AREF
  64. // PB6 9| |20 AVCC
  65. // PB7 10| |19 PB5 (D 13)
  66. // PWM+ (D 5) PD5 11| |18 PB4 (D 12)
  67. // PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM
  68. // (D 7) PD7 13| |16 PB2 (D 10) PWM
  69. // (D 8) PB0 14| |15 PB1 (D 9) PWM
  70. // +----+
  71. //
  72. // (PWM+ indicates the additional PWM pins on the ATmega168.)
  73. // ATMEL ATMEGA1280 / ARDUINO
  74. //
  75. // 0-7 PE0-PE7 works
  76. // 8-13 PB0-PB5 works
  77. // 14-21 PA0-PA7 works
  78. // 22-29 PH0-PH7 works
  79. // 30-35 PG5-PG0 works
  80. // 36-43 PC7-PC0 works
  81. // 44-51 PJ7-PJ0 works
  82. // 52-59 PL7-PL0 works
  83. // 60-67 PD7-PD0 works
  84. // A0-A7 PF0-PF7
  85. // A8-A15 PK0-PK7
  86. // these arrays map port names (e.g. port B) to the
  87. // appropriate addresses for various functions (e.g. reading
  88. // and writing)
  89. const uint16_t PROGMEM port_to_mode_PGM[] = {
  90. NOT_A_PORT,
  91. NOT_A_PORT,
  92. (uint16_t) &DDRB,
  93. (uint16_t) &DDRC,
  94. (uint16_t) &DDRD,
  95. };
  96. const uint16_t PROGMEM port_to_output_PGM[] = {
  97. NOT_A_PORT,
  98. NOT_A_PORT,
  99. (uint16_t) &PORTB,
  100. (uint16_t) &PORTC,
  101. (uint16_t) &PORTD,
  102. };
  103. const uint16_t PROGMEM port_to_input_PGM[] = {
  104. NOT_A_PORT,
  105. NOT_A_PORT,
  106. (uint16_t) &PINB,
  107. (uint16_t) &PINC,
  108. (uint16_t) &PIND,
  109. };
  110. const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
  111. PD, /* 0 */
  112. PD,
  113. PD,
  114. PD,
  115. PD,
  116. PD,
  117. PD,
  118. PD,
  119. PB, /* 8 */
  120. PB,
  121. PB,
  122. PB,
  123. PB,
  124. PB,
  125. PC, /* 14 */
  126. PC,
  127. PC,
  128. PC,
  129. PC,
  130. PC,
  131. };
  132. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
  133. _BV(0), /* 0, port D */
  134. _BV(1),
  135. _BV(2),
  136. _BV(3),
  137. _BV(4),
  138. _BV(5),
  139. _BV(6),
  140. _BV(7),
  141. _BV(0), /* 8, port B */
  142. _BV(1),
  143. _BV(2),
  144. _BV(3),
  145. _BV(4),
  146. _BV(5),
  147. _BV(0), /* 14, port C */
  148. _BV(1),
  149. _BV(2),
  150. _BV(3),
  151. _BV(4),
  152. _BV(5),
  153. };
  154. const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
  155. NOT_ON_TIMER, /* 0 - port D */
  156. NOT_ON_TIMER,
  157. NOT_ON_TIMER,
  158. // on the ATmega168, digital pin 3 has hardware pwm
  159. #if defined(__AVR_ATmega8__)
  160. NOT_ON_TIMER,
  161. #else
  162. TIMER2B,
  163. #endif
  164. NOT_ON_TIMER,
  165. // on the ATmega168, digital pins 5 and 6 have hardware pwm
  166. #if defined(__AVR_ATmega8__)
  167. NOT_ON_TIMER,
  168. NOT_ON_TIMER,
  169. #else
  170. TIMER0B,
  171. TIMER0A,
  172. #endif
  173. NOT_ON_TIMER,
  174. NOT_ON_TIMER, /* 8 - port B */
  175. TIMER1A,
  176. TIMER1B,
  177. #if defined(__AVR_ATmega8__)
  178. TIMER2,
  179. #else
  180. TIMER2A,
  181. #endif
  182. NOT_ON_TIMER,
  183. NOT_ON_TIMER,
  184. NOT_ON_TIMER,
  185. NOT_ON_TIMER, /* 14 - port C */
  186. NOT_ON_TIMER,
  187. NOT_ON_TIMER,
  188. NOT_ON_TIMER,
  189. NOT_ON_TIMER,
  190. };
  191. #endif
  192. #endif