完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
以下为main程序被注释部分是我想添加的部分 #include "public.h" #include "adc.h" #include "systick.h" #include "gui.h" int main(void) { GPIO_InitTypeDef GPIO_InitStructure; switch() u8 i,dat1[6],dat2[6],dat3[6],dat4[6]; u16 value; // u16 IC2value; float ad; TFT_Init(); //TFT初始化 adc_init(); //ADC初始化 TFT_ClearScreen(BLACK); GUI_Show12ASCII(10,100," Vm/V ",YELLOW,BLACK); GUI_Show12ASCII(10,130," F/HZ ",YELLOW,BLACK); GUI_Show12ASCII(10,160," D/% ",YELLOW,BLACK); GUI_Show12ASCII(10,190," Tr/ns ",YELLOW,BLACK); while(1) { // GPIO_InitTypeDef GPIO_InitStructure; // NVIC_InitTypeDef NVIC_InitStructure; // TIM_ICInitTypeDef TIM_ICInitStructure; // // // RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //时钟配置 // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //GPIO配置 // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // GPIO_Init(GPIOA, &GPIO_InitStructure); // // NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //NVIC配置 // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // NVIC_Init(&NVIC_InitStructure); // // TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; //通道选择 // TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿触发 // TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //管脚与寄存器对应关系 // TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; ////输入预分频。意思是控制在多少个 输入周期做一次捕获,如果 ////输入的信号频率没有变,测得的周期也不会变。比如选择4分频,则每四个输入周期才做一次捕获,这样在输入信号变化不频繁的情况下, ////可以减少软件被不断中断的次数。 // TIM_ICInitStructure.TIM_ICFilter = 0x0; //滤波设置,经历几个周期跳变认定波形稳定0x0~0xF // TIM_PWMIConfig(TIM3, &TIM_ICInitStructure); //根据参数配置TIM外设信息 // TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2); //选择IC2为始终触发源 // TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset); // //TIM从模式:触发信号的上升沿重新初始化计数器和触发寄存器的更新事件 // TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable); //启动定时器的被动触发 // TIM_Cmd(TIM3, ENABLE); //启动TIM3 // TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE); //打开中断 value=0; for(i=0;i<10;i++) { ADC_SoftwareStartConvCmd(ADC1, ENABLE); while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));//转换结束标志位 value=value+ADC_GetConversionValue(ADC1);//返回最近一次ADCx规则组的转换结果 } value=value/10; ad=value*3.3/4096; value=(u16)(ad*100); dat1[0]=value/100+0x30; dat1[1]='.'; dat1[2]=value%100/10+0x30; dat1[3]=value%100%10+0x30; dat1[4]='0'; dat1[5]=' |