analogin
Published 04 Jan 2010, by
Simon Ford

No tags
« Back to documentation index
Show/hide line numbers
main.cpp Source File
main.cpp
00001
00002
00003 #include "mbed.h"
00004
00005 int main() {
00006
00007
00008 LPC_SC->PCONP |= (1 << 12);
00009 LPC_SC->PCLKSEL0 &= ~(0x3 << 24);
00010
00011
00012 LPC_ADC->ADCR = (0 << 0)
00013 | (25 << 8)
00014 | (0 << 16)
00015 | (0 << 17)
00016 | (1 << 21)
00017 | (0 << 24)
00018 | (0 << 27);
00019
00020
00021 LPC_PINCON->PINSEL3 &= ~((unsigned int)0x3 << 30);
00022 LPC_PINCON->PINSEL3 |= (unsigned int)0x3 << 30;
00023
00024 LPC_PINCON->PINMODE3 &= ~((unsigned int)0x3 << 30);
00025 LPC_PINCON->PINMODE3 |= (unsigned int)0x2 << 30;
00026
00027 while(1) {
00028
00029 LPC_ADC->ADCR &= ~0xFF;
00030 LPC_ADC->ADCR |= 1 << 5;
00031 LPC_ADC->ADCR |= 1 << 24;
00032
00033
00034 unsigned int data;
00035 do {
00036 data = LPC_ADC->ADGDR;
00037 } while ((data & ((unsigned int)1 << 31)) == 0);
00038
00039
00040 LPC_ADC->ADCR &= ~(1 << 24);
00041
00042 printf("0x%3X\n", data);
00043 }
00044 }