为什么显示是会多出100000??提问原子哥,也同问各位大佬,串口接收的数据液晶显示,有没有也遇到这样的问题??求解谢谢啦
显示部分代码[mw_shl_code=c,true]u8 RX_BUF[40];
int main(void)
{
u8 i;
u16 times=0;
long temp=0,temp1=0;
double temp2;
delay_init(); //延时函数初始化
LED_Init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
LCD_Init();
uart_init(9600);
POINT_COLOR=RED;
LCD_Clear(WHITE);
POINT_COLOR=RED;
while(1)
{
if(USART_RX_STA&0x8000)
{
if((USART_RX_BUF[0]==0x60)&&(USART_RX_BUF[9]==0x55))
{
for(i=1;i<9;i++)
{
RX_BUF[i-1]=USART_RX_BUF;
}
temp = RX_BUF[0]*10000000;
temp+= RX_BUF[1]*1000000;
temp+= RX_BUF[2]*100000;
temp+= RX_BUF[3]*10000;
temp+= RX_BUF[4]*1000;
temp+= RX_BUF[5]*100;
temp+= RX_BUF[6]*10;
temp+= RX_BUF[7]*1;
printf("\r\n%ld\r\n",temp);
for(i=10;i<20;i++)
{
RX_BUF[i-2]=USART_RX_BUF;
}
temp1 = RX_BUF[8]*100000000;
temp1 += RX_BUF[9]*10000000;
temp1 += RX_BUF[10]*1000000;
temp1 += RX_BUF[11]*100000;
temp1 += RX_BUF[12]*10000;
temp1 += RX_BUF[13]*1000;
temp1 += RX_BUF[14]*100;
temp1 += RX_BUF[15]*10;
temp1 += RX_BUF[16]*1;
printf("\r\n%ld\r\n",temp1);
temp2=(50000000.0*temp1)/(temp*1.0);
printf("\r\n%f\r\n",temp2);
LCD_ShowString(130,30,400,30,16," Frequency Indicator");
LCD_ShowString(0,120,210,30,16," TIME:");
LCD_ShowNum(90,120,temp1,16,16);
LCD_ShowString(400,120,400,30,16,"s");
LCD_ShowString(0,150,210,30,16,"Duty Cycle:");
LCD_ShowNum(90,150,temp,16,16);
LCD_ShowString(400,150,400,30,16,"%");
LCD_ShowString(0,90,210,30,16," Frequency:");
LCD_ShowxNum(90,90,temp2,16,16,0);
LCD_ShowString(400,90,400,30,16,"Hz");
// delay_ms(1000);
USART_RX_STA=0;
}
else
{
USART_RX_STA=0;
LCD_ShowString(130,30,400,30,16," Fthis is error!!!");
}
}
}[/mw_shl_code]
|