{
UINT32 ADC_Data=0;
PCONP=PCONP|(1<<12); /*ADC power on*/
/*The PCONP register allows turning off selected peripheral functions for the purpose of
saving power. This is accomplished by gating off the clock source to the specified
peripheral blocks.Some peripherals, particularly those that include analog functions, may consume power
that is not clock dependent. These peripherals may contain a separate disable control that
turns off additional circuitry to reduce power.If a peripheral control bit is 1, that peripheral is enabled.
If a peripheral bit is 0, that peripheral's clock is disabled (gated off) to conserve power */
switch(unit)
{
case 0:
PINSEL1 |= (1<<14); /* AD0.0 *//* pin function configuration*/
AD0CR=(1<<0) | /* SEL =0, select channel 0*/
((Fpclk/1000000-1)<<8) | /* CLKDIV=Fpclk/1000000-1, that is, the conversion clock is 1MHz*/
(0<<16) | /* BURST=0, software control conversion operation*/
(0<<17) | /* CLKS=0, use 11clock conversion*/
(1<<21) | /* PDN=1, normal working mode (non-power-down conversion mode)*/
(0<<22) | /* Reversed*/
(1<<24) | /* START=1, Start AD conversion directly*/
(0<<27);
//DelayNS(0x10);
ADC_Data=AD0DR0;
/**************************************************/
AD0CR=(AD0CR&0x00FFFF00)|0x01|(1<<24); /* Set channel 0 and perform the first conversion*/
//DelayNS(20);
while((AD0DR0&0x80000000)==0); /* Wait for the conversion to end */
//DelayNS(20);
AD0CR=AD0CR|(1<<24); /* Start conversion again*/
while( (AD0DR0&0x80000000)==0); /* Wait for the conversion to end */
ADC_Data=AD0DR0;/* Read the conversion result*/
ADC_Data=(ADC_Data>>6)&0x3FF;/* Value conversion*/
/******************************************************/
break;
case 1:
PINSEL1 |= (1<<16); /* AD0.1 */
AD0CR=(1<<1) | /* SEL =1, select channel 1*/
((Fpclk/1000000-1)<<8) | /* CLKDIV=Fpclk/1000000-1, that is, the conversion clock is 1MHz*/
(0<<16) | /* BURST=0, software control conversion operation*/
(0<<17) | /* CLKS=0, use 11clock conversion*/
(1<<21) | /* PDN=1, normal operation mode (non-power-down conversion mode)*/
(0<<22) | /* Reversed*/
(1<<24) | /* START=1, directly start AD conversion*/
(0<<27);
//DelayNS(0x10);
ADC_Data=AD0DR1;
/**************************************************/
AD0CR=(AD0CR&0x00FFFF00)|0x02|(1<<24); /* Set channel 1 and perform the first conversion*/
//DelayNS(20);
while((AD0DR1&0x80000000)==0); /* Wait for the conversion to end */
//DelayNS(20);
AD0CR=AD0CR|(1<<24); /* Start conversion again*/
while( (AD0DR1&0x80000000)==0); /* Wait for the conversion to end */
ADC_Data=AD0DR1;/* Read the conversion result*/
ADC_Data=(ADC_Data>>6)&0x3FF;/* Value conversion*/
/************************************************************/
break;
case 2:
PINSEL1 |= (1<<18); /* AD0.2 */
AD0CR=(1<<2) | /* SEL =2, select channel 2*/
((Fpclk/1000000-1)<<8) | /* CLKDIV=Fpclk/1000000-1, that is, the conversion clock is 1MHz*/
(0<<16) | /* BURST=0, software control conversion operation*/
(0<<17) | /* CLKS=0, use 11clock conversion*/
(1<<21) | /* PDN=1, normal operation mode (non-power-down conversion mode)*/
(0<<22) | /* Reversed*/
(1<<24) | /* START=1, directly start AD conversion*/
(0<<27);
//DelayNS(0x10);
ADC_Data=AD0DR2;
/**************************************************/
AD0CR=(AD0CR&0x00FFFF00)|0x04|(1<<24); /* Set channel 2 and perform the first conversion*/
//DelayNS(20);
while((AD0DR2&0x80000000)==0); /* Wait for the conversion to end */
//DelayNS(20);
AD0CR=AD0CR|(1<<24); /* Start conversion again*/
while( (AD0DR2&0x80000000)==0); /* Wait for the conversion to end */
ADC_Data=AD0DR2;/* Read the conversion result*/
ADC_Data=(ADC_Data>>6)&0x3FF;/* Value conversion*/
/************************************************************/
break;
case 3:
PINSEL1 |= (1<<20); /* AD0.3 */
AD0CR=(1<<3) | /* SEL =3, select channel 3*/
((Fpclk/1000000-1)<<8) | /* CLKDIV=Fpclk/1000000-1, that is, the conversion clock is 1MHz*/
(0<<16) | /* BURST=0, software control conversion operation*/
(0<<17) | /* CLKS=0, use 11clock conversion*/
(1<<21) | /* PDN=1, normal operation mode (non-power-down conversion mode)*/
(0<<22) | /* Reversed*/
(1<<24) | /* START=1, directly start AD conversion*/
(0<<27);
//DelayNS(0x10);
ADC_Data=AD0DR3;
/**************************************************/
AD0CR=(AD0CR&0x00FFFF00)|0x08|(1<<24); /* Set channel 3 and perform the first conversion*/
//DelayNS(20);
while((AD0DR3&0x80000000)==0); /* Wait for the conversion to end */
//DelayNS(20);
AD0CR=AD0CR|(1<<24); /* Start conversion again*/
while( (AD0DR3&0x80000000)==0); /* Wait for the conversion to end */
ADC_Data=AD0DR3;/* Read the conversion result*/
ADC_Data=(ADC_Data>>6)&0x3FF;/* Value conversion*/
/************************************************************/
break;
case 4:
PINSEL3 |= (3<<28); /* AD0.4 */
AD0CR=(1<<4) | /* SEL =4, select channel 4*/
((Fpclk/1000000-1)<<8) | /* CLKDIV=Fpclk/1000000-1, that is, the conversion clock is 1MHz*/
(0<<16) | /* BURST=0, software control conversion operation*/
(0<<17) | /* CLKS=0, use 11clock conversion*/
(1<<21) | /* PDN=1, normal operation mode (non-power-down conversion mode)*/
(0<<22) | /* Reversed*/
(1<<24) | /* START=1, directly start AD conversion*/
(0<<27);
//DelayNS(0x10);
ADC_Data=AD0DR4;
/******************************************************/
AD0CR=(AD0CR&0x00FFFF00)|0x10|(1<<24); /* Set channel 4 and perform the first conversion*/
//DelayNS(20);
while((AD0DR4&0x80000000)==0); /* Wait for the conversion to end */
//DelayNS(20);
AD0CR=AD0CR|(1<<24); /* Start conversion again*/
while( (AD0DR4&0x80000000)==0); /* Wait for the conversion to end */
ADC_Data=AD0DR4;/* Read the conversion result*/
ADC_Data=(ADC_Data>>6)&0x3FF;/* Value conversion*/
/********************************************************/
break;
case 5:
PINSEL3|=0xc0000000; /* AD0.5 */
AD0CR=(1<<5) | /* SEL =5,Select channel 5*/
((Fpclk/1000000-1)<<8) | /* CLKDIV=Fpclk/1000000-1, that is, the conversion clock is 1MHz*/
(0<<16) | /* BURST=0, software controls the conversion operation*/
(0<<17) | /* CLKS=0, use 11clock conversion*/
(1<<21) | /* PDN=1, normal working mode (non-power-down conversion mode)*/
(0<<22) | /* Reversed*/
(1<<24) | /* START=1, directly start AD conversion*/
(0<<27);
//DelayNS(0x10);
ADC_Data=AD0DR5;
/******************************************************/
AD0CR=(AD0CR&0x00FFFF00)|0x20|(1<<24); /* Set channel 5 for the first conversion*/
//DelayNS(20);
while((AD0DR5&0x80000000)==0); /* Wait for the conversion to end */
//DelayNS(20);
AD0CR=AD0CR|(1<<24); /* Start conversion again*/
while( (AD0DR5&0x80000000)==0); /* Wait for the conversion to end */
ADC_Data=AD0DR5;/*Read conversion result*/
ADC_Data=(ADC_Data>>6)&0x3FF;/*Value conversion*/
/************************************************************/
break;
case 6:
PINSEL0 |= (3<<24); /* AD0.6 */
AD0CR=(1<<6) | /* SEL =6, select channel 6*/
((Fpclk/1000000-1)<<8) | /* CLKDIV=Fpclk/1000000-1, that is, the conversion clock is 1MHz*/
(0<<16) | /* BURST=0, software control conversion operation*/
(0<<17) | /* CLKS=0, use 11clock conversion*/
(1<<21) | /* PDN=1, normal operation mode (non-power-down conversion mode)*/
(0<<22) | /* Reversed*/
(1<<24) | /* START=1, start AD conversion directly*/
(0<<27);
//DelayNS(0x10);
ADC_Data=AD0DR6;
/**************************************************/
AD0CR=(AD0CR&0x00FFFF00)|0x40|(1<<24); /* Set channel 6 for the first conversion*/
//DelayNS(20);
while((AD0DR6&0x80000000)==0); /* Wait for the conversion to end */
//DelayNS(20);
AD0CR=AD0CR|(1<<24); /* Start conversion again*/
while( (AD0DR6&0x80000000)==0); /* Wait for the conversion to end */
ADC_Data=AD0DR6; /* Read the conversion result*/
ADC_Data=(ADC_Data>>6)&0x3FF; /*value conversion*/
/************************************************************/
break;
case 7:
PINSEL0 |= (3<<26); /* AD0.7 */
AD0CR=(1<<7) | /* SEL =7,select channel 7*/
((Fpclk/1000000-1)<<8) | /* CLKDIV=Fpclk/1000000-1,that is,the conversion clock is 1MHz*/
(0<<16) | /* BURST=0,software control conversion operation*/
(0<<17) | /* CLKS=0,use 11clock conversion*/
(1<<21) | /* PDN=1,normal working mode (non power-down conversion mode)*/
(0<<22) | /* Reversed*/
(1<<24) | /* START=1,Directly start AD conversion*/
(0<<27);
//DelayNS(0x10);
ADC_Data=AD0DR7;
/**************************************************/
AD0CR=(AD0CR&0x00FFFF00)|0x40|(1<<24); /* Set channel 6 for the first conversion*/
//DelayNS(20);
while((AD0DR7&0x80000000)==0); /* Wait for the conversion to end */
//DelayNS(20);
AD0CR=AD0CR|(1<<24); /* Start conversion again*/
while( (AD0DR7&0x80000000)==0); /* Wait for the conversion to end */
ADC_Data=AD0DR7;/* Read the conversion result*/
ADC_Data=(ADC_Data>>6)&0x3FF;/* Value conversion*/
/************************************************************/
break;
default:
break;
}
//ADC_result = ((ADC_Data*1.0/1023)/0.4*3.3);
return(ADC_Data);
}
Previous article:LPC23xx reads and writes AT24C64 via I2C interface
Next article:Some concepts about ARM
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 【NUCLEO-L552ZE Review】- 7 : EXTI - One unexpected thing after another
- Key scanning program based on FPGA
- Issues that should be paid attention to when drawing PCB diagrams from the perspective of welding
- How to design a battery tester for various battery sizes, voltages and form factors
- Can anyone help analyze the parameters of this DC-DC transformer?
- In the 5G era, IoT technology empowers smart healthcare
- 【TouchGFX Design】(2) Simple interface design
- Sony HT-Z9F speaker system disassembled with Rockchip RKNanoD chip
- [Rvb2601 Creative Application Development] lvgl Usage 2 - Drawing
- [DWIN Serial Port Screen] Nucleic Acid Sampling and Registration System - Three Links to DWIN Cloud