想请教各位 为什么LCD显示的三行都相同(都输出的是ADC的值)????
sprintf((char*)string,"%s%.3f","ADC Value:",temp); LCD_DisplayStringLine(Line6,string); //打印ADC转换的值
sprintf((char*)string1," %s%.3f","PA9:",100*(arr-PA9pwmout)/arr);
LCD_DisplayStringLine(Line7,string1); //打印PA9引脚输出的PWM波占空比
sprintf((char*)string2," %s %.3f","PA9:",720000000/arr);
LCD_DisplayStringLine(Line8,string2); //打印PWM波的频率
完整的main函数如下
int main(void)
{
float adcx;
u8 string[20]; u8 string1[20]; u8 string2[20];
float temp;
u16 arr=7199;//71999(1kHZ)~~7199(10kHZ) 频率可调PWM波
key_Init();
Adc_Init();
LED_Init();
TIM1_PWM_Init(arr,0);//PWM波频率为 72000000/arr
//LCD显示
STM3210B_LCD_Init();//LCD初始化函数
LCD_Clear(White);
LCD_SetTextColor(Green);
LCD_SetBackColor(Red);
LCD_ClearLine(Line0);
LCD_ClearLine(Line1);
LCD_ClearLine(Line2);
LCD_ClearLine(Line3);
LCD_ClearLine(Line4);
LCD_DisplayStringLine(Line1," ADC DEMO ");
LCD_DisplayStringLine(Line3," PB0-ADC channel 8 ");
LCD_SetTextColor(Black);
LCD_SetBackColor(White);
while(1)
{
u16 PA9pwmout;
PA9pwmout=arr-(adcx*arr)/0xfff; //占空比与ADC的关系
TIM_SetCompare2(TIM1,PA9pwmout); //改变CCR2的值,调节占空比
adcx=Get_Adc( ADC_Channel_8);
temp=adcx*(3.3/0xfff);
sprintf((char*)string,"%s%.3f","ADC Value:",temp);
LCD_DisplayStringLine(Line7,string);
sprintf((char*)string1," %s%.3f","PA9:",100*(arr-PA9pwmout)/arr);
LCD_DisplayStringLine(Line6,string1);
sprintf((char*)string2," %s %.3f","PA9:",720000000/arr);
LCD_DisplayStringLine(Line8,string2);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
sprintf((char*)string,"%s%.3f","ADC Value:",1.2);
LCD_DisplayStringLine(Line7,string);
sprintf((char*)string1," %s%.3f","PA9:",2.3);
LCD_DisplayStringLine(Line6,string1);
sprintf((char*)string2," %s %.3f","PA9:",4.5);
LCD_DisplayStringLine(Line8,string2);
看结果大慨就知道问题在哪儿了
一周热门 更多>