;;; init()
;;; Length: 114 bytes
;;; provided by: Arduino Environment
;;; Required by: Arduino Environment, user sketches
;;; Comments: initializes peripherals (especially timers) as expected by
;;; the ISR and PWM output, and so on.
;;; The compiler seems to do a particularly poor job of optimizing
;;; what ought to be straightforward code.
00000148 <init>:
void init()
{
// this needs to be called before setup() or some functions won't
// work there
sei();
148: 78 94 sei
// on the ATmega168, timer 0 is also used for fast hardware pwm
// (using phase-correct PWM would mean that timer 0 overflowed half as often
// resulting in different millis() behavior on the ATmega8 and ATmega168)
#if !defined(__AVR_ATmega8__)
sbi(TCCR0A, WGM01);
14a: 84 b5 in r24, 0x24 ; 36
14c: 82 60 ori r24, 0x02 ; 2
14e: 84 bd out 0x24, r24 ; 36
sbi(TCCR0A, WGM00);
150: 84 b5 in r24, 0x24 ; 36
152: 81 60 ori r24, 0x01 ; 1
154: 84 bd out 0x24, r24 ; 36
// set timer 0 prescale factor to 64
#if defined(__AVR_ATmega8__)
sbi(TCCR0, CS01);
sbi(TCCR0, CS00);
#else
sbi(TCCR0B, CS01);
156: 85 b5 in r24, 0x25 ; 37
158: 82 60 ori r24, 0x02 ; 2
15a: 85 bd out 0x25, r24 ; 37
sbi(TCCR0B, CS00);
15c: 85 b5 in r24, 0x25 ; 37
15e: 81 60 ori r24, 0x01 ; 1
160: 85 bd out 0x25, r24 ; 37
#endif
// enable timer 0 overflow interrupt
#if defined(__AVR_ATmega8__)
sbi(TIMSK, TOIE0);
#else
sbi(TIMSK0, TOIE0);
162: ee e6 ldi r30, 0x6E ; 110
164: f0 e0 ldi r31, 0x00 ; 0
166: 80 81 ld r24, Z
168: 81 60 ori r24, 0x01 ; 1
16a: 80 83 st Z, r24
// this is better for motors as it ensures an even waveform
// note, however, that fast pwm mode can achieve a frequency of up
// 8 MHz (with a 16 MHz clock) at 50% duty cycle
// set timer 1 prescale factor to 64
sbi(TCCR1B, CS11);
16c: e1 e8 ldi r30, 0x81 ; 129
16e: f0 e0 ldi r31, 0x00 ; 0
170: 80 81 ld r24, Z
172: 82 60 ori r24, 0x02 ; 2
174: 80 83 st Z, r24
sbi(TCCR1B, CS10);
176: 80 81 ld r24, Z
178: 81 60 ori r24, 0x01 ; 1
17a: 80 83 st Z, r24
// put timer 1 in 8-bit phase correct pwm mode
sbi(TCCR1A, WGM10);
17c: e0 e8 ldi r30, 0x80 ; 128
17e: f0 e0 ldi r31, 0x00 ; 0
180: 80 81 ld r24, Z
182: 81 60 ori r24, 0x01 ; 1
184: 80 83 st Z, r24
// set timer 2 prescale factor to 64
#if defined(__AVR_ATmega8__)
sbi(TCCR2, CS22);
#else
sbi(TCCR2B, CS22);
186: e1 eb ldi r30, 0xB1 ; 177
188: f0 e0 ldi r31, 0x00 ; 0
18a: 80 81 ld r24, Z
18c: 84 60 ori r24, 0x04 ; 4
18e: 80 83 st Z, r24
#endif
// configure timer 2 for phase correct pwm (8-bit)
#if defined(__AVR_ATmega8__)
sbi(TCCR2, WGM20);
#else
sbi(TCCR2A, WGM20);
190: e0 eb ldi r30, 0xB0 ; 176
192: f0 e0 ldi r31, 0x00 ; 0
194: 80 81 ld r24, Z
196: 81 60 ori r24, 0x01 ; 1
198: 80 83 st Z, r24
// set a2d prescale factor to 128
// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
// XXX: this will not work properly for other clock speeds, and
// this code should use F_CPU to determine the prescale factor.
sbi(ADCSRA, ADPS2);
19a: ea e7 ldi r30, 0x7A ; 122
19c: f0 e0 ldi r31, 0x00 ; 0
19e: 80 81 ld r24, Z
1a0: 84 60 ori r24, 0x04 ; 4
1a2: 80 83 st Z, r24
sbi(ADCSRA, ADPS1);
1a4: 80 81 ld r24, Z
1a6: 82 60 ori r24, 0x02 ; 2
1a8: 80 83 st Z, r24
sbi(ADCSRA, ADPS0);
1aa: 80 81 ld r24, Z
1ac: 81 60 ori r24, 0x01 ; 1
1ae: 80 83 st Z, r24
// enable a2d conversions
sbi(ADCSRA, ADEN);
1b0: 80 81 ld r24, Z
1b2: 80 68 ori r24, 0x80 ; 128
1b4: 80 83 st Z, r24
// here so they can be used as normal digital i/o; they will be
// reconnected in Serial.begin()
#if defined(__AVR_ATmega8__)
UCSRB = 0;
#else
UCSR0B = 0;
1b6: 10 92 c1 00 sts 0x00C1, r1
#endif
1ba: 08 95 ret
;;; exit and __stop_program
;;; length: 4 bytes
;;; provided by: gcc C compiler
;;; required by: nothing.
;;; Comment pretty much unused in the arduino environment.
000001bc <_exit>:
1bc: f8 94 cli
000001be <__stop_program>:
1be: ff cf rjmp .-2 ; 0x1be <__stop_program>