阅读:1689回复:2
请教D12与单片机开发U盘的问题?请高手指点!
老东西了,已经很落伍了,不过还是没做出来,用的是PDIUSBD12,做FAT16文件系统,256M的FLASH ,这个FLASH一页有2048字节,
我直接用一页作为WINDOWS的一簇了.现在是优盘盘符已经能识别出来了,看属性也正确,打开U盘也能看到里面的文件,可是点 这个文件的属性,文件的字节数和占用空间都是0,再复制这个文件,粘贴到硬盘时会出错!图片如下: 图片:2010_8_6_12_27_28.jpg 图片:2010_8_6_12_27_41.jpg 图片:2010_8_6_12_27_51.jpg 图片:2010_8_6_12_28_01.jpg 图片:2010_8_6_12_30_27.jpg |
|
沙发#
发布于:2010-08-09 10:46
const uchar Fat16_MBR[512]={
0x33,0xc0,0x8e,0xc0,0x8e,0xd8,0x8e,0xd0,0xbc,0x00,0x7c,0xfc,0x8b,0xf4,0xbf,0x00,//00000000 0x06,0xb9,0x00,0x01,0xf2,0xa5,0xea,0x44,0x06,0x00,0x00,0x8b,0xd5,0x58,0xb4,0x10,//00000010 0xf6,0xe4,0x05,0xae,0x04,0x8b,0xf0,0x8a,0x74,0x01,0x8b,0x4c,0x02,0xbb,0x00,0x7c,//00000020 0xe8,0x01,0x02,0xcd,0x13,0x72,0x16,0x81,0xbf,0xfe,0x01,0x55,0xaa,0x75,0x0e,0xea,//00000030 0x00,0x7c,0x00,0x00,0x80,0xfa,0x81,0x74,0x02,0xb2,0x80,0x8b,0xea,0xbf,0xbe,0x07,//00000040 0xb9,0x04,0x00,0x32,0xf6,0x8a,0x45,0x04,0x3c,0x00,0x74,0x0b,0x3c,0x05,0x74,0x07,//00000050 0x80,0x3d,0x80,0x74,0x19,0xfe,0xc6,0x83,0xc7,0x10,0xe2,0xe9,0x0a,0xf6,0x74,0x06,//00000060 0xbe,0x9c,0x06,0xeb,0x04,0x90,0xbe,0xb4,0x06,0xe8,0x0e,0x00,0xeb,0xfe,0x8a,0xc6,//00000070 0x04,0x31,0x50,0xbe,0x99,0x06,0xbb,0x1b,0x06,0x53,0xfc,0xac,0x50,0x24,0x7f,0xb4,//00000080 0x0e,0xcd,0x10,0x58,0xa8,0x80,0x74,0xf2,0xc3,0x0d,0x0a,0xa0,0x0d,0x0a,0x4e,0x6f,//00000090 0x20,0x61,0x63,0x74,0x69,0x76,0x65,0x20,0x70,0x61,0x72,0x74,0x69,0x74,0x69,0x6f,//000000a0 0x6e,0x2e,0x2e,0xae,0x0d,0x0a,0x50,0x61,0x72,0x74,0x69,0x74,0x69,0x6f,0x6e,0x20,//000000b0 0x6e,0x6f,0x74,0x20,0x66,0x6f,0x75,0x6e,0x64,0x2e,0x2e,0xae,0x00,0x00,0x00,0x00,//000000c0 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//000000d0 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//000000e0 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//000000f0 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000100 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000110 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000120 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000130 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000140 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000150 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000160 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000170 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000180 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//00000190 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//000001a0 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,//000001b0 0x01,0x00,0x06,0xff,0xff,0xff,0x01,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,//000001c0 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//000001d0 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//000001e0 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0xaa //000001f0 }; const uchar Fat16_BPB[512]={ // 低位在前,高位在后 0xEB,0x03,0x90, //标志, 'M','S','W','I','N','4','.','1', //OEM名 0,8, //每扇区字节数2048 1, //每簇1扇区 1,0, //保留扇区数为1,从BPB到FAT表 的扇区数 2, //2个分区表 0x80,0, //根目录项数128*32=4096 0,0, //总扇区数20000H 0xf8, //存储介质标志 0x80,0, //每个分区表占30个扇区 0,0, //每道扇区数 0,0, //磁头数 1,0,0,0, //从MBR到BPB的扇区数1 2,0,0,0, //20000H个扇区 0, //软盘使用0 0, //保留 0x29, //扩展引导标记 '2','0','1','0', //卷的序列号 'w','i','n','l','i','o','n','.','.','.','.', //卷标 'F','A','T','1','6',0,0,0, //FAT标识 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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',0x20,'e','c','g',// 文件名 0x02, // 文件属性,存档加隐藏 0,0,0,0,0,0,0,0,0,0, // 保留字节 0,0, 0,0, // 更新时间 2,0, // 起始簇号 0x00,0x20,0x00,0x00}; // 文件大小200m DS1302_Read_Time(Time,7); // 获取时间 hour = Time[2]; // 获得小时 hour <<=11; // 小时*2048 min = Time[1]; // 获取分钟 min <<=5; // 分钟*32 dat = hour+min+Time[0]+2; // 计算更新时间 f[22] = dat; f[23] = (uchar)(dat>>8); // 保存时间 year = Time[6]+20; // 计算年yr-1980 year <<=9; // 年*512 mon = Time[4]; // 获取月份 mon <<=5; // 月份*32 dat = year+mon+Time[3]; // 计算更新时间 f[24] = dat; f[25] = (uchar)(dat>>8); // 保存时间 FLASH_Write(0,0,(uchar*)Fat16_MBR,512); // 创建MBR表 FLASH_Write(1,0,(uchar*)Fat16_BPB,512); // 创建BPB表 FLASH_Write( 2,0,d,10); // 创建FAT分区表1 FLASH_Write( 2,12,DataBuff[0],2038); for(i=1;i<128;i++) { FLASH_Write( 2+i,0, DataBuff[0],2048); } FLASH_Write(130,0,d,10); // 创建FAT分区表2 FLASH_Write(130,12,DataBuff[0],2038); for(i=1;i<128;i++) { FLASH_Write( 130+i,0, DataBuff[0],2048); } FLASH_Write(258,0,f,32); // 创建跟目录区 } |
|
板凳#
发布于:2010-08-09 10:49
以上是建立FAT16 文件系统的程序,现在是文件可以看到,但点文件的属性发现占用字节和文件大小都为0,复制它的时候提示"无法复制,找不到源文件",不知道是怎么回事?大家有遇到过类似的现象么???指点一下!
|
|