新手上路
- 积分
- 35
- 金钱
- 35
- 注册时间
- 2016-2-26
- 在线时间
- 8 小时
|
1金钱
/*******************************************************************************
1¤3ìÎļtμÄ¿aê¼
ËùóDí·ÎļtóÃ<includes.h>°üo¬
Ö÷oˉêyÎļt½øDDê±ÖóoíÖD¶ÏμÄÅäÖÃ
*******************************************************************************/
#include <includes.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define ADC1_DR_Address ((u32)0x4001244C)
int AD_value;
static unsigned long ticks;
int ExTick;
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void DMA_Configuration(void);
void ADC_Configuration(void);
int main (void)
{
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
ili9320_Initializtion();
ili9320_Clear(0xffff);
DMA_Configuration();
ADC_Configuration();
GUI_Text(80,60,"ADC_DMA_TEST",12,0x0000,0xffff);
GUI_Text(80,80,"Input-IO A0",12,0x0000,0xffff);
GUI_Text(80,100,"ADC_Value:",10,0x0000,0xffff);
GUI_Text(80,120,"Voltage_V:",10,0x0000,0xffff);
GUI_Text(210,120,"V",1,0x0000,0xffff);
//èçDèòa¾«è·Î趨μÄ2é¼ˉ£¬Dèòa×ÔDDÔö¼óèí¼tÂË2¨3ìDò
while(1)
{
ticks=ticks+1;
if (ticks >= 400000)
{
ticks = 0;
//ÏÔê¾ADCÖμ
GUI_Word(170,100,5,AD_value,0,0xffff,Magenta);
//ÏÔê¾μçÑ1Öμ
GUI_Word(170,120,4,((3.3/4096)*AD_value)*1000,3,0xffff,Magenta);
}
}
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
if(RCC_WaitForHSEStartUp() == SUCCESS) /* Wait till HSE is ready μè′yía2¿¾§ÕñÆô¶ˉ*/
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //9±¶Æμ 8M*9=72M
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : Configures the different GPIO ports.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//½« A0ÅäÖÃÎaADCêäèë¶Ë¿ú
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //ê1ÄüDMA1ê±Öó
/* DMA channel1 configuration ----------------------------------------------*/
//ê1ÄüDMA
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&AD_value;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
}
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //ê1ÄüADC1ê±Öó
/* ADC1 configuration ------------------------------------------------------*/
//ADCÅäÖÃ
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC1oíADC21¤×÷Ôú¶àá¢Ä£ê½
ADC_InitStructure.ADC_ScanConvMode = ENABLE;//Ä£êy×a»»1¤×÷Ôúé¨Ãèģ꽣¨¶àí¨μࣩ»1êÇμ¥′Σ¨μ¥í¨μࣩģê½
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//Ä£êy×a»»1¤×÷Ôúé¨Ãèģ꽣¨¶àí¨μࣩ»1êÇμ¥′Σ¨μ¥í¨μࣩģê½
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//×a»»óéèí¼t¶ø2»êÇía2¿′¥·¢Æô¶ˉ
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//ADCêy¾Yóò¶ÔÆë
ADC_InitStructure.ADC_NbrOfChannel = 1;//1涨½øDD1æÔò×a»»μÄADCí¨μàμÄêyÄ¿¡£Õa¸öêyÄ¿μÄè¡Öμ·¶Î§êÇ1μ½16
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channels configuration [1æÔòÄ£ê½í¨μàÅäÖÃ]*/
ADC_RegularChannelConfig(ADC1, ADC_Channel_0 ,1, ADC_SampleTime_55Cycles5);
/* Enable ADC1 DMA [ê1ÄüADC1 DMA]*/
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 [ê1Äü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);
}
|
-
|