• 【GMT43智能液晶模块】例程十三:FATFS实验——文件操作


    实验原理:

      STM32F429上带有SDIO控制器,GMT43液晶模块上将SDIO连接到TF卡座。本实验

    将Micro SD卡插入TF卡座上即可。通过FATFS创建test.txt文件,并且写入数据0-255,然后

    读出并显示在液晶屏上。

    示例截图:

    源代码下载链接:

    链接:https://pan.baidu.com/s/1raoiNl6 密码:5w39

    GMT43购买链接:

    核心代码:

    int main(void)
    {
        FRESULT res;
    
        rcc.initialize();
        ads7843.initialize();
        SDRAM_Init();
        SDRAM_GPIOConfig();
        FMC_SDRAMWriteProtectionConfig(FMC_Bank2_SDRAM,DISABLE);
        lcd_tft.initialize();
        systick.initialize();
    
        GUI_Init();
        GUI_SetBkColor(GUI_BLACK);
        GUI_Clear();
    
        pwm.initialize(80);
        GUI_Delay(200);
        LCD_ON;
    
        if(SD_Init() != 0){
            GUI_SetColor(GUI_RED);
            GUI_SetFont(&GUI_FontFixedsys16);
            GUI_DispStringHCenterAt("SD Error!",480/2,272/2);
            while(1);
        }
    
        res = f_mount(&fatfs,"0:",1);
        if(res != RES_OK){
            GUI_SetColor(GUI_RED);
            GUI_SetFont(&GUI_FontFixedsys16);
            GUI_DispStringHCenterAt("f_mount Error!",480/2,272/2);        
            while(1);
        }    
        power_on.check_touch();
    
        frame.process();
    }
    static void frame_process(void)
    {
        FIL file;                                                                //文件对象
        int i,j;
        unsigned int counter;
    
        GUI_CURSOR_Show();
        WM_SetCreateFlags(WM_CF_MEMDEV);
        GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    
        sprintf(buffer,"Is to write and read
    ");
        MULTIEDIT_AddText(hItem,buffer);
        memset(buffer,0,sizeof(buffer));
        GUI_Exec();
    
        f_open(&file,"0:/test.txt",FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
        f_lseek(&file,0); 
        for(i = 0;i < 512;i++){
            write_buffer[i] = i % 256;
        }
        f_write(&file,write_buffer,512,&counter);                          //将缓冲器中的内容写入源文件    
        f_lseek(&file,0);                                                     //移动读指针到文件首
        f_read(&file,read_buffer,512,&counter);
        f_close(&file);  
    
        MULTIEDIT_SetText(hItem,buffer);                                   //上次显示的文本清空
    
        sprintf(buffer,"Complete
    ");
        MULTIEDIT_AddText(hItem,buffer);
        memset(buffer,0,sizeof(buffer));
    
        sprintf(buffer,"write data:
    ");
        MULTIEDIT_AddText(hItem,buffer);
        memset(buffer,0,sizeof(buffer));
    
        for(i = 0;i < 64;i++){
            for(j=0;j < 8;j++){
                sprintf(buffer," %02X",write_buffer[i*8+j]);    
                MULTIEDIT_AddText(hItem,buffer);
                memset(buffer,0,sizeof(buffer));
            }
            sprintf(buffer,"
    ");
            MULTIEDIT_AddText(hItem,buffer);
            memset(buffer,0,sizeof(buffer));
        }
    
        sprintf(buffer,"read data:
    ");
        MULTIEDIT_AddText(hItem,buffer);
        memset(buffer,0,sizeof(buffer));
    
        for(i = 0;i < 64;i++){
            for(j=0;j < 8;j++){
                sprintf(buffer," %02X",read_buffer[i*8+j]);    
                MULTIEDIT_AddText(hItem,buffer);
                memset(buffer,0,sizeof(buffer));
            }
            sprintf(buffer,"
    ");
            MULTIEDIT_AddText(hItem,buffer);
            memset(buffer,0,sizeof(buffer));
        }
    
        while(1){
            GUI_Exec();
        }
    }
  • 相关阅读:
    POJ_2513Colored Sticks 字典树+
    hdu1098:Ignatius's puzzle
    hdu1010:Tempter of the Bone 搜索+剪枝
    轻院1875: 蛤玮的财宝
    POJ3069:Saruman's Army
    轻院1874: 蛤玮学计网
    Educational Codeforces Round 18 E. Colored Balls
    浏览器f12的方法下载资源
    把手机上的新浪微博客户端卸载了
    Xmind使用总结
  • 原文地址:https://www.cnblogs.com/xiaomagee/p/8390549.html
Copyright © 2020-2023  润新知