forked from nsayer/Crazy-Clock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calibrate.c
47 lines (37 loc) · 1.55 KB
/
calibrate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Crazy Clock for Arduino
Copyright 2014 Nicholas W. Sayer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* This is a calibration sketch. It's intended to connect the system clock as directly
* as possible to an I/O pin. The best we can do is generate a half-speed clock by
* telling timer0 to toggle OC0A with the system clock. The result is 16.384 kHz.
*/
#include <avr/io.h>
#include <avr/cpufunc.h>
#include <avr/power.h>
void main() {
ADCSRA = 0; // DIE, ADC!!! DIE!!!
ACSR = _BV(ACD); // Turn off analog comparator - but was it ever on anyway?
power_adc_disable();
power_usi_disable();
power_timer1_disable();
TCCR0A = _BV(COM0A0) | _BV(WGM01); // mode 2 - CTC, toggle OC0A
TCCR0B = _BV(CS00); // prescale = 1 (none)
OCR0A = 0; // as fast as possible
DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB2); // all our pins are output.
PORTB = 0; // Initialize all pins low.
// And we're done.
while(1);
}