![](/media/cache/profiles/74961657ae02e93fc17be9d9fc864620.50x50_q85.jpg)
LPC1768.c@1:2c52307d223f, 2010-12-02 (annotated)
- Committer:
- hugozijlmans
- Date:
- Thu Dec 02 12:32:18 2010 +0000
- Revision:
- 1:2c52307d223f
Added RIT & Timer0 interrupt routines
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hugozijlmans | 1:2c52307d223f | 1 | #include "LPC17xx.h" |
hugozijlmans | 1:2c52307d223f | 2 | #include "core_cm3.h" |
hugozijlmans | 1:2c52307d223f | 3 | #include "cmsis_nvic.h" |
hugozijlmans | 1:2c52307d223f | 4 | #include "LPC1768.h" |
hugozijlmans | 1:2c52307d223f | 5 | #include "main.h" |
hugozijlmans | 1:2c52307d223f | 6 | |
hugozijlmans | 1:2c52307d223f | 7 | void PLL0_init(void) { |
hugozijlmans | 1:2c52307d223f | 8 | |
hugozijlmans | 1:2c52307d223f | 9 | // Set main clk as main oscillator |
hugozijlmans | 1:2c52307d223f | 10 | CLKSRCSEL = 1; |
hugozijlmans | 1:2c52307d223f | 11 | |
hugozijlmans | 1:2c52307d223f | 12 | PLL0_disconnect(); |
hugozijlmans | 1:2c52307d223f | 13 | |
hugozijlmans | 1:2c52307d223f | 14 | PLL0_disable(); |
hugozijlmans | 1:2c52307d223f | 15 | |
hugozijlmans | 1:2c52307d223f | 16 | // Set PLL0 multiplier |
hugozijlmans | 1:2c52307d223f | 17 | PLL0CFG = PLLMULT; |
hugozijlmans | 1:2c52307d223f | 18 | |
hugozijlmans | 1:2c52307d223f | 19 | // Feed the PLL |
hugozijlmans | 1:2c52307d223f | 20 | PLL0FEED = 0xAA; |
hugozijlmans | 1:2c52307d223f | 21 | PLL0FEED = 0x55; |
hugozijlmans | 1:2c52307d223f | 22 | |
hugozijlmans | 1:2c52307d223f | 23 | PLL0_enable(); |
hugozijlmans | 1:2c52307d223f | 24 | |
hugozijlmans | 1:2c52307d223f | 25 | // Set CPU clock divider |
hugozijlmans | 1:2c52307d223f | 26 | CCLKCFG = 2; |
hugozijlmans | 1:2c52307d223f | 27 | |
hugozijlmans | 1:2c52307d223f | 28 | // Wait for PLOCK0 to become 1 |
hugozijlmans | 1:2c52307d223f | 29 | while ((PLL0STAT & (1<<26)) == 0x00); |
hugozijlmans | 1:2c52307d223f | 30 | |
hugozijlmans | 1:2c52307d223f | 31 | PLL0_connect(); |
hugozijlmans | 1:2c52307d223f | 32 | |
hugozijlmans | 1:2c52307d223f | 33 | } |
hugozijlmans | 1:2c52307d223f | 34 | |
hugozijlmans | 1:2c52307d223f | 35 | void PLL0_disconnect(void) { |
hugozijlmans | 1:2c52307d223f | 36 | |
hugozijlmans | 1:2c52307d223f | 37 | // Disconnect the PLL0 |
hugozijlmans | 1:2c52307d223f | 38 | PLL0CON &= ~(1<<1); /* Disconnect the main PLL (PLL0) */ |
hugozijlmans | 1:2c52307d223f | 39 | |
hugozijlmans | 1:2c52307d223f | 40 | // Feed the PLL |
hugozijlmans | 1:2c52307d223f | 41 | PLL0FEED = 0xAA; |
hugozijlmans | 1:2c52307d223f | 42 | PLL0FEED = 0x55; |
hugozijlmans | 1:2c52307d223f | 43 | |
hugozijlmans | 1:2c52307d223f | 44 | // Wait for main PLL (PLL0) to disconnect |
hugozijlmans | 1:2c52307d223f | 45 | while ((PLL0STAT & (1<<25)) != 0x00); |
hugozijlmans | 1:2c52307d223f | 46 | |
hugozijlmans | 1:2c52307d223f | 47 | } |
hugozijlmans | 1:2c52307d223f | 48 | |
hugozijlmans | 1:2c52307d223f | 49 | void PLL0_connect(void) { |
hugozijlmans | 1:2c52307d223f | 50 | |
hugozijlmans | 1:2c52307d223f | 51 | // Connect to the main PLL (PLL0) |
hugozijlmans | 1:2c52307d223f | 52 | PLL0CON |= 1<<1; |
hugozijlmans | 1:2c52307d223f | 53 | |
hugozijlmans | 1:2c52307d223f | 54 | // Feed the PLL |
hugozijlmans | 1:2c52307d223f | 55 | PLL0FEED = 0xAA; |
hugozijlmans | 1:2c52307d223f | 56 | PLL0FEED = 0x55; |
hugozijlmans | 1:2c52307d223f | 57 | |
hugozijlmans | 1:2c52307d223f | 58 | // Wait for main PLL (PLL0) to connect |
hugozijlmans | 1:2c52307d223f | 59 | while ((PLL0STAT & (1<<25)) == 0x00); |
hugozijlmans | 1:2c52307d223f | 60 | |
hugozijlmans | 1:2c52307d223f | 61 | } |
hugozijlmans | 1:2c52307d223f | 62 | |
hugozijlmans | 1:2c52307d223f | 63 | void PLL0_disable(void) { |
hugozijlmans | 1:2c52307d223f | 64 | |
hugozijlmans | 1:2c52307d223f | 65 | // Turn off the main PLL (PLL0) |
hugozijlmans | 1:2c52307d223f | 66 | PLL0CON &= ~(1<<0); |
hugozijlmans | 1:2c52307d223f | 67 | |
hugozijlmans | 1:2c52307d223f | 68 | // Feed the PLL |
hugozijlmans | 1:2c52307d223f | 69 | PLL0FEED = 0xAA; |
hugozijlmans | 1:2c52307d223f | 70 | PLL0FEED = 0x55; |
hugozijlmans | 1:2c52307d223f | 71 | |
hugozijlmans | 1:2c52307d223f | 72 | // Wait for main PLL (PLL0) to shut down |
hugozijlmans | 1:2c52307d223f | 73 | while ((PLL0STAT & (1<<24)) != 0x00); |
hugozijlmans | 1:2c52307d223f | 74 | |
hugozijlmans | 1:2c52307d223f | 75 | } |
hugozijlmans | 1:2c52307d223f | 76 | |
hugozijlmans | 1:2c52307d223f | 77 | void PLL0_enable(void) { |
hugozijlmans | 1:2c52307d223f | 78 | |
hugozijlmans | 1:2c52307d223f | 79 | // Turn on the main PLL (PLL0) |
hugozijlmans | 1:2c52307d223f | 80 | PLL0CON |= 1<<0; |
hugozijlmans | 1:2c52307d223f | 81 | |
hugozijlmans | 1:2c52307d223f | 82 | // Feed the PLL |
hugozijlmans | 1:2c52307d223f | 83 | PLL0FEED = 0xAA; |
hugozijlmans | 1:2c52307d223f | 84 | PLL0FEED = 0x55; |
hugozijlmans | 1:2c52307d223f | 85 | |
hugozijlmans | 1:2c52307d223f | 86 | // Wait for main PLL (PLL0) to come up |
hugozijlmans | 1:2c52307d223f | 87 | while ((PLL0STAT & (1<<24)) == 0x00); |
hugozijlmans | 1:2c52307d223f | 88 | |
hugozijlmans | 1:2c52307d223f | 89 | } |
hugozijlmans | 1:2c52307d223f | 90 | |
hugozijlmans | 1:2c52307d223f | 91 | void LED_init(void) { |
hugozijlmans | 1:2c52307d223f | 92 | |
hugozijlmans | 1:2c52307d223f | 93 | // Set output direction for LEDs |
hugozijlmans | 1:2c52307d223f | 94 | FIODIR |= LED_MASK; |
hugozijlmans | 1:2c52307d223f | 95 | |
hugozijlmans | 1:2c52307d223f | 96 | } |
hugozijlmans | 1:2c52307d223f | 97 |