新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > DA驅(qū)動(dòng)程序 函數(shù)配置

DA驅(qū)動(dòng)程序 函數(shù)配置

作者: 時(shí)間:2016-11-26 來(lái)源:網(wǎng)絡(luò) 收藏
//Author:"淚與汗的纏綿"

//Data:2011-11月

本文引用地址:http://m.butianyuan.cn/article/201611/321619.htm

//功能:DA驅(qū)動(dòng)程序,函數(shù)配置
#include "main.h"
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDefGPIO_InitStructure;
u8 Rx_Buffer[128*2];
vu32 FLASH_ID = 0;
#defineM25P64_FLASH_ID0x202017
float AD_value;
//u16 colors[]={
//0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff ,0x7bef
//};



static vu32 TimingDelay = 0;
static vu32 LedShowStatus = 0;
static volatile ErrorStatus HSEStartUpStatus = SUCCESS;
voidADC_configuration();


int main(void)
{
RCC_Init();
ADC_configuration();
LCD_Display_Color(0xffe0);
LCD_SetBackColor(0xffe0);
LCD_SetTextColor(0x07e0);

while (1)
{
AD_value=ADC_GetConversionValue(ADC1);
AD_value=AD_value/4095.0*3.3;
AD_value=AD_value*1000.0;
Display_variate(60,16,AD_value);
}
}


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_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_GPIOB |RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOD| RCC_APB2Periph_AFIO, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);


RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);



RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM4, ENABLE);



SysTick_Config();

STM3210B_LCD_Init();


SPI_FLASH_Init();


FLASH_ID = SPI_FLASH_ReadID();

if(FLASH_ID == M25P64_FLASH_ID)
{

GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_SET);
}
else
{

GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_SET);
}
}


void SysTick_Config(void)
{

SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);


SysTick_SetReload(720000);


SysTick_ITConfig(ENABLE);
}



void Delay(u32 nCount)
{
TimingDelay = nCount;


SysTick_CounterCmd(SysTick_Counter_Enable);

while(TimingDelay != 0)
{
}


SysTick_CounterCmd(SysTick_Counter_Disable);


SysTick_CounterCmd(SysTick_Counter_Clear);
}



void Decrement_TimingDelay(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
////////////AD的配置函數(shù)/////////////////////////////
voidADC_configuration()
{

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_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_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel=1;//指定用于轉(zhuǎn)換的通道數(shù)
ADC_Init(ADC1, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_55Cycles5);

ADC_Cmd(ADC1, ENABLE);

ADC_ResetCalibration(ADC1);

while(ADC_GetResetCalibrationStatus(ADC1));//等待ADC的校準(zhǔn)寄存器被設(shè)置完畢

ADC_StartCalibration(ADC1);

while(ADC_GetCalibrationStatus(ADC1));

ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}



評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉