您的位置 首页 开关

10路AD驱动程序

Author:泪与汗的缠绵Data:2011-11月功能:10路AD驱动程序,TFT函数的配置includestm32f10x_libhincludestdiohinclude

//Author:”泪与汗的纠缠”

//Data:2011-11月

//功用:10路AD驱动程序,TFT函数的装备

#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 规矩组的转化成果
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;// 规矩了次序进行规矩转化的 ADC 通道的数目。这个数目的取值规模是 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;//外设作为数据传输的来历(外设传到内存) DMA_DIR_PeripheralDST——内存传到外设
DMA_InitStructure.DMA_BufferSize =10;//接连转化10个AD通道值
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设寄存器地址不变
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//内存寄存器地址递加
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //外设数据宽度32bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//内存数据宽度32bit
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA形式是循环
DMA_InitStructure.DMA_Priority = DMA_Priority_High;//DMA优先级
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//DMA没有设置内存到内存传输
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel1, ENABLE);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/dianyuan/kaiguan/257886.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部