//主程序
int main()
{
u16 value,value1,value2;
float ad;
u8 i=0,j,dat[7],dat1[7];
pwm_dac_init();
adc_init();
TFT_Init(); //TFT 彩屏初始化
LED_Init(); //端口初始化
printf_init(); //printf 初始化
TFT_ClearScreen(BLACK); //清屏
GUI_Show12ASCII(10,10,"This is a PWM-DAC Check!",YELLOW,BLACK);
GUI_Show12ASCII(10,27,"Connect the PB6 PB0!",YELLOW,BLACK);
GUI_Show12ASCII(10,100,"The DA Value is:",YELLOW,BLACK);
GUI_Show12ASCII(10,117,"The AD Volage is:",YELLOW,BLACK);
while(1)
{
value=0;
for(i=0;i<=10;i++)
{
value=25*i;
TIM_SetCompare1(TIM4, value);//设置 TIMx 捕获比较 1 寄存器值
delay_ms(1);
value1=TIM_GetCapture1(TIM4);
dat[0]=value1/100+0x30;
dat[1]=value1%100/10+0x30;
dat[2]=value1%100%10+0x30;
dat[3]='\0';
ADC_SoftwareStartConvCmd(ADC1, ENABLE); //使能或者失能指定的
ADC 的软件转换启动功能
while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));//转换结束标志位
value2=ADC_GetConversionValue(ADC1);
ad=value2*3.3/4096;
value2=ad*100;
dat1[0]=value2/100+0x30;
dat1[1]='.';
dat1[2]=value2%100/10+0x30;
dat1[3]=value2%100%10+0x30;
dat1[4]='V';
dat1[5]='\0';
GUI_Show12ASCII(160,100,dat,YELLOW,BLACK);
GUI_Show12ASCII(160,117,dat1,YELLOW,BLACK);
delay_ms(500);
if(j>1)
{
j=0;
GPIO_SetBits(GPIOC,GPIO_Pin_0);
}
else
{
j++;
GPIO_ResetBits(GPIOC,GPIO_Pin_0);
}
}
}
}
|