本帖最后由 一杯茶2009 于 2016-7-21 21:03 编辑
采用的是FATFS 0.09,硬件STM32F103,虽然FLASH有512K,但是增加文件系统支持添加CC936.C后,占用空间还是相当恐怖的。
随后想着把CC936.C码表转移至外挂SPI FLASH SST25V016B中节省ROM空间。当然也需要改写转换函数。贴出来和大家分享一下。
#define CODE_UtoG_BASE (64*1024*14) //unicode转GBK基地址
#define CODE_GtoU_BASE (64*1024*16) //GBK转unicode基地址
#if !_USE_LFN || _CODE_PAGE != 936
#error This file is not needed in current configuration. Remove from the project.
#endif
WCHAR ff_convert ( /* Converted code, 0 means conversion error */
WCHAR src, /* Character code to be converted */
UINT dir /* 0: Unicode to OEMCP, 1: OEMCP to Unicode */
)
{
unsigned int p=0;
WCHAR c,temp;
int i, n, li, hi;
unsigned int oem2uni=87172,uni2oem=87172;//码表占用字节大小
unsigned char buff[2];
if (src < 0x80) { /* ASCII */
c = src;
} else {
if (dir) { /* OEMCP to unicode */
p = CODE_GtoU_BASE;
hi = oem2uni / 4 - 1;
} else { /* Unicode to OEMCP */
p = CODE_UtoG_BASE;
hi = uni2oem / 4 - 1;
}
li = 0;
for (n = 16; n; n--){ //2分法查表
i = li + (hi - li) / 2;
SST25V_BufferRead(p + i*4, buff, 2);
temp = (buff[0]<<8)+buff[1];
if (src == temp ) break;
if (src > temp)
li = i;
else
hi = i;
}
SST25V_BufferRead(p + (i*4+2), buff, 2);
temp = (buff[0]<<8)+buff[1];
c = n ? temp : 0;
}
return c;
}
一周热门 更多>