/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
/* System clocks configuration ---------------------------------------------*/
RCC_Configuration();
/* NVIC configuration ------------------------------------------------------*/
NVIC_Configuration();
/* GPIO configuration ------------------------------------------------------*/
GPIO_Configuration();
LcdShow_Init();
/* DMA1 channel1 configuration ----------------------------------------------*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //Enable DMA clock
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//Peripheral address
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_RCVTab;//Memory address
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//dma transmission direction unidirectional
DMA_InitStructure.DMA_BufferSize = 160;//Set the length of the DMA buffer during transmission word
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//Set the peripheral increment mode of DMA, one peripheral
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//Set the memory increment mode of DMA,
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//Peripheral data word
lengthDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//Memory data word
lengthDMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//Set DMA transfer mode: continuous circular modeDMA_InitStructure.DMA_Priority
= DMA_Priority_High;//Set DMA priority levelDMA_InitStructure.DMA_M2M
= DMA_M2M_Disable;//Set variables in 2 DMA memories to access each otherDMA_Init
(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//Independent working modeADC_InitStructure.ADC_ScanConvMode
= ENABLE;//Scan modeADC_InitStructure.ADC_ContinuousConvMode = ENABLE
;//Continuous conversionADC_InitStructure.ADC_ExternalTrigConv
= ADC_ExternalTrigConv_None;//External trigger disabledADC_InitStructure.ADC_DataAlign
= ADC_DataAlign_Right;//Data right
alignmentADC_InitStructure.ADC_NbrOfChannel = 8;//Number of channels used for conversionADC_Init
(ADC1, &ADC_InitStructure);
/* ADC1 regular channels configuration [规则模式通道配置]*/
ADC_RegularChannelConfig(ADC1, ADC_Channel_8 , 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_9 , 2, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 3, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 4, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 5, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 6, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 7, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 8, ADC_SampleTime_239Cycles5);
/* Enable ADC1 DMA [使能ADC1 DMA]*/
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 [使能ADC1]*/
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(RESET==DMA_GetFlagStatus(DMA1_FLAG_TC1)); //自己添加
while(1)
{
vu16 value1 = 0;
vu16 value2 = 0;
vu16 value3 = 0;
vu16 value4 = 0;
vu16 value5 = 0;
vu16 value6 = 0;
vu16 value7 = 0;
vu16 value8 = 0;
value1 = average(ADC_RCVTab,0);
value2 = average(ADC_RCVTab,1);
value3 = average(ADC_RCVTab,2);
value4 = average(ADC_RCVTab,3);
value5 = average(ADC_RCVTab,4);
value6 = average(ADC_RCVTab,5);
value7 = average(ADC_RCVTab,6);
value8 = average(ADC_RCVTab,7);
u8 num1 = value3 % 10;
u8 num2 = (value3 / 10) % 10;
u8 num3= (value3 / 100) % 10;
u8 num4 = value3 / 1000;
if (num1 > 9)
display[3] = num1 + (65 - 10);
else
display[3] = num1 + (48-0);
if (num2 > 9)
display[2] = num2 +(65 - 10);
else
display[2] = num2 + (48 - 0);
if (num3>9)
display[1]=num3+(65-10);
else
display[1]=num3+(48-0);
if (num4>9)
display[0]=num4+(65-10);
else
display[0]=num4+(48-0);
write_string(display);
delay();
}
}
u16 average(vu16 ADCDataTab[], u16 nChannel) //Add by yourself
{
u16 averagevalue=0, maxvalue=0, minvalue=0xFFFF, i;
for (i=0;i<20;i++)
{
averagevalue += *(ADCDataTab+nChannel+i*8);
if(*(ADCDataTab+nChannel+i*8)>maxvalue)
maxvalue=*(ADCDataTab+nChannel+i*8);
if(*(ADCDataTab+nChannel+i*8)
}
return ((averagevalue-maxvalue-minvalue)/18); //This will take time and is not advisable. It is best to use >>
}
Previous article:STM32 Development Board Basic Tutorial (Ten) - An Introduction to RTC
Next article:How to debug stm32 in ram under ulink
Recommended ReadingLatest update time:2024-11-16 17:47
- Popular Resources
- Popular amplifiers
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
- Can anyone provide a download link for the AD package library (with 3D effects)? It's quite complete. Thank you.
- [ESP32-Korvo Review] (1) Development Board Circuit Connection
- What to do if ESP32-WROOM-32 has high power consumption when connected to the Internet
- Use the hal library to drive ra8875 using the Red Bull development board
- RK3288 All-in-one open source motherboard
- Download: Qorvo Ultra-Wideband (UWB) For Dummies
- EEWORLD University Hall----MCU Principles and Applications Harbin Institute of Technology
- Regarding the calculation correction of the article "Starting from the sensitivity of GPS receivers"
- Selection of Typical Design Examples of Switching Power Supplies
- Delay problem in single chip microcomputer