//Author:"淚與汗的纏綿"//Data:2011-11月
本文引用地址:http://m.butianyuan.cn/article/201611/321620.htm//功能:DA驅(qū)動(dòng)程序,TFT函數(shù)的配置
#include "yf_tft.h"
u8 cnt;
ADC_InitTypeDef ADC_InitStructure;
voidADC_configuration(void);
voidDAC_Configuration(void);
int average_volt(void);
void Delayms(u16 t);
int main(void)
{float AD_value;
u16 DAC_data;int x,y;
RCC_Configuration();
ADC_configuration();
DAC_Configuration();
ili9320_Initializtion(); //端口引腳初始化
ili9320_Delay(800000);
ili9320_Clear(Blue);
TFT_DrawLine(3,4,3,235,Black);
TFT_DrawLine(4,4,4,235,Black);
TFT_DrawLine(2,229,315,229,Black);
TFT_DrawLine(2,230,315,230,Black);
TFT_DrawLine(4,4,315,4,Red);
Display_Grid(Black);
LCD_showzifustr(100,100,"晶體管特性曲線",Black,Blue);
while(1)
{if(cnt>50)
DAC_data=DAC_data+0x00f0;
DAC_SetChannel2Data(DAC_Align_12b_L, DAC_data);//設(shè)置DAC通道1為12位且數(shù)據(jù)左對(duì)齊模式
DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE);//使能DAC通道1的軟件觸發(fā)方式,轉(zhuǎn)換一次
DAC_SetChannel1Data(DAC_Align_12b_L, DAC_data);//設(shè)置DAC通道1為12位且數(shù)據(jù)左對(duì)齊模式
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);//使能DAC通道1的軟件觸發(fā)方式,轉(zhuǎn)換一次
AD_value=average_volt();
AD_value=AD_value/4095.0*3.3;
AD_value=AD_value*1000.0;
Display_variate(60,16,AD_value);
x++;
y=229-AD_value*227/4096;
if(x>320)
{
x=0;
ili9320_Clear(Blue);
Display_Grid(Black);
TFT_DrawLine(3,4,3,235,Black);
TFT_DrawLine(4,4,4,235,Black);
TFT_DrawLine(2,229,315,229,Black);
TFT_DrawLine(2,230,315,230,Black);
TFT_DrawLine(4,4,315,4,Red);
}
ili9320_SetPoint(x,y,Red);
Delayms(1);
}
}
void RCC_Configuration(void)
{
SystemInit () ;//很重要?。。?!
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC,ENABLE);
}
////////////AD的配置函數(shù)/////////////////////////////
voidADC_configuration()
{
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);
}
////////////AD濾波函數(shù)/////////////////////////////
int average_volt()
{
u16 sum=0,i,AD_value;
for(i=0;i<10;i++)
{
AD_value=ADC_GetConversionValue(ADC1);
sum=sum+AD_value;
}
return sum=sum/i;
}
void DAC_Configuration(void)
{
DAC_InitTypeDef DAC_InitStructure;
DAC_InitStructure.DAC_Trigger=DAC_Trigger_Software;//DAC觸發(fā)方式為軟件控制
DAC_InitStructure.DAC_WaveGeneration=DAC_WaveGeneration_None;
//不從DAC端口產(chǎn)生波形
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bits8_0; //8位DA波形生成模式
DAC_InitStructure.DAC_OutputBuffer=DAC_OutputBuffer_Enable;
//使能DAC輸出緩沖器
//用上面參數(shù)初始化DAC通道1
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Cmd(DAC_Channel_1, ENABLE);//使能DAC通道1
DAC_Init(DAC_Channel_2, &DAC_InitStructure);//用上面參數(shù)初始化DAC通道1
DAC_Cmd(DAC_Channel_2, ENABLE);//使能DAC通道1
}
void Delayms(u16 t)// Delay Time about 1 ms;
{
u16 i;
cnt++;
do
{
for (i=0; i<500; i++);
}
while(t--);
}
評(píng)論