📄 lcd_gbk.c
字号:
/*****************************************************/
/* File name : LCD_GBK.c */
/* Description : code for displaying a GBK characters, */
/* Platform : AVRStudio4.13 + WinAVR20070525 for AVR */
/* Author : Michael Zhang - 章其波 */
/* Email : sudazqb@163.com */
/* MSN : zhangqibo_1985@hotmail.com */
/* Date : 2007-1-2 */
/* NOT FOR COMMERCIAL USE, ALL RIGHT RESERVED! */
/*****************************************************/
/* Change Log: */
/* 20081002: for LPC2132 mp3 board. do not need modify */
/* 20071208: modify codes for ARM platform (AT91SAM7S256) */
/* 20071109: add a faster display function for 3310 */
/* 20070102: original version */
/*****************************************************/
#include"LCD_GBK.h"
uint32 GBK12,GBK16,GBK2UNI,UNI2GBK;//用于存放四个文件的起始扇区
extern uint32 FirstDataSector;//第一个数据扇区
extern uint16 SectorsPerClust;//每簇扇区数
extern uint16 BytesPerSector;//每扇区字节数
uint8 GBK_Buffer[32];//单个汉字点阵数据缓冲
uint8 GBK_Ini()//gbk初始化
{
GBK12 = FAT_Open("\\st12.sys");//打开文件,得到簇号
if(GBK12 == 1)return 1;
//GBK16 = FAT_Open("\\st16.sys");
//if(GBK16 == 1)return 1;
//GBK2UNI = FAT_Open("\\gbk2uni.sys");
//if(GBK2UNI == 1)return 1;
UNI2GBK = FAT_Open("\\uni2gbk.sys");
if(UNI2GBK == 1)return 1;
//将簇号转成扇区号
GBK12 = (uint32)FirstDataSector+(uint32)(GBK12 - 2)*(uint32)SectorsPerClust;//calculate the actual sector number
GBK16 = (uint32)FirstDataSector+(uint32)(GBK16 - 2)*(uint32)SectorsPerClust;//calculate the actual sector number
GBK2UNI = (uint32)FirstDataSector+(uint32)(GBK2UNI - 2)*(uint32)SectorsPerClust;//calculate the actual sector number
UNI2GBK = (uint32)FirstDataSector+(uint32)(UNI2GBK - 2)*(uint32)SectorsPerClust;//calculate the actual sector number
return 0;
}
extern uint16 fatGetWord(uint8 * addr);
uint8 Unicode_to_GBK(uint8 *ch)
{
uint16 temp;
uint16 sector_offset;//扇区偏移
uint16 byte_offset;//字节偏移
uint8 buffer[512];
temp = get16_little(ch);//由于FAT中文件民unicode码是 地字节在前,所以要按uint型读
temp -= 0x4e00;//减去基础数据
temp *= 2;//每个汉字两个字节
sector_offset = temp/BytesPerSector;//计算出扇区偏移,确定存在哪个扇区
byte_offset = temp%BytesPerSector;//存在哪个字节
if(FAT_ReadSector(UNI2GBK + sector_offset,buffer))return 1;//读那个扇区
*ch = buffer[byte_offset];//将数据读出
*(ch+1) = buffer[byte_offset+1];
return 0;
}
uint8 GBK_to_Unicode(uint8 *ch)
{
return 0;
}
uint8 Read_One_GBK12(uint8 *ch)
{
uint32 temp1;
uint8 temp2;
uint16 sector_offset;
uint16 byte_offset;
uint8 buffer[512];
temp1=*ch;
temp2=*(ch+1);
if(temp1<0x81||temp2<0x40)return 1;
temp1-=0x81;
temp2-=0x40;
temp1*=192;//xx7f and xxff are included
temp1+=temp2;
temp1*=24;
sector_offset = temp1/BytesPerSector;
byte_offset = temp1%BytesPerSector;
if(FAT_ReadSector(GBK12 + sector_offset,buffer))return 1;
if(byte_offset>488)
{
for(temp2 = 0,temp1 = byte_offset;temp2<(BytesPerSector - byte_offset);temp2++,temp1++)GBK_Buffer[temp2] = buffer[temp1];
if(FAT_ReadSector(GBK12 + sector_offset + 1,buffer))return 1;
for(temp1 = 0;temp2<24;temp2++,temp1++)GBK_Buffer[temp2] = buffer[temp1];
}
else for(temp2 = 0,temp1 = byte_offset;temp2<24;temp2++,temp1++)GBK_Buffer[temp2] = buffer[temp1];
return 0;
}
uint8 Read_One_GBK16(uint8 *ch)
{
uint16 temp1;
uint8 temp2;
uint16 sector_offset;//扇区偏移
uint16 byte_offset;//字节偏移
uint8 buffer[512];
temp1=*ch;
temp2=*(ch+1);
if(temp1<0x81||temp2<0x40)return 1;//不合法的汉字
temp1-=0x81;//的到类似于2312的区号
temp2-=0x40;//位号
temp1*=192;//xx7f and xxff are included
temp1+=temp2;//得到偏移
//temp1*=24;
sector_offset = temp1/(BytesPerSector/32);//算出要读哪个扇区
byte_offset = (temp1%(BytesPerSector/32))*32;//算出要读扇区的哪个字节
if(FAT_ReadSector(GBK16 + sector_offset,buffer))return 1;//读要读的扇区
for(temp2 = 0,temp1 = byte_offset;temp2<32;temp2++,temp1++)GBK_Buffer[temp2] = buffer[temp1];//复制要复制的数据
return 0;
}
uint8 Dis_GBK12_fast(uint16 x,uint16 y,uint8 *ch)
{
uint16 i,j;
uint8 temp;
extern uint8 disBuf[504];
// disBuf[(y/8)*84 + x +i] = temp;
j = y/12;
if(Read_One_GBK12(ch))return 1;
if(j==0)
{
for(i=x;i<x+12;i++)
{
temp = GBK_Buffer[i-x];
disBuf[i] = temp;
}
for(i=x+84;i<x+84+12;i++)
{
temp = GBK_Buffer[i-x-84+12];
disBuf[i] &= 0xf0;
disBuf[i] |= (temp & 0x0f);
}
}
else if(j==1)
{
for(i=x+84;i<x+84+12;i++)
{
temp = GBK_Buffer[i-x-84];
disBuf[i] &= 0x0f;
disBuf[i] |= ((temp<<4) & 0xf0);
}
for(i=x+168;i<x+168+12;i++)
{
temp = GBK_Buffer[i-x-168]>>4;
temp += GBK_Buffer[i-x+12-168]<<4;
disBuf[i] = temp;
}
}
else if(j==2)
{
for(i=x+252;i<x+12+252;i++)
{
temp = GBK_Buffer[i-x-252];
disBuf[i] = temp;
}
for(i=x+336;i<x+336+12;i++)
{
temp = GBK_Buffer[i-x+12-336];
disBuf[i] &= 0xf0;
disBuf[i] |= (temp & 0x0f);
}
}
else if(j==3)
{
for(i=x+336;i<x+336+12;i++)
{
temp = GBK_Buffer[i-x-336];
disBuf[i] &= 0x0f;
disBuf[i] |= ((temp<<4) & 0xf0);
}
for(i=x+420;i<x+420+12;i++)
{
temp = GBK_Buffer[i-x-420]>>4;
temp += GBK_Buffer[i-x+12-420]<<4;
disBuf[i] = temp;
}
}
return 0;
}
uint8 Dis_GBK12(uint16 x,uint16 y,uint8 *ch)
{
uint8 i,j;
uint8 temp;
if(Read_One_GBK12(ch))return 1;
for(i=0;i<12;i++)
{
temp = GBK_Buffer[i];
for(j=0;j<8;j++)
{
if(temp&(1<<j))OnePixel(x+i,y+j,1);
else OnePixel(x+i,y+j,0);
}
}
for(i=0;i<12;i++)
{
temp = GBK_Buffer[i + 12];
for(j=0;j<4;j++)
{
if(temp&(1<<j))OnePixel(x+i,y+j+8,1);
else OnePixel(x+i,y+j+8,0);
}
}
return 0;
}
uint8 Dis_GBK16(uint16 x,uint16 y,uint8 *ch)
{
uint8 i,j;
uint8 temp;
if(Read_One_GBK16(ch))return 1;
for(i=0;i<16;i++)
{
temp = GBK_Buffer[i];
for(j=0;j<8;j++)
{
if(temp&(1<<j))OnePixel(x+i,y+j,1);
else OnePixel(x+i,y+j,0);
}
}
for(i=0;i<16;i++)
{
temp = GBK_Buffer[i + 16];
for(j=0;j<8;j++)
{
if(temp&(1<<j))OnePixel(x+i,y+j+8,1);
else OnePixel(x+i,y+j+8,0);
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -