本帖最后由 missing01 于 2014-3-30 08:13 编辑
//#include <stm32f0xx_lib.h>
#include <stdint.h>
#include <system_stm32f0xx.h>
#include <stm32f0xx_gpio.h>
#include <Main.h>
#include "systick.h"
#include "LCD32.h"
#include "font.h"
#define ADC1_DR_Address 0x40012440
volatile uint16_t RegularConvData_Tab; //ÓÃÓÚ´¢´æ´ÓADC¶Áµ½µÄÖµ
void LedInit()
{
GPIO_InitTypeDef gpiostudy;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB ,ENABLE);//ʹÄÜAHBÍâÉèGPIOBʱÖÓ
gpiostudy.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6
|GPIO_Pin_7;
gpiostudy.GPIO_Mode=GPIO_Mode_OUT;
gpiostudy.GPIO_Speed=GPIO_Speed_50MHz;
gpiostudy.GPIO_PuPd=GPIO_PuPd_NOPULL;
gpiostudy.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOB,&gpiostudy);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC ,ENABLE);//ʹÄÜAHBÍâÉèGPIOCʱÖÓ
gpiostudy.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6
|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14;
gpiostudy.GPIO_Mode=GPIO_Mode_OUT;
gpiostudy.GPIO_Speed=GPIO_Speed_50MHz;
gpiostudy.GPIO_PuPd=GPIO_PuPd_NOPULL;
gpiostudy.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOC,&gpiostudy);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA ,ENABLE);//ʹÄÜAHBÍâÉèGPIOAʱÖÓ
gpiostudy.GPIO_Pin=GPIO_Pin_11;
gpiostudy.GPIO_Mode=GPIO_Mode_OUT;
gpiostudy.GPIO_Speed=GPIO_Speed_50MHz;
gpiostudy.GPIO_PuPd=GPIO_PuPd_NOPULL;
gpiostudy.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOA,&gpiostudy);
}
/********************************************************************************
º¯ÊýÃû£ºADC_DMA_Config
¹¦ÄÜ£ºADC DMA³õʼ»¯£¬ADCͨµÀÑ¡Ôñ
*******************************************************************************/
void ADC_DMA_Config()
{
ADC_InitTypeDef ADC_InitStruct;
DMA_InitTypeDef DMA_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable GPIOA clock */
// RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* ADC1 Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* DMA1 clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);
/* Configure PA.0 as analog input */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStruct); // PA0,ÊäÈëʱ²»ÓÃÉèÖÃËÙÂÊ
/* DMA1 Channel1 Config */
DMA_DeInit(DMA1_Channel1);
DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address; //ÉèÖÃÍâÉè»ùµØÖ·
DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)&RegularConvData_Tab;
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStruct.DMA_BufferSize =4;
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
DMA_InitStruct.DMA_Priority = DMA_Priority_High;
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStruct);
// /* ADC DMA request in circular mode */
ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);
/* DMA1 Channel1 enable */
DMA_Cmd(DMA1_Channel1, ENABLE);
// /* ADC DMA request in circular mode */
ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);
/* Initialize ADC structure */
ADC_StructInit(&ADC_InitStruct);
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_ContinuousConvMode = ENABLE;
ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct.ADC_ScanDirection = ADC_ScanDirection_Backward;
ADC_Init(ADC1, &ADC_InitStruct);
// /* Convert the ADC1 temperature sensor with 55.5 Cycles as sampling time */
// ADC_ChannelConfig(ADC1, ADC_Channel_TempSensor , ADC_SampleTime_55_5Cycles);
// ADC_TempSensorCmd(ENABLE);
/* Convert the ADC1 Vref with 55.5 Cycles as sampling time */
ADC_ChannelConfig(ADC1, ADC_Channel_1 , ADC_SampleTime_55_5Cycles);
// ADC_VrefintCmd(ENABLE);
/* ADC Calibration */
ADC_GetCalibrationFactor(ADC1);
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Wait the ADCEN falg */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
/* ADC1 regular Software Start Conv */
ADC_StartOfConversion(ADC1); //加上这个函数,LCD显示出问题,不加这个函数,LCD显示正常
}
int main()
{
SystemInit();
// ADC_DMA_Config();
//GPIO_DeInit(GPIOB);
// GPIO_DeInit(GPIOC);
LedInit();
// Uart_NVICInit();
// SysTick_Config(SysTick_CLKSource_HCLK); //sistickʱÖÓԴΪAHB ʱÖÓ
GPIO_ResetBits(GPIOA,GPIO_Pin_11);//µÆÁÁ
Systick_NVICInit();
// Delay(2000);
BACK_COLOR=BLACK;
POINT_COLOR=WHITE;
Lcd_Init();
//
/* GPIO_SetBits(GPIOA,GPIO_Pin_11);//µÆÃðÁ
Delay(2000);
LCD_Clear(RED);
GPIO_ResetBits(GPIOA,GPIO_Pin_11);//µÆÁÁ
Delay(3000);
LCD_Clear(GREEN);
Delay(3000);
LCD_WR_DATA8(0x0f,0x0f);
*/
//
//
// LCD_DrawPoint_big(100,100);
// LCD_DrawPoint(100,100);
//LCD_Fill(0,0,120,120,BLUE);
//LCD_DrawLine(0,0,150,150);
// LCD_DrawRectangle(100,100,200,200);
//Draw_Circle(100,100,100);
//LCD_ShowNum(100,100,102,3);//ʧ°Ü
// LCD_ShowChar(10,10,'a',0);//ʧ°Ü
LCD_Clear(BLACK);
LCD_ShowString(55,30,"ADC-DMA TEST");
// showhanzi(100,100,0);
// showhanzi(135,100,1);
//showhanzi(170,100,2);
//showimage();
while(1)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_11);
Delay(1000); //1s
GPIO_SetBits(GPIOA,GPIO_Pin_11);
Delay(2000); //1s¡
// ADC_ConvertedValueLocal= RegularConvData_Tab;
Delay(1000); //1s
LCD_ShowString(20,60,"adc value:");
LCD_ShowNum(100,60,RegularConvData_Tab,4);
// ADC1->CR&=(~(1<<2))|(~(1<<0));
// ADC1->CR|=(1<<2);
}
}
|
|