2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #include <avr/interrupt.h>
20 #define F_CPU 16000000UL // 16 MHz
21 #include <util/delay.h>
30 /* disable RC clock */
31 CLKSEL0 &= ~(1 << RCE);
34 PLLCSR &= ~(1 << PLLE);
36 /* Enable external clock */
37 CLKSEL0 |= (1 << EXTE);
39 /* wait for external clock to be ready */
40 while ((CLKSTA & (1 << EXTON)) == 0)
43 /* select external clock */
44 CLKSEL0 |= (1 << CLKS);
46 /* Disable the clock prescaler */
48 CLKPR = (1 << CLKPCE);
52 /* Set up the PLL to use the crystal */
54 /* Use primary system clock as PLL source */
55 PLLFRQ = ((0 << PINMUX) | /* Use primary clock */
56 (0 << PLLUSB) | /* No divide by 2 for USB */
57 (0 << PLLTM0) | /* Disable high speed timer */
58 (0x4 << PDIV0)); /* 48MHz PLL clock */
60 /* Set the frequency of the crystal */
61 PLLCSR |= (1 << PINDIV); /* For 16MHz crystal on Teensy board */
62 // PLLCSR &= ~(1 << PINDIV); /* For 8MHz crystal on TeleScience board */
65 PLLCSR |= (1 << PLLE);
66 while (!(PLLCSR & (1 << PLOCK)))
69 LEDDDR |= (1 << LEDDDRPIN);
72 LEDPORT |= (1 << LEDOUT);
74 LEDPORT &= ~(1 << LEDOUT);