1、FATFs SD卡底层程序之图片显示硬件环境:DAXIA32 学习板 STM32F103VC 72MHz编程环境:MDK 3.80a主程序:/*/* 函数名称:MAIN/* 功 能:从 SD卡读 BMP图片并显示/* 编 写:Bunagi/* 修 改:2010/9/4/*int main(void) FATFS fs;DIR dir;FIL fil;FILINFO fno;FRESULT res;char Buf512;u8 i;char FilSearchCount1013; / 文件名检索存放ChipHalInit();ChipOutHalInit();Lcd_Init();TFT_X =
2、 0;TFT_Y = 0;BG_COLOR = WHITE;TFTFill(WHITE);SysTickDelay(1000);TFTShowString16(TFT_X,TFT_Y,“图片显示测试“,RED);while(!GET_DOWN();TFT_X = 0;TFT_Y = 0;TFTFill(BLACK);/*f_mount(0,if(!FilSearch(while(1);elsefor(i = 0;i wBFIType = (Buf0dwBFISize = (Buf5dwBFIReserved = 0x00;bfinfo-dwBFIStartAdd = (Buf13dwBISiz
3、e = (Buf17dwBIWidth = (Buf21dwBIHeight = (Buf25wBIPlanes = 0x01;binfo-wBIBitCount = (Buf29dwBICompression = (Buf33dwBISizeImage = (Buf37dwBIXPelsPerMeter = (Buf41dwBIYPelsPerMeter = (Buf45dwBIClrUsed = (Buf49dwBIClrImportant = (Buf53fname,FilSearch) break;else if(fno-fname0 = 0) return FALSE;res = f
4、_open(fil,fno-fname,FA_OPEN_EXISTING | FA_READ);if(res != FR_OK) return FALSE;res = f_read(fil,Buf,BMPBufSize,if(res != FR_OK) return FALSE;BMPInfoLoad(tft_start_x = tft_end_x - (u16)(binfo.dwBIWidth-1);tft_start_y = tft_end_y - (u16)(binfo.dwBIHeight-1);rgb = 0;count = bfinfo.dwBFIStartAdd; / 当前象素数
5、据地址指针 color_byte = binfo.wBIBitCount 3; / binfo.wBIBitCount / 8 判断是几位的位图dowhile(count 3;rgb+;break; case 1: / 绿色象素数据转换成R5G6B5格式color |= (Bufcount 2) 3) 11;rgb+;break; default: break;if(rgb = color_byte) / 象素转换完成TFTPoint(tft_x,tft_y,color);color = 0;rgb = 0;if(-tft_x tft_start_x)tft_x = tft_end_x;if(
6、-tft_y tft_start_y) return TRUE;/ 处理每行象素对齐if(binfo.dwBIWidth*3)%4) != 0) count +=4 - (binfo.dwBIWidth*3)%4); count +;else/ 添加处理其它比如 16位图的程序 / 读下一个扇区数据if(f_read(fil,Buf,BMPBufSize,count = 0; while(!res return TRUE; /*/* 函数名称:FilSearch/* 功 能:在指定路径下查找指定扩展名的文件,并记录在(*p)13数组中,注意最大记录条/* 勿溢出/* 输入参数:fs/* dir
7、/* path 要检索的文件路径/* name 要检索的文件扩展名/* (*p)13 检索结果存放地址 /* 输出参数:TRUE 成功 FALSE 出错/* 编 写:Bunagi/* 修 改:2010/9/4/* bool FilSearch(FATFS *fs,DIR *dir,XCHAR *path,u8 *name,char (*p)13)FILINFO fno;FRESULT res;u8 i,j,k;j = k = 0;res = f_opendir(dir,path);if(res != FR_OK) return FALSE;dores = f_readdir(dir,if(res != FR_OK) return FALSE;if(fno.fname0 = 0) return TRUE;i = 13;while(-i) if(fno.fnamei = 0x2E) if(i) /检索到一个符合扩展名条件的文件for(k =0;k 13;k+) *(*(p+j)+k) = fno.fnamek;j+; while(!res