- GPIO_Configuration();
- znFAT_Device_Init(); // 存储设备初始化
- ILI9325_DisplayString_At(10,20,"SD OK ",Yellow,Red);
- znFAT_Select_Device(0,&Init_Args); //选择设备
- res=znFAT_Init(); // 文件系统初始化
- ILI9325_DisplayString_At(10,40,"FAT OK ",Yellow,Red);
- if(!res) // 文件系统初始化成功
- {
- ILI9325_DisplayString_At(10,60,"Suc. to init FS ",Yellow,Red);
- ILI9325_DisplayString_At(10,80,"BPB_Sector_No:",Yellow,Red);
- u32tostr(Init_Args.BPB_Sector_No, &buf[0]);
- ILI9325_DisplayString_At(10,100,&buf[0],Yellow,Red);
- ILI9325_DisplayString_At(10,120,"Total_SizeKB:",Yellow,Red);
- u32tostr(Init_Args.Total_SizeKB, &buf[0]);
- ILI9325_DisplayString_At(10,140,&buf[0],Yellow,Red);
- ILI9325_DisplayString_At(10,160,"BytesPerSector:",Yellow,Red);
- u32tostr(Init_Args.BytesPerSector, &buf[0]);
- ILI9325_DisplayString_At(10,180,&buf[0],Yellow,Red);
- ILI9325_DisplayString_At(10,200,"FATsectors:",Yellow,Red);
- u32tostr(Init_Args.FATsectors, &buf[0]);
- ILI9325_DisplayString_At(10,220,&buf[0],Yellow,Red);
- ILI9325_DisplayString_At(10,240,"SectorsPerClust:",Yellow,Red);
- u32tostr(Init_Args.SectorsPerClust, &buf[0]);
- ILI9325_DisplayString_At(10,260,&buf[0],Yellow,Red);
- ILI9325_DisplayString_At(10,280,"FirstFATSector:",Yellow,Red);
- u32tostr(Init_Args.FirstFATSector, &buf[0]);
- ILI9325_DisplayString_At(10,300,&buf[0],Yellow,Red);
- }
- else // 文件系统初始化失败
- {
- ILI9325_DisplayString_At(10,80,"Fail to init FS, Err Code ",Yellow,Red);
- }
运行程序后,其执行效果如图所示。
3)显示图片显示
经过前面的准备,离实现数码相框的目标就十分接近了。要实现数码相框功能,必须能
读取文件、识别图像文件头信息、读取数据并实现色彩格式的转换等。
在目前的图片显示中,最常用到的
24位色和16位色,由于TFT显示屏的色彩表现力只能达到16位,因此需要将24位色变为16位色来显示。即使是16位色,在存储时由于是按BGR顺序,故在显示时需转为RGB顺序,其转换方法如下:
- if(len==24)
- {
- // 读取3字节数据合成RGB色彩值,24位色
- dat=((buf[3*i+2]>>3)<<11)|((buf[3*i+1]>>2)<<5)|(buf[3*i]>>3);
- ILI9325WriteReg(0x22,dat); }
- else
- { // 读取2字节数据转为RGB顺序,16位色
- dat=((buf[i*2+1]<<8) | (buf[i*2]));
- ILI9325_WriteReg(0x22,(dat&0x7c00<<1)|(dat&0x03e0)<<1|(dat&0x001f));
- }
实践说明znFAT是个不错的文件系统,通过移植可方便地在Nucleo-F411RE开发板上实现数码相框功能,其效果如图所示。