c--SD卡,读取,摘取出来浮点数,然后赋值

95 篇文章 5 订阅

在这里插入图片描述

	UART_Send_Str("Start to read data....\r\n"); //开始读取数据
		
		i=0;
		linelength=0;
		readflag=1;
		while(readflag==1)
		{
			len=znFAT_ReadData(&fileinfo,i,1,&readBuf);
			if(readBuf==0x0D)
			{
				linebufTemp[i]=readBuf;
				readflag=0;//跳出读取循环
				
				//判断是不是有X,Y,两者都有
				//不断查询数组,看里面是不是存在X和Y,
				for(i=0;i<linelength;i++)
				{
					if(linebufTemp[i]=='X')
					{
					  xreadflag=1;
						xnpos=i;
					}
					if(linebufTemp[i]=='Y')
					{
					 yreadflag=1;
						ynpos=i;
					}
				}
				
				if(xreadflag==1 && yreadflag==1)//存在X和Y,将X和Y的数据拿出来,将Y和0x0D的数据拿出来
				{
					//将数组中的xnpos+1,ynpos-1之间的元素,放入xstring中,用atof转成float类型 2345  ==5-2+1
					for(i=xnpos+1;i<ynpos;i++)
					{
					  xstring[j]=linebufTemp[i];
						j++;
					}
					 xstring[j]='\0';
					j=0;
					for(i=ynpos+1;i<linelength+1;i++)
					{
					  ystring[j]=linebufTemp[i];
						j++;
					}
					 ystring[j]='\0';
					j=0;
					UART_Send_Str("xstring and ystring is below:---"); //输出读到的数据内容
					UART_Send_Enter();
					UART_Send_Str(xstring); //输出读到的数据内容
					UART_Send_Enter();
					UART_Send_Str(ystring); //输出读到的数据内容
					UART_Send_Enter();
				  xnew=atof(xstring);
					if(xnew<0)
					{
					  	UART_Send_StrNum("Have read data xnew(Bytes):",xnew*(-1)*1000+100); //输出实际读到的数据量	
						UART_Send_Enter();
					}
					else if(xnew>0)
					{
						UART_Send_StrNum("Have read data xnew(Bytes):",xnew*1000+100); //输出实际读到的数据量	
						UART_Send_Enter();
					}
				}
				else 	if(xreadflag==1 && yreadflag==0)
				{
				
				}
				else 	if(xreadflag==0 && yreadflag==1)
				{
				
				}
				
			}
			else 
			{
				linelength=linelength+1;
				linebufTemp[i]=readBuf;//将读取的数据,放到数组里面,一行的数据进行存取;
				i++;
			}
		}
		
		UART_Send_Str("Data is below:\r\n");
		UART_Send_Str(linebufTemp); //输出读到的数据内容
		UART_Send_Enter();
		UART_Send_StrNum("Have read data linebufTemp(Bytes):",linelength); //输出实际读到的数据量	
		
		
//		
//		len=znFAT_ReadData(&fileinfo,0,20,buf); //从文件偏移量10位置开始读取20个字节
//		
//		
//		
//		buf[20]=0;
//		

//		
		znFAT_Close_File(&fileinfo); //关闭文件
	}
	else
	{
		UART_Send_StrNum("Fail to open file, Err Code:",res);
	}
	
	znFAT_Flush_FS(); //刷新文件系统
	  
	while(1);
	
	return 0;
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值