本帖最后由 C919WAY 于 2019-6-6 11:44 编辑
代码如下,但是我每次换行存储的时候就存成了这样,第二行总是右移一些,不知道是为什么?
#include <string.h>
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "key.h"
#include "usmart.h"
#include "malloc.h"
#include "MMC_SD.h"
#include "ff.h"
#include "exfuns.h"
#include "fattester.h"
FIL fil;
FRESULT res;
UINT bww;
int main(void)
{
//FILE *fp;
u16 TDS;
float PH;
u8 soilhum;
u16 light;
u8 temp;
u8 airhum;
u16 TDS1;
float PH1;
u8 soilhum1;
u16 light1;
u8 temp1;
u8 airhum1;
char bufchar[100];
u32 total,free;
u8 t=0;
u8 i;
TDS=1300;
PH=6.5;
soilhum=30;
light=3000;
temp=18;
airhum=40;
TDS1=1400;
PH1=6.8;
soilhum1=20;
light1=2000;
temp1=19;
airhum1=45;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// éèÖÃÖD¶ÏóÅÏ輶·Ö×é2
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
uart_init(9600); //′®¿ú3õê¼»ˉÎa9600
exfuns_init(); //ÎafatfsÏà1رäá¿éêÇëÄú′æ
LCD_Init(); //3õê¼»ˉòo¾§
LED_Init(); //LED3õê¼»ˉ
//usmart_dev.init(72);
mem_init(); //3õê¼»ˉÄú′æ3Ø
POINT_COLOR=RED;//éèÖÃ×ÖìåÎaoìé«
LCD_ShowString(60,50,200,16,16,"Mini STM32");
LCD_ShowString(60,70,200,16,16,"FATFS TEST");
LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(60,110,200,16,16,"Use USMART for test");
LCD_ShowString(60,130,200,16,16,"2014/3/14");
while(SD_Initialize()) //¼ì2aSD¿¨
{
LCD_ShowString(60,150,200,16,16,"SD Card Error!");
delay_ms(200);
LCD_Fill(60,150,240,150+16,WHITE);//Çå3yÏÔê¾
delay_ms(200);
LED0=!LED0;//DS0éá˸
}
exfuns_init(); //ÎafatfsÏà1رäá¿éêÇëÄú′æ
f_mount(fs[0],"0:",1); //1òÔØSD¿¨
//f_mount(fs[1],"1:",1); //1òÔØFLASH.
while(exf_getfree("0",&total,&free)) //μÃμ½SD¿¨μÄ×üèYá¿oíê£óàèYá¿
{
LCD_ShowString(60,150,200,16,16,"Fatfs Error!");
delay_ms(200);
LCD_Fill(60,150,240,150+16,WHITE);//Çå3yÏÔê¾
delay_ms(200);
LED0=!LED0;//DS0éá˸
}
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
LCD_ShowString(60,150,200,16,16,"FATFS OK!");
LCD_ShowString(60,170,200,16,16,"SD Total Size: MB");
LCD_ShowString(60,190,200,16,16,"SD Free Size: MB");
LCD_ShowNum(172,170,total>>10,5,16); //ÏÔê¾SD¿¨×üèYá¿ MB
LCD_ShowNum(172,190,free>>10,5,16); //ÏÔê¾SD¿¨ê£óàèYá¿ MB
mf_mount(0,1);//×¢2á
f_open(&fil,"0:/1.txt", FA_OPEN_ALWAYS|FA_WRITE);
sprintf((char*)bufchar,"TDS:%d,PH:%.1f,soilhum:%d%%,light:%d,temp:%d,airhum:%d%%
",TDS,PH,soilhum,light,temp,airhum);
f_lseek (&fil,f_size (&fil));
f_write (&fil,bufchar,sizeof(bufchar),&bww);
f_close (&fil);
memset(bufchar,0,100);
delay_ms(500);
f_open(&fil,"0:/1.txt", FA_WRITE);
sprintf((char*)bufchar,"TDS:%d PH:%.1f soilhum:%d%% light:%d temp:%d airhum:%d%%
",TDS1,PH1,soilhum1,light1,temp1,airhum1);
f_lseek(&fil,f_size(&fil));
f_write(&fil,bufchar,sizeof(bufchar),&bww);
f_close(&fil);
memset(bufchar,0,100);
while(1)
{
t++;
delay_ms(200);
LED0=!LED0;
}
}
这是TXT文件显示的结果
TDS:1300,PH:6.5,soilhum:30%,light:3000,temp:18,airhum:40%
̛ TDS:1400 PH:6.8 soilhum:20% light:2000 temp:19 airhum:45%
附件中我也附加了代码,请高手帮忙看看
一周热门 更多>