微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > TFT之AD画线 --模拟示波器

TFT之AD画线 --模拟示波器

时间:11-26 来源:互联网 点击:
//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--);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top