#include <LPC214x.h>
void init_clock()
{
//fosc=12MHz
PLL0CFG=0x23; //MSEL=4, PSEL=2
PLL0CON=0x01; //Enable PLL
PLL0FEED=0x55; //update register PLLCFG
PLL0FEED=0xAA; //update register PLLCON
while(!(PLL0STAT&0x00000400)); //check LOCK bit
PLL0CON=0x00000003; //if LOCK=1 than connect
PLL0FEED=0x55; //update register PLLCFG
PLL0FEED=0xAA; //update register PLLCON
VPBDIV=0x01; //PCLK=CCLK
}
int main (void) {
int value;
int result;
init_clock();
PINSEL1 =0x01000000; //pin P0.28 is AD1 convertor
IODIR1 =0x00FF0000; //P1.16 - P1.23 output LED
IOCLR1 =0x00FF0000; //LEDs off initialy
AD0CR=0x002F1302; //AD0.1, 3MHz, 3bit
while(1){
AD0CR=AD0CR|0x01000000; //Start ADC, START=001;
while ((AD0DR1 & 0x80000000) == 0); //wait until ADC is done
AD0CR &= ~0x01000000; //stop ADC, START=000;
IOCLR1 = 0x00FF0000; //LEDs off
value = AD0DR1 & 0x000001C0; //take result, bits 6,7 and 8
result = value >> 6;
if(result == 0)
IOSET1 = 1 << 16;
else if(result == 1)
IOSET1 = 1 << 17;
else if(result == 2)
IOSET1 = 1 << 18;
else if(result == 3)
IOSET1 = 1 << 19;
else if(result == 4)
IOSET1 = 1 << 20;
else if(result == 5)
IOSET1 = 1 << 21;
else if(result == 6)
IOSET1 = 1 << 22;
else if(result == 7)
IOSET1 = 1 << 23;
}
}