First Version
Dependencies: EthernetInterface mbed-rtos mbed
adc.c
00001 /* 00002 * adc.c 00003 * 00004 * Created on: 02/07/2011 00005 * Author: francisco 00006 */ 00007 00008 #include <LPC17xx.h> 00009 #include "adc.h" 00010 00011 void init_adc(int adc_clk) 00012 { 00013 // Turn on power to ADC block 00014 LPC_SC->PCONP |= PCADC; 00015 00016 // Turn on ADC peripheral clock 00017 LPC_SC->PCLKSEL0 &= ~(3 << PCLK_ADC); 00018 LPC_SC->PCLKSEL0 |= (ADC_CCLK << PCLK_ADC); //CLK/8 00019 00020 unsigned int clkdiv = (SystemCoreClock/1)/65; 00021 clkdiv = clkdiv/adc_clk; 00022 00023 LPC_ADC->ADCR &= ~(ADC_OPERATIONAL|ADC_CLKDIV(255)); 00024 LPC_ADC->ADCR |= (ADC_OPERATIONAL|ADC_CLKDIV(clkdiv)); 00025 00026 //NVIC_EnableIRQ(ADC_IRQn); 00027 } 00028 00029 void setup_start(int mode,int edge) 00030 { 00031 LPC_ADC->ADCR |= mode; 00032 } 00033 00034 void select_channels(int adc_ch) 00035 { 00036 LPC_ADC->ADCR &= ~(ADC_CH_0|ADC_CH_1|ADC_CH_2|ADC_CH_3|ADC_CH_4|ADC_CH_5|ADC_CH_6|ADC_CH_7); 00037 LPC_ADC->ADCR |= adc_ch; 00038 00039 LPC_ADC->ADINTEN |= (1U<<8);//adc_ch; 00040 00041 if(adc_ch&ADC_CH_0) 00042 { 00043 LPC_PINCON->PINSEL1 |= 1U<<14; 00044 LPC_PINCON->PINMODE1 |= 2U<<14; 00045 } 00046 if(adc_ch&ADC_CH_1) 00047 { 00048 LPC_PINCON->PINSEL1 |= 1U<<16; 00049 LPC_PINCON->PINMODE1 |= 2U<<16; 00050 } 00051 if(adc_ch&ADC_CH_2) 00052 { 00053 LPC_PINCON->PINSEL1 |= 1U<<18; 00054 LPC_PINCON->PINMODE1 |= 2U<<18; 00055 } 00056 if(adc_ch&ADC_CH_3) 00057 { 00058 LPC_PINCON->PINSEL1 |= 1U<<20; 00059 LPC_PINCON->PINMODE1 |= 2U<<20; 00060 } 00061 if(adc_ch&ADC_CH_4) 00062 { 00063 LPC_PINCON->PINSEL3 |= 3U<<28; 00064 LPC_PINCON->PINMODE3 |= 2U<<28; 00065 } 00066 if(adc_ch&ADC_CH_5) 00067 { 00068 LPC_PINCON->PINSEL3 |= 3U<<30; 00069 LPC_PINCON->PINMODE3 |= 2U<<30; 00070 } 00071 if(adc_ch&ADC_CH_6) 00072 { 00073 LPC_PINCON->PINSEL0 |= 2U<<6; 00074 LPC_PINCON->PINMODE0 |= 2U<<6; 00075 } 00076 if(adc_ch&ADC_CH_7) 00077 { 00078 LPC_PINCON->PINSEL0 |= 2U<<4; 00079 LPC_PINCON->PINMODE0 |= 2U<<4; 00080 } 00081 }
Generated on Thu Jul 21 2022 16:56:17 by 1.7.2