//Author:"淚與汗的纏綿"//Data:2011-11月
本文引用地址:http://m.butianyuan.cn/article/201611/321621.htm//功能:10路AD驅動程序,TFT函數(shù)的配置
#include "stm32f10x_lib.h"
#include"stdio.h"
#include "main.h"
u8 Rx_Buffer[128*2];
vu32 FLASH_ID = 0;
#defineM25P64_FLASH_ID0x202017
//u16 colors[]={
//0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff ,0x7bef
//};
RCC_Init();
ADC_configuration();
DMA_Configuration();
LCD_Display_Color(0xffe0);
LCD_SetBackColor(0xffe0);
LCD_SetTextColor(0x07e0);
while (1)
{
for(cnt=0;cnt<10;cnt++)
{
AD_value=ADC_ConvertedValue[cnt];//返回最近一次 ADCx 規(guī)則組的轉換結果
AD_value=AD_value/4095.0*3.3;
readAD[cnt]=AD_value*1000.0;
Display_variate(cnt*15,80,cnt);
}
for(cnt=0;cnt<10;cnt++)
Display_variate(cnt*15,2,readAD[cnt]);
}
}
void RCC_Init(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus==SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_ADCCLKConfig(RCC_PCLK2_Div4);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
STM3210B_LCD_Init();
SPI_FLASH_Init();
}
void Delay(u32 t)// Delay Time about 1 ms;
{
u16 i;
do
{
for(i=0; i<5000; i++);
}
while(t--);
}
voidADC_configuration()
{
ADC_InitTypeDefADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode=ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_NbrOfChannel=10;// 規(guī)定了順序進行規(guī)則轉換的 ADC 通道的數(shù)目。這個數(shù)目的取值范圍是 1 到16。
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0,2, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_1,3, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2,4, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_3,5, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_4,6, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_5,7, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_6,8, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_7,9, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 10, ADC_SampleTime_55Cycles5);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));//等待ADC的校準寄存器被設置完畢
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
}
void DMA_Configuration(void)
{
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)ADC1_DR_Address;//定義DMA外設基地址
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;// 定義DMA內存基地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//外設作為數(shù)據(jù)傳輸?shù)膩碓矗ㄍ庠O傳到內存) DMA_DIR_PeripheralDST——內存?zhèn)鞯酵庠O
DMA_InitStructure.DMA_BufferSize =10;//連續(xù)轉化10個AD通道值
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外設寄存器地址不變
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//內存寄存器地址遞增
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //外設數(shù)據(jù)寬度32bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//內存數(shù)據(jù)寬度32bit
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA模式是循環(huán)
DMA_InitStructure.DMA_Priority = DMA_Priority_High;//DMA優(yōu)先級
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//DMA沒有設置內存到內存?zhèn)鬏?br />DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel1, ENABLE);
}
評論