Arduino  1.8.10
Arduino.h ファイル
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "binary.h"
#include "pins_arduino.h"

[ソースコード]

マクロ定義

#define HIGH   0x1
 
#define LOW   0x0
 
#define INPUT   0x0
 
#define OUTPUT   0x1
 
#define INPUT_PULLUP   0x2
 
#define PI   3.1415926535897932384626433832795
 
#define HALF_PI   1.5707963267948966192313216916398
 
#define TWO_PI   6.283185307179586476925286766559
 
#define DEG_TO_RAD   0.017453292519943295769236907684886
 
#define RAD_TO_DEG   57.295779513082320876798154814105
 
#define EULER   2.718281828459045235360287471352
 
#define SERIAL   0x0
 
#define DISPLAY   0x1
 
#define LSBFIRST   0
 
#define MSBFIRST   1
 
#define CHANGE   1
 
#define FALLING   2
 
#define RISING   3
 
#define INTERNAL   3
 
#define DEFAULT   1
 
#define EXTERNAL   0
 
#define min(a, b)   ((a)<(b)?(a):(b))
 
#define max(a, b)   ((a)>(b)?(a):(b))
 
#define abs(x)   ((x)>0?(x):-(x))
 
#define constrain(amt, low, high)   ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
 
#define round(x)   ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
 
#define radians(deg)   ((deg)*DEG_TO_RAD)
 
#define degrees(rad)   ((rad)*RAD_TO_DEG)
 
#define sq(x)   ((x)*(x))
 
#define interrupts()   sei()
 
#define noInterrupts()   cli()
 
#define clockCyclesPerMicrosecond()   ( F_CPU / 1000000L )
 
#define clockCyclesToMicroseconds(a)   ( (a) / clockCyclesPerMicrosecond() )
 
#define microsecondsToClockCycles(a)   ( (a) * clockCyclesPerMicrosecond() )
 
#define lowByte(w)   ((uint8_t) ((w) & 0xff))
 
#define highByte(w)   ((uint8_t) ((w) >> 8))
 
#define bitRead(value, bit)   (((value) >> (bit)) & 0x01)
 
#define bitSet(value, bit)   ((value) |= (1UL << (bit)))
 
#define bitClear(value, bit)   ((value) &= ~(1UL << (bit)))
 
#define bitWrite(value, bit, bitvalue)   (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
 
#define _NOP()   do { __asm__ volatile ("nop"); } while (0)
 
#define bit(b)   (1UL << (b))
 
#define analogInPinToBit(P)   (P)
 
#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))) )
 
#define NOT_A_PIN   0
 
#define NOT_A_PORT   0
 
#define NOT_AN_INTERRUPT   -1
 
#define NOT_ON_TIMER   0
 
#define TIMER0A   1
 
#define TIMER0B   2
 
#define TIMER1A   3
 
#define TIMER1B   4
 
#define TIMER1C   5
 
#define TIMER2   6
 
#define TIMER2A   7
 
#define TIMER2B   8
 
#define TIMER3A   9
 
#define TIMER3B   10
 
#define TIMER3C   11
 
#define TIMER4A   12
 
#define TIMER4B   13
 
#define TIMER4C   14
 
#define TIMER4D   15
 
#define TIMER5A   16
 
#define TIMER5B   17
 
#define TIMER5C   18
 

型定義

typedef unsigned int word
 
typedef bool boolean
 
typedef uint8_t byte
 

関数

void yield (void)
 
void init (void)
 
void initVariant (void)
 
int atexit (void(*func)()) __attribute__((weak))
 
void pinMode (uint8_t, uint8_t)
 
void digitalWrite (uint8_t, uint8_t)
 
int digitalRead (uint8_t)
 
int analogRead (uint8_t)
 
void analogReference (uint8_t mode)
 
void analogWrite (uint8_t, int)
 
unsigned long millis (void)
 
unsigned long micros (void)
 
void delay (unsigned long)
 
void delayMicroseconds (unsigned int us)
 
unsigned long pulseIn (uint8_t pin, uint8_t state, unsigned long timeout)
 
unsigned long pulseInLong (uint8_t pin, uint8_t state, unsigned long timeout)
 
void shiftOut (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
 
uint8_t shiftIn (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
 
void attachInterrupt (uint8_t, void(*)(void), int mode)
 
void detachInterrupt (uint8_t)
 
void setup (void)
 
void loop (void)
 

変数

const uint16_t PROGMEM port_to_mode_PGM []
 
const uint16_t PROGMEM port_to_input_PGM []
 
const uint16_t PROGMEM port_to_output_PGM []
 
const uint8_t PROGMEM digital_pin_to_port_PGM []
 
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM []
 
const uint8_t PROGMEM digital_pin_to_timer_PGM []
 

マクロ定義詳解

◆ _NOP

#define _NOP ( )    do { __asm__ volatile ("nop"); } while (0)

Arduino.h118 行目に定義があります。

◆ abs

#define abs (   x)    ((x)>0?(x):-(x))

Arduino.h94 行目に定義があります。

◆ analogInPinToBit [1/2]

#define analogInPinToBit (   P)    (P)

Arduino.h180 行目に定義があります。

◆ analogInPinToBit [2/2]

#define analogInPinToBit (   P)    (P)

Arduino.h180 行目に定義があります。

◆ bit

#define bit (   b)    (1UL << (b))

Arduino.h123 行目に定義があります。

◆ bitClear

#define bitClear (   value,
  bit 
)    ((value) &= ~(1UL << (bit)))

Arduino.h113 行目に定義があります。

◆ bitRead

#define bitRead (   value,
  bit 
)    (((value) >> (bit)) & 0x01)

Arduino.h111 行目に定義があります。

◆ bitSet

#define bitSet (   value,
  bit 
)    ((value) |= (1UL << (bit)))

Arduino.h112 行目に定義があります。

◆ bitWrite

#define bitWrite (   value,
  bit,
  bitvalue 
)    (bitvalue ? bitSet(value, bit) : bitClear(value, bit))

Arduino.h114 行目に定義があります。

◆ CHANGE

#define CHANGE   1

Arduino.h60 行目に定義があります。

◆ clockCyclesPerMicrosecond

#define clockCyclesPerMicrosecond ( )    ( F_CPU / 1000000L )

Arduino.h104 行目に定義があります。

◆ clockCyclesToMicroseconds

#define clockCyclesToMicroseconds (   a)    ( (a) / clockCyclesPerMicrosecond() )

Arduino.h105 行目に定義があります。

◆ constrain

#define constrain (   amt,
  low,
  high 
)    ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))

Arduino.h95 行目に定義があります。

◆ DEFAULT

#define DEFAULT   1

Arduino.h83 行目に定義があります。

◆ DEG_TO_RAD

#define DEG_TO_RAD   0.017453292519943295769236907684886

Arduino.h50 行目に定義があります。

◆ degrees

#define degrees (   rad)    ((rad)*RAD_TO_DEG)

Arduino.h98 行目に定義があります。

◆ digitalPinToBitMask

#define digitalPinToBitMask (   P)    ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )

Arduino.h178 行目に定義があります。

◆ digitalPinToPort

#define digitalPinToPort (   P)    ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )

Arduino.h177 行目に定義があります。

◆ digitalPinToTimer

#define digitalPinToTimer (   P)    ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )

Arduino.h179 行目に定義があります。

◆ DISPLAY

#define DISPLAY   0x1

Arduino.h55 行目に定義があります。

◆ EULER

#define EULER   2.718281828459045235360287471352

Arduino.h52 行目に定義があります。

◆ EXTERNAL

#define EXTERNAL   0

Arduino.h84 行目に定義があります。

◆ FALLING

#define FALLING   2

Arduino.h61 行目に定義があります。

◆ HALF_PI

#define HALF_PI   1.5707963267948966192313216916398

Arduino.h48 行目に定義があります。

◆ HIGH

#define HIGH   0x1

Arduino.h40 行目に定義があります。

◆ highByte

#define highByte (   w)    ((uint8_t) ((w) >> 8))

Arduino.h109 行目に定義があります。

◆ INPUT

#define INPUT   0x0

Arduino.h43 行目に定義があります。

◆ INPUT_PULLUP

#define INPUT_PULLUP   0x2

Arduino.h45 行目に定義があります。

◆ INTERNAL

#define INTERNAL   3

Arduino.h81 行目に定義があります。

◆ interrupts

#define interrupts ( )    sei()

Arduino.h101 行目に定義があります。

◆ LOW

#define LOW   0x0

Arduino.h41 行目に定義があります。

◆ lowByte

#define lowByte (   w)    ((uint8_t) ((w) & 0xff))

Arduino.h108 行目に定義があります。

◆ LSBFIRST

#define LSBFIRST   0

Arduino.h57 行目に定義があります。

◆ max

#define max (   a,
 
)    ((a)>(b)?(a):(b))

Arduino.h93 行目に定義があります。

◆ microsecondsToClockCycles

#define microsecondsToClockCycles (   a)    ( (a) * clockCyclesPerMicrosecond() )

Arduino.h106 行目に定義があります。

◆ min

#define min (   a,
 
)    ((a)<(b)?(a):(b))

Arduino.h92 行目に定義があります。

◆ MSBFIRST

#define MSBFIRST   1

Arduino.h58 行目に定義があります。

◆ noInterrupts

#define noInterrupts ( )    cli()

Arduino.h102 行目に定義があります。

◆ NOT_A_PIN

#define NOT_A_PIN   0

Arduino.h185 行目に定義があります。

◆ NOT_A_PORT

#define NOT_A_PORT   0

Arduino.h186 行目に定義があります。

◆ NOT_AN_INTERRUPT

#define NOT_AN_INTERRUPT   -1

Arduino.h188 行目に定義があります。

◆ NOT_ON_TIMER

#define NOT_ON_TIMER   0

Arduino.h204 行目に定義があります。

◆ OUTPUT

#define OUTPUT   0x1

Arduino.h44 行目に定義があります。

◆ PI

#define PI   3.1415926535897932384626433832795

Arduino.h47 行目に定義があります。

◆ portInputRegister

#define portInputRegister (   P)    ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )

Arduino.h182 行目に定義があります。

◆ portModeRegister

#define portModeRegister (   P)    ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )

Arduino.h183 行目に定義があります。

◆ portOutputRegister

#define portOutputRegister (   P)    ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )

Arduino.h181 行目に定義があります。

◆ RAD_TO_DEG

#define RAD_TO_DEG   57.295779513082320876798154814105

Arduino.h51 行目に定義があります。

◆ radians

#define radians (   deg)    ((deg)*DEG_TO_RAD)

Arduino.h97 行目に定義があります。

◆ RISING

#define RISING   3

Arduino.h62 行目に定義があります。

◆ round

#define round (   x)    ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))

Arduino.h96 行目に定義があります。

◆ SERIAL

#define SERIAL   0x0

Arduino.h54 行目に定義があります。

◆ sq

#define sq (   x)    ((x)*(x))

Arduino.h99 行目に定義があります。

◆ TIMER0A

#define TIMER0A   1

Arduino.h205 行目に定義があります。

◆ TIMER0B

#define TIMER0B   2

Arduino.h206 行目に定義があります。

◆ TIMER1A

#define TIMER1A   3

Arduino.h207 行目に定義があります。

◆ TIMER1B

#define TIMER1B   4

Arduino.h208 行目に定義があります。

◆ TIMER1C

#define TIMER1C   5

Arduino.h209 行目に定義があります。

◆ TIMER2

#define TIMER2   6

Arduino.h210 行目に定義があります。

◆ TIMER2A

#define TIMER2A   7

Arduino.h211 行目に定義があります。

◆ TIMER2B

#define TIMER2B   8

Arduino.h212 行目に定義があります。

◆ TIMER3A

#define TIMER3A   9

Arduino.h214 行目に定義があります。

◆ TIMER3B

#define TIMER3B   10

Arduino.h215 行目に定義があります。

◆ TIMER3C

#define TIMER3C   11

Arduino.h216 行目に定義があります。

◆ TIMER4A

#define TIMER4A   12

Arduino.h217 行目に定義があります。

◆ TIMER4B

#define TIMER4B   13

Arduino.h218 行目に定義があります。

◆ TIMER4C

#define TIMER4C   14

Arduino.h219 行目に定義があります。

◆ TIMER4D

#define TIMER4D   15

Arduino.h220 行目に定義があります。

◆ TIMER5A

#define TIMER5A   16

Arduino.h221 行目に定義があります。

◆ TIMER5B

#define TIMER5B   17

Arduino.h222 行目に定義があります。

◆ TIMER5C

#define TIMER5C   18

Arduino.h223 行目に定義があります。

◆ TWO_PI

#define TWO_PI   6.283185307179586476925286766559

Arduino.h49 行目に定義があります。

型定義詳解

◆ boolean

typedef bool boolean

Arduino.h125 行目に定義があります。

◆ byte

typedef uint8_t byte

Arduino.h126 行目に定義があります。

◆ word

typedef unsigned int word

Arduino.h121 行目に定義があります。

関数詳解

◆ analogRead()

int analogRead ( uint8_t  )

wiring_analog.c38 行目に定義があります。

39 {
40  uint8_t low, high;
41 
42 #if defined(analogPinToChannel)
43 #if defined(__AVR_ATmega32U4__)
44  if (pin >= 18) pin -= 18; // allow for channel or pin numbers
45 #endif
46  pin = analogPinToChannel(pin);
47 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
48  if (pin >= 54) pin -= 54; // allow for channel or pin numbers
49 #elif defined(__AVR_ATmega32U4__)
50  if (pin >= 18) pin -= 18; // allow for channel or pin numbers
51 #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
52  if (pin >= 24) pin -= 24; // allow for channel or pin numbers
53 #else
54  if (pin >= 14) pin -= 14; // allow for channel or pin numbers
55 #endif
56 
57 #if defined(ADCSRB) && defined(MUX5)
58  // the MUX5 bit of ADCSRB selects whether we're reading from channels
59  // 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
60  ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
61 #endif
62 
63  // set the analog reference (high two bits of ADMUX) and select the
64  // channel (low 4 bits). this also sets ADLAR (left-adjust result)
65  // to 0 (the default).
66 #if defined(ADMUX)
67 #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
68  ADMUX = (analog_reference << 4) | (pin & 0x07);
69 #else
70  ADMUX = (analog_reference << 6) | (pin & 0x07);
71 #endif
72 #endif
73 
74  // without a delay, we seem to read from the wrong channel
75  //delay(1);
76 
77 #if defined(ADCSRA) && defined(ADCL)
78  // start the conversion
79  sbi(ADCSRA, ADSC);
80 
81  // ADSC is cleared when the conversion finishes
82  while (bit_is_set(ADCSRA, ADSC));
83 
84  // we have to read ADCL first; doing so locks both ADCL
85  // and ADCH until ADCH is read. reading ADCL second would
86  // cause the results of each conversion to be discarded,
87  // as ADCL and ADCH would be locked when it completed.
88  low = ADCL;
89  high = ADCH;
90 #else
91  // we dont have an ADC, return 0
92  low = 0;
93  high = 0;
94 #endif
95 
96  // combine the two bytes
97  return (high << 8) | low;
98 }
#define ADCL
Definition: io2333.h:60
#define ADCSRA
Definition: io90pwm1.h:551
#define analogPinToChannel(P)
Definition: pins_arduino.h:134
#define ADCH
Definition: io2333.h:61
#define bit_is_set(sfr, bit)
Definition: sfr_defs.h:234
uint8_t analog_reference
Definition: wiring_analog.c:28
#define sbi(sfr, bit)
Definition: ATmegaBOOT.c:75
#define ADSC
Definition: io2333.h:359
#define ADMUX
Definition: io2333.h:67
#define ADCSRB
Definition: io90pwm1.h:563
#define low(sfr, bit)
#define MUX5
Definition: iom1284rfr2.h:813
#define high(sfr, bit)

◆ analogReference()

void analogReference ( uint8_t  mode)

wiring_analog.c30 行目に定義があります。

31 {
32  // can't actually set the register here because the default setting
33  // will connect AVCC and the AREF pin, which would cause a short if
34  // there's something connected to AREF.
35  analog_reference = mode;
36 }
uint8_t analog_reference
Definition: wiring_analog.c:28

◆ analogWrite()

void analogWrite ( uint8_t  ,
int   
)

wiring_analog.c104 行目に定義があります。

105 {
106  // We need to make sure the PWM output is enabled for those pins
107  // that support it, as we turn it off when digitally reading or
108  // writing with them. Also, make sure the pin is in output mode
109  // for consistenty with Wiring, which doesn't require a pinMode
110  // call for the analog output pins.
111  pinMode(pin, OUTPUT);
112  if (val == 0)
113  {
114  digitalWrite(pin, LOW);
115  }
116  else if (val == 255)
117  {
118  digitalWrite(pin, HIGH);
119  }
120  else
121  {
122  switch(digitalPinToTimer(pin))
123  {
124  // XXX fix needed for atmega8
125  #if defined(TCCR0) && defined(COM00) && !defined(__AVR_ATmega8__)
126  case TIMER0A:
127  // connect pwm to pin on timer 0
128  sbi(TCCR0, COM00);
129  OCR0 = val; // set pwm duty
130  break;
131  #endif
132 
133  #if defined(TCCR0A) && defined(COM0A1)
134  case TIMER0A:
135  // connect pwm to pin on timer 0, channel A
136  sbi(TCCR0A, COM0A1);
137  OCR0A = val; // set pwm duty
138  break;
139  #endif
140 
141  #if defined(TCCR0A) && defined(COM0B1)
142  case TIMER0B:
143  // connect pwm to pin on timer 0, channel B
144  sbi(TCCR0A, COM0B1);
145  OCR0B = val; // set pwm duty
146  break;
147  #endif
148 
149  #if defined(TCCR1A) && defined(COM1A1)
150  case TIMER1A:
151  // connect pwm to pin on timer 1, channel A
152  sbi(TCCR1A, COM1A1);
153  OCR1A = val; // set pwm duty
154  break;
155  #endif
156 
157  #if defined(TCCR1A) && defined(COM1B1)
158  case TIMER1B:
159  // connect pwm to pin on timer 1, channel B
160  sbi(TCCR1A, COM1B1);
161  OCR1B = val; // set pwm duty
162  break;
163  #endif
164 
165  #if defined(TCCR1A) && defined(COM1C1)
166  case TIMER1C:
167  // connect pwm to pin on timer 1, channel B
168  sbi(TCCR1A, COM1C1);
169  OCR1C = val; // set pwm duty
170  break;
171  #endif
172 
173  #if defined(TCCR2) && defined(COM21)
174  case TIMER2:
175  // connect pwm to pin on timer 2
176  sbi(TCCR2, COM21);
177  OCR2 = val; // set pwm duty
178  break;
179  #endif
180 
181  #if defined(TCCR2A) && defined(COM2A1)
182  case TIMER2A:
183  // connect pwm to pin on timer 2, channel A
184  sbi(TCCR2A, COM2A1);
185  OCR2A = val; // set pwm duty
186  break;
187  #endif
188 
189  #if defined(TCCR2A) && defined(COM2B1)
190  case TIMER2B:
191  // connect pwm to pin on timer 2, channel B
192  sbi(TCCR2A, COM2B1);
193  OCR2B = val; // set pwm duty
194  break;
195  #endif
196 
197  #if defined(TCCR3A) && defined(COM3A1)
198  case TIMER3A:
199  // connect pwm to pin on timer 3, channel A
200  sbi(TCCR3A, COM3A1);
201  OCR3A = val; // set pwm duty
202  break;
203  #endif
204 
205  #if defined(TCCR3A) && defined(COM3B1)
206  case TIMER3B:
207  // connect pwm to pin on timer 3, channel B
208  sbi(TCCR3A, COM3B1);
209  OCR3B = val; // set pwm duty
210  break;
211  #endif
212 
213  #if defined(TCCR3A) && defined(COM3C1)
214  case TIMER3C:
215  // connect pwm to pin on timer 3, channel C
216  sbi(TCCR3A, COM3C1);
217  OCR3C = val; // set pwm duty
218  break;
219  #endif
220 
221  #if defined(TCCR4A)
222  case TIMER4A:
223  //connect pwm to pin on timer 4, channel A
224  sbi(TCCR4A, COM4A1);
225  #if defined(COM4A0) // only used on 32U4
226  cbi(TCCR4A, COM4A0);
227  #endif
228  OCR4A = val; // set pwm duty
229  break;
230  #endif
231 
232  #if defined(TCCR4A) && defined(COM4B1)
233  case TIMER4B:
234  // connect pwm to pin on timer 4, channel B
235  sbi(TCCR4A, COM4B1);
236  OCR4B = val; // set pwm duty
237  break;
238  #endif
239 
240  #if defined(TCCR4A) && defined(COM4C1)
241  case TIMER4C:
242  // connect pwm to pin on timer 4, channel C
243  sbi(TCCR4A, COM4C1);
244  OCR4C = val; // set pwm duty
245  break;
246  #endif
247 
248  #if defined(TCCR4C) && defined(COM4D1)
249  case TIMER4D:
250  // connect pwm to pin on timer 4, channel D
251  sbi(TCCR4C, COM4D1);
252  #if defined(COM4D0) // only used on 32U4
253  cbi(TCCR4C, COM4D0);
254  #endif
255  OCR4D = val; // set pwm duty
256  break;
257  #endif
258 
259 
260  #if defined(TCCR5A) && defined(COM5A1)
261  case TIMER5A:
262  // connect pwm to pin on timer 5, channel A
263  sbi(TCCR5A, COM5A1);
264  OCR5A = val; // set pwm duty
265  break;
266  #endif
267 
268  #if defined(TCCR5A) && defined(COM5B1)
269  case TIMER5B:
270  // connect pwm to pin on timer 5, channel B
271  sbi(TCCR5A, COM5B1);
272  OCR5B = val; // set pwm duty
273  break;
274  #endif
275 
276  #if defined(TCCR5A) && defined(COM5C1)
277  case TIMER5C:
278  // connect pwm to pin on timer 5, channel C
279  sbi(TCCR5A, COM5C1);
280  OCR5C = val; // set pwm duty
281  break;
282  #endif
283 
284  case NOT_ON_TIMER:
285  default:
286  if (val < 128) {
287  digitalWrite(pin, LOW);
288  } else {
289  digitalWrite(pin, HIGH);
290  }
291  }
292  }
293 }
#define TCCR3A
Definition: iocanxx.h:274
#define OCR0
Definition: ioat94k.h:175
#define TIMER4B
Definition: Arduino.h:218
void pinMode(uint8_t, uint8_t)
#define COM4D0
Definition: iom16u4.h:962
#define COM2A1
Definition: io90scr100.h:994
#define COM1B1
Definition: io43u32x.h:226
#define digitalPinToTimer(P)
Definition: Arduino.h:179
#define OCR3C
Definition: iocanxx.h:303
#define COM0A1
Definition: io90pwm1.h:290
#define COM1C1
Definition: iocanxx.h:808
#define OCR5B
Definition: iom1284rfr2.h:1793
#define TCCR1A
Definition: pins_arduino.h:68
#define COM4A1
Definition: iom1284rfr2.h:976
#define COM4A0
Definition: iom1284rfr2.h:975
#define TIMER2A
Definition: Arduino.h:211
#define TCCR5A
Definition: iom1284rfr2.h:1748
#define COM00
Definition: io76c711.h:192
#define TIMER0A
Definition: Arduino.h:205
#define sbi(sfr, bit)
Definition: ATmegaBOOT.c:75
#define TIMER2B
Definition: Arduino.h:212
#define TCCR4C
Definition: iom1284rfr2.h:987
#define COM21
Definition: io4434.h:355
void digitalWrite(uint8_t, uint8_t)
#define TCCR2
Definition: io4434.h:149
#define TCCR2A
Definition: io90scr100.h:988
#define OCR4A
Definition: iom1284rfr2.h:1007
#define COM2B1
Definition: io90scr100.h:992
#define OCR0A
Definition: io90pwm1.h:320
#define COM5B1
Definition: iom1284rfr2.h:1754
#define OCR3B
Definition: iocanxx.h:298
#define OCR2A
Definition: io90scr100.h:1014
#define TIMER1B
Definition: Arduino.h:208
#define TIMER1A
Definition: Arduino.h:207
#define OCR1A
Definition: io2313.h:107
#define TIMER2
Definition: Arduino.h:210
#define TIMER0B
Definition: Arduino.h:206
#define TCCR0
Definition: io1200.h:93
#define OCR4D
Definition: iom16u4.h:1092
#define COM3B1
Definition: iocanxx.h:818
#define TIMER1C
Definition: Arduino.h:209
#define TIMER4C
Definition: Arduino.h:219
#define COM1A1
Definition: io2313.h:240
#define OCR4C
Definition: iom1284rfr2.h:1019
#define TIMER5B
Definition: Arduino.h:222
#define COM0B1
Definition: io90pwm1.h:292
#define cbi(sfr, bit)
Definition: ATmegaBOOT.c:72
#define LOW
Definition: Arduino.h:41
#define HIGH
Definition: Arduino.h:40
#define OCR1B
Definition: io43u32x.h:132
#define TCCR4A
Definition: iom1284rfr2.h:968
#define OUTPUT
Definition: Arduino.h:44
#define COM5C1
Definition: iom1284rfr2.h:1752
#define OCR1C
Definition: iocanxx.h:269
#define OCR5A
Definition: iom1284rfr2.h:1787
#define COM3C1
Definition: iocanxx.h:820
#define OCR2
Definition: io4434.h:143
#define NOT_ON_TIMER
Definition: Arduino.h:204
#define OCR5C
Definition: iom1284rfr2.h:1799
#define OCR0B
Definition: io90pwm1.h:332
#define TIMER3B
Definition: Arduino.h:215
#define COM4D1
Definition: iom16u4.h:963
#define TIMER5C
Definition: Arduino.h:223
#define TIMER4A
Definition: Arduino.h:217
#define COM4B1
Definition: iom1284rfr2.h:974
#define TIMER4D
Definition: Arduino.h:220
#define TIMER5A
Definition: Arduino.h:221
#define COM3A1
Definition: iocanxx.h:816
#define COM4C1
Definition: iom1284rfr2.h:972
#define TCCR0A
Definition: io90pwm1.h:288
#define COM5A1
Definition: iom1284rfr2.h:1756
#define TIMER3A
Definition: Arduino.h:214
#define OCR2B
Definition: io90scr100.h:1024
#define OCR4B
Definition: iom1284rfr2.h:1013
#define TIMER3C
Definition: Arduino.h:216
#define OCR3A
Definition: iocanxx.h:293

◆ atexit()

int atexit ( void(*)()  func)

main.cpp23 行目に定義があります。

23 { return 0; }

◆ attachInterrupt()

void attachInterrupt ( uint8_t  ,
void(*)(void)  ,
int  mode 
)

WInterrupts.c69 行目に定義があります。

69  {
70  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
71  intFunc[interruptNum] = userFunc;
72 
73  // Configure the interrupt mode (trigger on low input, any change, rising
74  // edge, or falling edge). The mode constants were chosen to correspond
75  // to the configuration bits in the hardware register, so we simply shift
76  // the mode into place.
77 
78  // Enable the interrupt.
79 
80  switch (interruptNum) {
81 #if defined(__AVR_ATmega32U4__)
82  // I hate doing this, but the register assignment differs between the 1280/2560
83  // and the 32U4. Since avrlib defines registers PCMSK1 and PCMSK2 that aren't
84  // even present on the 32U4 this is the only way to distinguish between them.
85  case 0:
86  EICRA = (EICRA & ~((1<<ISC00) | (1<<ISC01))) | (mode << ISC00);
87  EIMSK |= (1<<INT0);
88  break;
89  case 1:
90  EICRA = (EICRA & ~((1<<ISC10) | (1<<ISC11))) | (mode << ISC10);
91  EIMSK |= (1<<INT1);
92  break;
93  case 2:
94  EICRA = (EICRA & ~((1<<ISC20) | (1<<ISC21))) | (mode << ISC20);
95  EIMSK |= (1<<INT2);
96  break;
97  case 3:
98  EICRA = (EICRA & ~((1<<ISC30) | (1<<ISC31))) | (mode << ISC30);
99  EIMSK |= (1<<INT3);
100  break;
101  case 4:
102  EICRB = (EICRB & ~((1<<ISC60) | (1<<ISC61))) | (mode << ISC60);
103  EIMSK |= (1<<INT6);
104  break;
105 #elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
106  case 2:
107  EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
108  EIMSK |= (1 << INT0);
109  break;
110  case 3:
111  EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
112  EIMSK |= (1 << INT1);
113  break;
114  case 4:
115  EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
116  EIMSK |= (1 << INT2);
117  break;
118  case 5:
119  EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
120  EIMSK |= (1 << INT3);
121  break;
122  case 0:
123  EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
124  EIMSK |= (1 << INT4);
125  break;
126  case 1:
127  EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
128  EIMSK |= (1 << INT5);
129  break;
130  case 6:
131  EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
132  EIMSK |= (1 << INT6);
133  break;
134  case 7:
135  EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
136  EIMSK |= (1 << INT7);
137  break;
138 #else
139  case 0:
140  #if defined(EICRA) && defined(ISC00) && defined(EIMSK)
141  EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
142  EIMSK |= (1 << INT0);
143  #elif defined(MCUCR) && defined(ISC00) && defined(GICR)
144  MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
145  GICR |= (1 << INT0);
146  #elif defined(MCUCR) && defined(ISC00) && defined(GIMSK)
147  MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
148  GIMSK |= (1 << INT0);
149  #else
150  #error attachInterrupt not finished for this CPU (case 0)
151  #endif
152  break;
153 
154  case 1:
155  #if defined(EICRA) && defined(ISC10) && defined(ISC11) && defined(EIMSK)
156  EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
157  EIMSK |= (1 << INT1);
158  #elif defined(MCUCR) && defined(ISC10) && defined(ISC11) && defined(GICR)
159  MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
160  GICR |= (1 << INT1);
161  #elif defined(MCUCR) && defined(ISC10) && defined(GIMSK) && defined(GIMSK)
162  MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
163  GIMSK |= (1 << INT1);
164  #else
165  #warning attachInterrupt may need some more work for this cpu (case 1)
166  #endif
167  break;
168 
169  case 2:
170  #if defined(EICRA) && defined(ISC20) && defined(ISC21) && defined(EIMSK)
171  EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
172  EIMSK |= (1 << INT2);
173  #elif defined(MCUCR) && defined(ISC20) && defined(ISC21) && defined(GICR)
174  MCUCR = (MCUCR & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
175  GICR |= (1 << INT2);
176  #elif defined(MCUCR) && defined(ISC20) && defined(GIMSK) && defined(GIMSK)
177  MCUCR = (MCUCR & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
178  GIMSK |= (1 << INT2);
179  #endif
180  break;
181 #endif
182  }
183  }
184 }
#define ISC41
Definition: iocanxx.h:751
#define ISC00
Definition: io1200.h:149
#define ISC50
Definition: iocanxx.h:750
#define ISC21
Definition: io90pwm1.h:505
#define ISC30
Definition: io90pwm1.h:504
#define ISC40
Definition: iocanxx.h:752
#define ISC11
Definition: io2313.h:229
#define INT6
Definition: iocanxx.h:769
#define INT3
#define INT1
#define GICR
Definition: iom16.h:465
#define EIMSK
Definition: io76c711.h:121
#define ISC61
Definition: iocanxx.h:747
#define EICRB
Definition: iocanxx.h:196
#define MCUCR
Definition: io1200.h:97
#define INT5
Definition: iocanxx.h:770
#define ISC51
Definition: iocanxx.h:749
#define ISC71
Definition: iocanxx.h:745
#define ISC10
Definition: io2313.h:230
#define EXTERNAL_NUM_INTERRUPTS
#define ISC31
Definition: io90pwm1.h:503
#define INT2
#define ISC70
Definition: iocanxx.h:746
#define INT4
Definition: iocanxx.h:771
#define GIMSK
Definition: io1200.h:109
#define INT7
Definition: iocanxx.h:768
#define ISC60
Definition: iocanxx.h:748
#define EICRA
Definition: io90pwm1.h:501
#define ISC20
Definition: io90pwm1.h:506
#define ISC01
Definition: io1200.h:148
#define INT0

◆ delay()

void delay ( unsigned long  )

wiring.c106 行目に定義があります。

107 {
108  uint32_t start = micros();
109 
110  while (ms > 0) {
111  yield();
112  while ( ms > 0 && (micros() - start) >= 1000) {
113  ms--;
114  start += 1000;
115  }
116  }
117 }
void yield(void)
unsigned long micros()
Definition: wiring.c:79

◆ delayMicroseconds()

void delayMicroseconds ( unsigned int  us)

wiring.c120 行目に定義があります。

121 {
122  // call = 4 cycles + 2 to 4 cycles to init us(2 for constant delay, 4 for variable)
123 
124  // calling avrlib's delay_us() function with low values (e.g. 1 or
125  // 2 microseconds) gives delays longer than desired.
126  //delay_us(us);
127 #if F_CPU >= 24000000L
128  // for the 24 MHz clock for the aventurous ones, trying to overclock
129 
130  // zero delay fix
131  if (!us) return; // = 3 cycles, (4 when true)
132 
133  // the following loop takes a 1/6 of a microsecond (4 cycles)
134  // per iteration, so execute it six times for each microsecond of
135  // delay requested.
136  us *= 6; // x6 us, = 7 cycles
137 
138  // account for the time taken in the preceeding commands.
139  // we just burned 22 (24) cycles above, remove 5, (5*4=20)
140  // us is at least 6 so we can substract 5
141  us -= 5; //=2 cycles
142 
143 #elif F_CPU >= 20000000L
144  // for the 20 MHz clock on rare Arduino boards
145 
146  // for a one-microsecond delay, simply return. the overhead
147  // of the function call takes 18 (20) cycles, which is 1us
148  __asm__ __volatile__ (
149  "nop" "\n\t"
150  "nop" "\n\t"
151  "nop" "\n\t"
152  "nop"); //just waiting 4 cycles
153  if (us <= 1) return; // = 3 cycles, (4 when true)
154 
155  // the following loop takes a 1/5 of a microsecond (4 cycles)
156  // per iteration, so execute it five times for each microsecond of
157  // delay requested.
158  us = (us << 2) + us; // x5 us, = 7 cycles
159 
160  // account for the time taken in the preceeding commands.
161  // we just burned 26 (28) cycles above, remove 7, (7*4=28)
162  // us is at least 10 so we can substract 7
163  us -= 7; // 2 cycles
164 
165 #elif F_CPU >= 16000000L
166  // for the 16 MHz clock on most Arduino boards
167 
168  // for a one-microsecond delay, simply return. the overhead
169  // of the function call takes 14 (16) cycles, which is 1us
170  if (us <= 1) return; // = 3 cycles, (4 when true)
171 
172  // the following loop takes 1/4 of a microsecond (4 cycles)
173  // per iteration, so execute it four times for each microsecond of
174  // delay requested.
175  us <<= 2; // x4 us, = 4 cycles
176 
177  // account for the time taken in the preceeding commands.
178  // we just burned 19 (21) cycles above, remove 5, (5*4=20)
179  // us is at least 8 so we can substract 5
180  us -= 5; // = 2 cycles,
181 
182 #elif F_CPU >= 12000000L
183  // for the 12 MHz clock if somebody is working with USB
184 
185  // for a 1 microsecond delay, simply return. the overhead
186  // of the function call takes 14 (16) cycles, which is 1.5us
187  if (us <= 1) return; // = 3 cycles, (4 when true)
188 
189  // the following loop takes 1/3 of a microsecond (4 cycles)
190  // per iteration, so execute it three times for each microsecond of
191  // delay requested.
192  us = (us << 1) + us; // x3 us, = 5 cycles
193 
194  // account for the time taken in the preceeding commands.
195  // we just burned 20 (22) cycles above, remove 5, (5*4=20)
196  // us is at least 6 so we can substract 5
197  us -= 5; //2 cycles
198 
199 #elif F_CPU >= 8000000L
200  // for the 8 MHz internal clock
201 
202  // for a 1 and 2 microsecond delay, simply return. the overhead
203  // of the function call takes 14 (16) cycles, which is 2us
204  if (us <= 2) return; // = 3 cycles, (4 when true)
205 
206  // the following loop takes 1/2 of a microsecond (4 cycles)
207  // per iteration, so execute it twice for each microsecond of
208  // delay requested.
209  us <<= 1; //x2 us, = 2 cycles
210 
211  // account for the time taken in the preceeding commands.
212  // we just burned 17 (19) cycles above, remove 4, (4*4=16)
213  // us is at least 6 so we can substract 4
214  us -= 4; // = 2 cycles
215 
216 #else
217  // for the 1 MHz internal clock (default settings for common Atmega microcontrollers)
218 
219  // the overhead of the function calls is 14 (16) cycles
220  if (us <= 16) return; //= 3 cycles, (4 when true)
221  if (us <= 25) return; //= 3 cycles, (4 when true), (must be at least 25 if we want to substract 22)
222 
223  // compensate for the time taken by the preceeding and next commands (about 22 cycles)
224  us -= 22; // = 2 cycles
225  // the following loop takes 4 microseconds (4 cycles)
226  // per iteration, so execute it us/4 times
227  // us is at least 4, divided by 4 gives us 1 (no zero delay bug)
228  us >>= 2; // us div 4, = 4 cycles
229 
230 
231 #endif
232 
233  // busy wait
234  __asm__ __volatile__ (
235  "1: sbiw %0,1" "\n\t" // 2 cycles
236  "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
237  );
238  // return = 4 cycles
239 }

◆ detachInterrupt()

void detachInterrupt ( uint8_t  )

WInterrupts.c186 行目に定義があります。

186  {
187  if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
188  // Disable the interrupt. (We can't assume that interruptNum is equal
189  // to the number of the EIMSK bit to clear, as this isn't true on the
190  // ATmega8. There, INT0 is 6 and INT1 is 7.)
191  switch (interruptNum) {
192 #if defined(__AVR_ATmega32U4__)
193  case 0:
194  EIMSK &= ~(1<<INT0);
195  break;
196  case 1:
197  EIMSK &= ~(1<<INT1);
198  break;
199  case 2:
200  EIMSK &= ~(1<<INT2);
201  break;
202  case 3:
203  EIMSK &= ~(1<<INT3);
204  break;
205  case 4:
206  EIMSK &= ~(1<<INT6);
207  break;
208 #elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
209  case 2:
210  EIMSK &= ~(1 << INT0);
211  break;
212  case 3:
213  EIMSK &= ~(1 << INT1);
214  break;
215  case 4:
216  EIMSK &= ~(1 << INT2);
217  break;
218  case 5:
219  EIMSK &= ~(1 << INT3);
220  break;
221  case 0:
222  EIMSK &= ~(1 << INT4);
223  break;
224  case 1:
225  EIMSK &= ~(1 << INT5);
226  break;
227  case 6:
228  EIMSK &= ~(1 << INT6);
229  break;
230  case 7:
231  EIMSK &= ~(1 << INT7);
232  break;
233 #else
234  case 0:
235  #if defined(EIMSK) && defined(INT0)
236  EIMSK &= ~(1 << INT0);
237  #elif defined(GICR) && defined(ISC00)
238  GICR &= ~(1 << INT0); // atmega32
239  #elif defined(GIMSK) && defined(INT0)
240  GIMSK &= ~(1 << INT0);
241  #else
242  #error detachInterrupt not finished for this cpu
243  #endif
244  break;
245 
246  case 1:
247  #if defined(EIMSK) && defined(INT1)
248  EIMSK &= ~(1 << INT1);
249  #elif defined(GICR) && defined(INT1)
250  GICR &= ~(1 << INT1); // atmega32
251  #elif defined(GIMSK) && defined(INT1)
252  GIMSK &= ~(1 << INT1);
253  #else
254  #warning detachInterrupt may need some more work for this cpu (case 1)
255  #endif
256  break;
257 
258  case 2:
259  #if defined(EIMSK) && defined(INT2)
260  EIMSK &= ~(1 << INT2);
261  #elif defined(GICR) && defined(INT2)
262  GICR &= ~(1 << INT2); // atmega32
263  #elif defined(GIMSK) && defined(INT2)
264  GIMSK &= ~(1 << INT2);
265  #elif defined(INT2)
266  #warning detachInterrupt may need some more work for this cpu (case 2)
267  #endif
268  break;
269 #endif
270  }
271 
272  intFunc[interruptNum] = nothing;
273  }
274 }
#define INT6
Definition: iocanxx.h:769
#define INT3
#define INT1
#define GICR
Definition: iom16.h:465
#define EIMSK
Definition: io76c711.h:121
#define INT5
Definition: iocanxx.h:770
#define EXTERNAL_NUM_INTERRUPTS
#define INT2
#define INT4
Definition: iocanxx.h:771
#define GIMSK
Definition: io1200.h:109
#define INT7
Definition: iocanxx.h:768
#define INT0

◆ digitalRead()

int digitalRead ( uint8_t  )

wiring_digital.c165 行目に定義があります。

166 {
167  uint8_t timer = digitalPinToTimer(pin);
168  uint8_t bit = digitalPinToBitMask(pin);
169  uint8_t port = digitalPinToPort(pin);
170 
171  if (port == NOT_A_PIN) return LOW;
172 
173  // If the pin that support PWM output, we need to turn it off
174  // before getting a digital reading.
175  if (timer != NOT_ON_TIMER) turnOffPWM(timer);
176 
177  if (*portInputRegister(port) & bit) return HIGH;
178  return LOW;
179 }
#define bit(b)
Definition: Arduino.h:123
#define portInputRegister(P)
Definition: Arduino.h:182
#define digitalPinToBitMask(P)
Definition: Arduino.h:178
#define digitalPinToTimer(P)
Definition: Arduino.h:179
#define LOW
Definition: Arduino.h:41
#define HIGH
Definition: Arduino.h:40
#define NOT_ON_TIMER
Definition: Arduino.h:204
#define NOT_A_PIN
Definition: Arduino.h:185
#define digitalPinToPort(P)
Definition: Arduino.h:177

◆ digitalWrite()

void digitalWrite ( uint8_t  ,
uint8_t   
)

wiring_digital.c138 行目に定義があります。

139 {
140  uint8_t timer = digitalPinToTimer(pin);
141  uint8_t bit = digitalPinToBitMask(pin);
142  uint8_t port = digitalPinToPort(pin);
143  volatile uint8_t *out;
144 
145  if (port == NOT_A_PIN) return;
146 
147  // If the pin that support PWM output, we need to turn it off
148  // before doing a digital write.
149  if (timer != NOT_ON_TIMER) turnOffPWM(timer);
150 
151  out = portOutputRegister(port);
152 
153  uint8_t oldSREG = SREG;
154  cli();
155 
156  if (val == LOW) {
157  *out &= ~bit;
158  } else {
159  *out |= bit;
160  }
161 
162  SREG = oldSREG;
163 }
#define bit(b)
Definition: Arduino.h:123
#define SREG
Definition: common.h:103
#define digitalPinToBitMask(P)
Definition: Arduino.h:178
#define portOutputRegister(P)
Definition: Arduino.h:181
#define digitalPinToTimer(P)
Definition: Arduino.h:179
#define cli()
Definition: interrupt.h:99
#define LOW
Definition: Arduino.h:41
#define NOT_ON_TIMER
Definition: Arduino.h:204
#define NOT_A_PIN
Definition: Arduino.h:185
#define digitalPinToPort(P)
Definition: Arduino.h:177

◆ init()

void init ( void  )

wiring.c241 行目に定義があります。

242 {
243  // this needs to be called before setup() or some functions won't
244  // work there
245  sei();
246 
247  // on the ATmega168, timer 0 is also used for fast hardware pwm
248  // (using phase-correct PWM would mean that timer 0 overflowed half as often
249  // resulting in different millis() behavior on the ATmega8 and ATmega168)
250 #if defined(TCCR0A) && defined(WGM01)
251  sbi(TCCR0A, WGM01);
252  sbi(TCCR0A, WGM00);
253 #endif
254 
255  // set timer 0 prescale factor to 64
256 #if defined(__AVR_ATmega128__)
257  // CPU specific: different values for the ATmega128
258  sbi(TCCR0, CS02);
259 #elif defined(TCCR0) && defined(CS01) && defined(CS00)
260  // this combination is for the standard atmega8
261  sbi(TCCR0, CS01);
262  sbi(TCCR0, CS00);
263 #elif defined(TCCR0B) && defined(CS01) && defined(CS00)
264  // this combination is for the standard 168/328/1280/2560
265  sbi(TCCR0B, CS01);
266  sbi(TCCR0B, CS00);
267 #elif defined(TCCR0A) && defined(CS01) && defined(CS00)
268  // this combination is for the __AVR_ATmega645__ series
269  sbi(TCCR0A, CS01);
270  sbi(TCCR0A, CS00);
271 #else
272  #error Timer 0 prescale factor 64 not set correctly
273 #endif
274 
275  // enable timer 0 overflow interrupt
276 #if defined(TIMSK) && defined(TOIE0)
277  sbi(TIMSK, TOIE0);
278 #elif defined(TIMSK0) && defined(TOIE0)
279  sbi(TIMSK0, TOIE0);
280 #else
281  #error Timer 0 overflow interrupt not set correctly
282 #endif
283 
284  // timers 1 and 2 are used for phase-correct hardware pwm
285  // this is better for motors as it ensures an even waveform
286  // note, however, that fast pwm mode can achieve a frequency of up
287  // 8 MHz (with a 16 MHz clock) at 50% duty cycle
288 
289 #if defined(TCCR1B) && defined(CS11) && defined(CS10)
290  TCCR1B = 0;
291 
292  // set timer 1 prescale factor to 64
293  sbi(TCCR1B, CS11);
294 #if F_CPU >= 8000000L
295  sbi(TCCR1B, CS10);
296 #endif
297 #elif defined(TCCR1) && defined(CS11) && defined(CS10)
298  sbi(TCCR1, CS11);
299 #if F_CPU >= 8000000L
300  sbi(TCCR1, CS10);
301 #endif
302 #endif
303  // put timer 1 in 8-bit phase correct pwm mode
304 #if defined(TCCR1A) && defined(WGM10)
305  sbi(TCCR1A, WGM10);
306 #endif
307 
308  // set timer 2 prescale factor to 64
309 #if defined(TCCR2) && defined(CS22)
310  sbi(TCCR2, CS22);
311 #elif defined(TCCR2B) && defined(CS22)
312  sbi(TCCR2B, CS22);
313 //#else
314  // Timer 2 not finished (may not be present on this CPU)
315 #endif
316 
317  // configure timer 2 for phase correct pwm (8-bit)
318 #if defined(TCCR2) && defined(WGM20)
319  sbi(TCCR2, WGM20);
320 #elif defined(TCCR2A) && defined(WGM20)
321  sbi(TCCR2A, WGM20);
322 //#else
323  // Timer 2 not finished (may not be present on this CPU)
324 #endif
325 
326 #if defined(TCCR3B) && defined(CS31) && defined(WGM30)
327  sbi(TCCR3B, CS31); // set timer 3 prescale factor to 64
328  sbi(TCCR3B, CS30);
329  sbi(TCCR3A, WGM30); // put timer 3 in 8-bit phase correct pwm mode
330 #endif
331 
332 #if defined(TCCR4A) && defined(TCCR4B) && defined(TCCR4D) /* beginning of timer4 block for 32U4 and similar */
333  sbi(TCCR4B, CS42); // set timer4 prescale factor to 64
334  sbi(TCCR4B, CS41);
335  sbi(TCCR4B, CS40);
336  sbi(TCCR4D, WGM40); // put timer 4 in phase- and frequency-correct PWM mode
337  sbi(TCCR4A, PWM4A); // enable PWM mode for comparator OCR4A
338  sbi(TCCR4C, PWM4D); // enable PWM mode for comparator OCR4D
339 #else /* beginning of timer4 block for ATMEGA1280 and ATMEGA2560 */
340 #if defined(TCCR4B) && defined(CS41) && defined(WGM40)
341  sbi(TCCR4B, CS41); // set timer 4 prescale factor to 64
342  sbi(TCCR4B, CS40);
343  sbi(TCCR4A, WGM40); // put timer 4 in 8-bit phase correct pwm mode
344 #endif
345 #endif /* end timer4 block for ATMEGA1280/2560 and similar */
346 
347 #if defined(TCCR5B) && defined(CS51) && defined(WGM50)
348  sbi(TCCR5B, CS51); // set timer 5 prescale factor to 64
349  sbi(TCCR5B, CS50);
350  sbi(TCCR5A, WGM50); // put timer 5 in 8-bit phase correct pwm mode
351 #endif
352 
353 #if defined(ADCSRA)
354  // set a2d prescaler so we are inside the desired 50-200 KHz range.
355  #if F_CPU >= 16000000 // 16 MHz / 128 = 125 KHz
356  sbi(ADCSRA, ADPS2);
357  sbi(ADCSRA, ADPS1);
358  sbi(ADCSRA, ADPS0);
359  #elif F_CPU >= 8000000 // 8 MHz / 64 = 125 KHz
360  sbi(ADCSRA, ADPS2);
361  sbi(ADCSRA, ADPS1);
362  cbi(ADCSRA, ADPS0);
363  #elif F_CPU >= 4000000 // 4 MHz / 32 = 125 KHz
364  sbi(ADCSRA, ADPS2);
365  cbi(ADCSRA, ADPS1);
366  sbi(ADCSRA, ADPS0);
367  #elif F_CPU >= 2000000 // 2 MHz / 16 = 125 KHz
368  sbi(ADCSRA, ADPS2);
369  cbi(ADCSRA, ADPS1);
370  cbi(ADCSRA, ADPS0);
371  #elif F_CPU >= 1000000 // 1 MHz / 8 = 125 KHz
372  cbi(ADCSRA, ADPS2);
373  sbi(ADCSRA, ADPS1);
374  sbi(ADCSRA, ADPS0);
375  #else // 128 kHz / 2 = 64 KHz -> This is the closest you can get, the prescaler is 2
376  cbi(ADCSRA, ADPS2);
377  cbi(ADCSRA, ADPS1);
378  sbi(ADCSRA, ADPS0);
379  #endif
380  // enable a2d conversions
381  sbi(ADCSRA, ADEN);
382 #endif
383 
384  // the bootloader connects pins 0 and 1 to the USART; disconnect them
385  // here so they can be used as normal digital i/o; they will be
386  // reconnected in Serial.begin()
387 #if defined(UCSRB)
388  UCSRB = 0;
389 #elif defined(UCSR0B)
390  UCSR0B = 0;
391 #endif
392 }
#define sei()
Definition: interrupt.h:81
#define TCCR3A
Definition: iocanxx.h:274
#define CS11
Definition: io2313.h:250
#define PWM4A
Definition: iom16u4.h:941
#define WGM00
Definition: io90pwm1.h:295
#define ADCSRA
Definition: io90pwm1.h:551
#define CS02
Definition: io1200.h:152
#define CS22
Definition: io4434.h:358
#define CS10
Definition: io2313.h:251
#define WGM01
Definition: io90pwm1.h:294
#define ADPS2
Definition: io2333.h:363
#define UCSRB
Definition: io2333.h:76
#define WGM40
Definition: iom1284rfr2.h:969
#define TCCR1A
Definition: pins_arduino.h:68
#define ADPS0
Definition: io2333.h:365
#define CS30
Definition: iocanxx.h:845
#define WGM10
Definition: io90pwm1.h:613
#define TIMSK
Definition: io1200.h:105
#define WGM20
Definition: io90scr100.h:989
#define TCCR5A
Definition: iom1284rfr2.h:1748
#define sbi(sfr, bit)
Definition: ATmegaBOOT.c:75
#define TCCR4C
Definition: iom1284rfr2.h:987
#define WGM50
Definition: iom1284rfr2.h:1749
#define CS51
Definition: iom1284rfr2.h:1760
#define TCCR2
Definition: io4434.h:149
#define TCCR5B
Definition: iom1284rfr2.h:1758
#define TCCR2A
Definition: io90scr100.h:988
#define CS42
Definition: iom1284rfr2.h:981
#define CS31
Definition: iocanxx.h:844
#define UCSR0B
Definition: io90scr100.h:1110
#define TCCR0
Definition: io1200.h:93
#define TOIE0
Definition: io1200.h:140
#define PWM4D
Definition: iom16u4.h:960
#define CS50
Definition: iom1284rfr2.h:1759
#define cbi(sfr, bit)
Definition: ATmegaBOOT.c:72
#define TCCR4B
Definition: iom1284rfr2.h:978
#define TCCR4A
Definition: iom1284rfr2.h:968
#define CS40
Definition: iom1284rfr2.h:979
#define ADPS1
Definition: io2333.h:364
#define TCCR3B
Definition: iocanxx.h:277
#define WGM30
Definition: iocanxx.h:823
#define TCCR0B
Definition: io90pwm1.h:298
#define TCCR1
Definition: io8534.h:100
#define ADEN
Definition: io2333.h:358
#define TIMSK0
Definition: io90pwm1.h:515
#define CS41
Definition: iom1284rfr2.h:980
#define CS00
Definition: io1200.h:154
#define TCCR0A
Definition: io90pwm1.h:288
#define TCCR2B
Definition: io90scr100.h:996
#define TCCR4D
Definition: iom16u4.h:969
#define CS01
Definition: io1200.h:153
#define TCCR1B
Definition: io2313.h:117

◆ initVariant()

void initVariant ( void  )

main.cpp28 行目に定義があります。

28 { }

◆ loop()

void loop ( void  )

◆ micros()

unsigned long micros ( void  )

wiring.c79 行目に定義があります。

79  {
80  unsigned long m;
81  uint8_t oldSREG = SREG, t;
82 
83  cli();
85 #if defined(TCNT0)
86  t = TCNT0;
87 #elif defined(TCNT0L)
88  t = TCNT0L;
89 #else
90  #error TIMER 0 not defined
91 #endif
92 
93 #ifdef TIFR0
94  if ((TIFR0 & _BV(TOV0)) && (t < 255))
95  m++;
96 #else
97  if ((TIFR & _BV(TOV0)) && (t < 255))
98  m++;
99 #endif
100 
101  SREG = oldSREG;
102 
103  return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
104 }
#define SREG
Definition: common.h:103
#define TCNT0L
Definition: iom16hva2.h:177
#define TIFR
Definition: io1200.h:102
volatile unsigned long timer0_overflow_count
Definition: wiring.c:38
m
Definition: wiring.c:53
#define clockCyclesPerMicrosecond()
Definition: Arduino.h:104
#define TIFR0
Definition: io90pwm1.h:153
#define cli()
Definition: interrupt.h:99
#define _BV(bit)
Definition: sfr_defs.h:208
#define TOV0
Definition: io1200.h:143
#define TCNT0
Definition: io1200.h:92

◆ millis()

unsigned long millis ( void  )

wiring.c65 行目に定義があります。

66 {
67  unsigned long m;
68  uint8_t oldSREG = SREG;
69 
70  // disable interrupts while we read timer0_millis or we might get an
71  // inconsistent value (e.g. in the middle of a write to timer0_millis)
72  cli();
73  m = timer0_millis;
74  SREG = oldSREG;
75 
76  return m;
77 }
#define SREG
Definition: common.h:103
m
Definition: wiring.c:53
#define cli()
Definition: interrupt.h:99
volatile unsigned long timer0_millis
Definition: wiring.c:39

◆ pinMode()

void pinMode ( uint8_t  ,
uint8_t   
)

wiring_digital.c29 行目に定義があります。

30 {
31  uint8_t bit = digitalPinToBitMask(pin);
32  uint8_t port = digitalPinToPort(pin);
33  volatile uint8_t *reg, *out;
34 
35  if (port == NOT_A_PIN) return;
36 
37  // JWS: can I let the optimizer do this?
38  reg = portModeRegister(port);
39  out = portOutputRegister(port);
40 
41  if (mode == INPUT) {
42  uint8_t oldSREG = SREG;
43  cli();
44  *reg &= ~bit;
45  *out &= ~bit;
46  SREG = oldSREG;
47  } else if (mode == INPUT_PULLUP) {
48  uint8_t oldSREG = SREG;
49  cli();
50  *reg &= ~bit;
51  *out |= bit;
52  SREG = oldSREG;
53  } else {
54  uint8_t oldSREG = SREG;
55  cli();
56  *reg |= bit;
57  SREG = oldSREG;
58  }
59 }
#define bit(b)
Definition: Arduino.h:123
#define SREG
Definition: common.h:103
#define digitalPinToBitMask(P)
Definition: Arduino.h:178
#define portOutputRegister(P)
Definition: Arduino.h:181
#define portModeRegister(P)
Definition: Arduino.h:183
#define cli()
Definition: interrupt.h:99
#define INPUT_PULLUP
Definition: Arduino.h:45
#define NOT_A_PIN
Definition: Arduino.h:185
#define digitalPinToPort(P)
Definition: Arduino.h:177
#define INPUT
Definition: Arduino.h:43

◆ pulseIn()

unsigned long pulseIn ( uint8_t  pin,
uint8_t  state,
unsigned long  timeout 
)

wiring_pulse.c33 行目に定義があります。

34 {
35  // cache the port and bit of the pin in order to speed up the
36  // pulse width measuring loop and achieve finer resolution. calling
37  // digitalRead() instead yields much coarser resolution.
38  uint8_t bit = digitalPinToBitMask(pin);
39  uint8_t port = digitalPinToPort(pin);
40  uint8_t stateMask = (state ? bit : 0);
41 
42  // convert the timeout from microseconds to a number of times through
43  // the initial loop; it takes approximately 16 clock cycles per iteration
44  unsigned long maxloops = microsecondsToClockCycles(timeout)/16;
45 
46  unsigned long width = countPulseASM(portInputRegister(port), bit, stateMask, maxloops);
47 
48  // prevent clockCyclesToMicroseconds to return bogus values if countPulseASM timed out
49  if (width)
50  return clockCyclesToMicroseconds(width * 16 + 16);
51  else
52  return 0;
53 }
#define bit(b)
Definition: Arduino.h:123
#define portInputRegister(P)
Definition: Arduino.h:182
#define digitalPinToBitMask(P)
Definition: Arduino.h:178
uint32_t countPulseASM(volatile uint8_t *port, uint8_t bit, uint8_t stateMask, unsigned long maxloops)
#define microsecondsToClockCycles(a)
Definition: Arduino.h:106
#define digitalPinToPort(P)
Definition: Arduino.h:177
#define clockCyclesToMicroseconds(a)
Definition: Arduino.h:105

◆ pulseInLong()

unsigned long pulseInLong ( uint8_t  pin,
uint8_t  state,
unsigned long  timeout 
)

wiring_pulse.c63 行目に定義があります。

64 {
65  // cache the port and bit of the pin in order to speed up the
66  // pulse width measuring loop and achieve finer resolution. calling
67  // digitalRead() instead yields much coarser resolution.
68  uint8_t bit = digitalPinToBitMask(pin);
69  uint8_t port = digitalPinToPort(pin);
70  uint8_t stateMask = (state ? bit : 0);
71 
72  unsigned long startMicros = micros();
73 
74  // wait for any previous pulse to end
75  while ((*portInputRegister(port) & bit) == stateMask) {
76  if (micros() - startMicros > timeout)
77  return 0;
78  }
79 
80  // wait for the pulse to start
81  while ((*portInputRegister(port) & bit) != stateMask) {
82  if (micros() - startMicros > timeout)
83  return 0;
84  }
85 
86  unsigned long start = micros();
87  // wait for the pulse to stop
88  while ((*portInputRegister(port) & bit) == stateMask) {
89  if (micros() - startMicros > timeout)
90  return 0;
91  }
92  return micros() - start;
93 }
#define bit(b)
Definition: Arduino.h:123
#define portInputRegister(P)
Definition: Arduino.h:182
#define digitalPinToBitMask(P)
Definition: Arduino.h:178
#define digitalPinToPort(P)
Definition: Arduino.h:177
unsigned long micros(void)
Definition: wiring.c:79

◆ setup()

void setup ( void  )

◆ shiftIn()

uint8_t shiftIn ( uint8_t  dataPin,
uint8_t  clockPin,
uint8_t  bitOrder 
)

wiring_shift.c25 行目に定義があります。

25  {
26  uint8_t value = 0;
27  uint8_t i;
28 
29  for (i = 0; i < 8; ++i) {
30  digitalWrite(clockPin, HIGH);
31  if (bitOrder == LSBFIRST)
32  value |= digitalRead(dataPin) << i;
33  else
34  value |= digitalRead(dataPin) << (7 - i);
35  digitalWrite(clockPin, LOW);
36  }
37  return value;
38 }
uint8_t i
void digitalWrite(uint8_t, uint8_t)
#define LSBFIRST
Definition: Arduino.h:57
#define LOW
Definition: Arduino.h:41
#define HIGH
Definition: Arduino.h:40
int digitalRead(uint8_t)

◆ shiftOut()

void shiftOut ( uint8_t  dataPin,
uint8_t  clockPin,
uint8_t  bitOrder,
uint8_t  val 
)

wiring_shift.c40 行目に定義があります。

41 {
42  uint8_t i;
43 
44  for (i = 0; i < 8; i++) {
45  if (bitOrder == LSBFIRST)
46  digitalWrite(dataPin, !!(val & (1 << i)));
47  else
48  digitalWrite(dataPin, !!(val & (1 << (7 - i))));
49 
50  digitalWrite(clockPin, HIGH);
51  digitalWrite(clockPin, LOW);
52  }
53 }
uint8_t i
void digitalWrite(uint8_t, uint8_t)
#define LSBFIRST
Definition: Arduino.h:57
#define LOW
Definition: Arduino.h:41
#define HIGH
Definition: Arduino.h:40

◆ yield()

void yield ( void  )

変数詳解

◆ digital_pin_to_bit_mask_PGM

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]

◆ digital_pin_to_port_PGM

const uint8_t PROGMEM digital_pin_to_port_PGM[]

◆ digital_pin_to_timer_PGM

const uint8_t PROGMEM digital_pin_to_timer_PGM[]

◆ port_to_input_PGM

const uint16_t PROGMEM port_to_input_PGM[]

◆ port_to_mode_PGM

const uint16_t PROGMEM port_to_mode_PGM[]

◆ port_to_output_PGM

const uint16_t PROGMEM port_to_output_PGM[]