//Author:”泪与汗的纠缠”
//Data:2011-11月
//功用:DA驱动程序,TFT函数的装备
#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);//设置DAC通道1为12位且数据左对齐形式
DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE);//使能DAC通道1的软件触发方法,转化一次
DAC_SetChannel1Data(DAC_Align_12b_L, DAC_data);//设置DAC通道1为12位且数据左对齐形式
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);//使能DAC通道1的软件触发方法,转化一次
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的装备函数/////////////////////////////
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;//指定用于转化的通道数
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的校准寄存器被设置结束
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
////////////AD滤波函数/////////////////////////////
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触发方法为软件操控
DAC_InitStructure.DAC_WaveGeneration=DAC_WaveGeneration_None;
//不从DAC端口发生波形
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bits8_0; //8位DA波形生成形式
DAC_InitStructure.DAC_OutputBuffer=DAC_OutputBuffer_Enable;
//使能DAC输出缓冲器
//用上面参数初始化DAC通道1
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Cmd(DAC_Channel_1, ENABLE);//使能DAC通道1
DAC_Init(DAC_Channel_2, &DAC_InitStructure);//用上面参数初始化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–);
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/bandaoti/fenxiao/257885.html