本帖最后由 kyzb001 于 2011-12-15 12:40 编辑
其实就是12864+M0+FATFS文件系统!
附上代码
没有12864的记得把 ST7588lcd_Init和DisplayDisk这个函数屏蔽! 串口一样可以打印消息的~!
void disk_read_file()
{
uint8_t Disk_Key=0 ;
uint8_t file_rank=0;
uint8_t temp;
strcpy(diskname,"");
obtain_folder();
DisplayDisk(0);
while(1)
{
Disk_Key=KeyVolat;
temp=file_rank;
switch(Disk_Key)
{
case KEY_NONE: break;
case KEY_UP :
{
if(file_rank++>=foldernum)
file_rank=foldernum;
while(Disk_Key==KEY_UP)
Disk_Key=KeyVolat;
} break;
case KEY_DOWN:
{
if(file_rank--<=0)
file_rank=0;
while(Disk_Key==KEY_DOWN)
Disk_Key=KeyVolat;
} break;
case KEY_MENU:
{
strcpy(diskname,disk[file_rank].foldername);
file_rank=0;
obtain_folder();
} break;
}
if(temp!=file_rank)
{
DisplayDisk(file_rank);
}
}
}
[code]
void obtain_folder()
{
FATFS FatFs; /* File system object for logical drive */
FRESULT res;
FILINFO finfo;
DIR dirs;
uint8_t i;
filenum=0;
foldernum=0;
for(i=0;i<20;i++)
{
memset(disk.foldername,0,20);
memset(disk.filename,0,20);
}
f_mount(0, &FatFs);
printf("--------------Open File:/%s-------------------------\n",diskname);
res=f_opendir(&dirs, diskname);
if ( res== FR_OK)
{
printf("--------------file name:%s--------------------------\n",diskname);
while ((f_readdir(&dirs, &finfo) == FR_OK) && finfo.fname[0])
{
if (finfo.fattrib & AM_DIR)//如果是文件夹
{
printf("%s/%s\n",diskname,&finfo.fname[0]);
strcpy(disk[foldernum++].foldername , &finfo.fname[0]);
}
if (finfo.fattrib & AM_ARC)//如果是文件
{
printf("%s/%s\n",diskname,&finfo.fname[0]);
strcpy(disk[filenum++].filename , &finfo.fname[0]);
}
}
}
// DisplayDisk(0);
f_mount(0, NULL);
}
[/code]
typedef struct
{
char filename[20];
char foldername[20];
}disk_t;
disk_t disk[20];
uint8_t filenum=0;
uint8_t foldernum=0;
char diskname[20];
void DisplayDisk(unsigned char x_line)
{
uint8_t i,j;
uint8_t filenumber;
filenumber=foldernum+filenum;
j=0;
CogLCDClr();
for(i=0;i<filenumber;i++)
{
if(i<foldernum)
DisPlay_12X12_Str((uint8_t *)disk.foldername ,5,i*12);
else if(i>=foldernum&&i<5)
DisPlay_12X12_Str((uint8_t *)disk[j++].filename ,5,i*12);
else
break;
}
DisPlay_Picture(0x00,0,3+(x_line*12),4,4);
CogLCDRedraw();
DrvSYS_Delay(8000);
}
|