第一种方法:直接输汉字或字母等 直接输出
在GB2312编码中对所收汉字进行了“分区”处理,94个区,每区含有94个汉字/符号
* 汉字由两个ASCII码组成,第一个减去160就是区码,第二个减去160就是位码
* 在C中处理时,如"啊"的代码是B0A0 +1,定义*pStr = "啊",则*pStr = 176(B0),*(pStr+1) = 161(A0+1)
* 第一个ASC 176 - 160(0xA0) = 16 ,第二个 ASC 161 - 160(0xA0) = 1,所以区位码为:1601
* 按GB2312表顺序,从第一行开始向右每取8个点作为一个字节,如果最后不足8个点就补满8位。
* 8位逐行取模,第一点为高位.16X16汉字一行就有两个字节 X 16行
* 因字模数字式从0开始,所以 起始位为 ( ( (*pStr - 0xA0) - 1 ) * 94 + ( *(pStr+1) - 0xA0 ) - 1 ) * 32
*/
/* 左侧字模起始地址 */
pZKL = &__CHS[ ( ( (*pStr - 0xA0) - 1 ) * 94 + ( *(pStr+1) - 0xA0 ) - 1 ) * 32];
/* 右侧字模起始地址 */
pZKR = &__CHS[ ( ( ( (*pStr - 0xA0) - 1 ) * 94 + ( *(pStr+1) - 0xA0 ) - 1 ) * 32 ) + 1];
/*******************************************************************************
* 函数名称: Lcd_Print_ZW
* 功能描述: 在LCD屏幕上指定坐标点写汉字 NETC-陈建长.
* 输入参数: (unsigned int x,unsigned int y坐标),(unsigned char *pStr 单个汉字 如 “啊”),
(unsigned int c,unsigned int bk_c颜色和区域颜色),unsigned int st 区域颜色选择
st = 1 有 st = 0 无,在动态变化的情况下,如果没有区域颜色则前后信息叠加.
* 输出参数: None
* 返回参数: None
*******************************************************************************/
void Lcd_Print_ZW(unsigned int x,unsigned int y,unsigned char *pStr,unsigned int c,unsigned int bk_c,unsigned int st)
{
unsigned short int i,j;
unsigned char *pZKL,*pZKR,mask,buf;
pZKL = &__CHS[ ( ( (*pStr - 0xA0) - 1 ) * 94 + ( *(pStr+1) - 0xA0 ) - 1 ) * 32];
pZKR = &__CHS[ ( ( ( (*pStr - 0xA0) - 1 ) * 94 + ( *(pStr+1) - 0xA0 ) - 1 ) * 32 ) + 1];
for( i = 0 ; i < 16 ; i++ )
{
/* 处理左侧显示 */
mask = 0x80;
buf = *pZKL;
*(pZKL += 2);
for( j = 0 ; j < 8 ; j++ )
{
if( buf & mask )
{
PutPixel(x+j,y+i,c);
}
else
{
if( st )
{
PutPixel(x+j,y+j,bk_c);
}
}
mask = mask >> 1;
}
/* 处理右侧显示 */
mask = 0x80;
buf = *pZKR;
*(pZKR += 2);
for( j = 0 ; j < 8 ; j++ )
{
if( buf & mask )
{
PutPixel(x+j + 8,y+i,c);
}
else
{
if( st )
{
PutPixel(x+j + 8,y+i,bk_c);
}
}
mask = mask >> 1;
}
}
}
eg : 输出:“啊”
Lcd_Print_ZW(100, 100, "啊", 0x0, 0x0, 0);
第二种方法:用字符取模软件生成字符数组,读取输出
代码如下:
- *************************************************
- file name LCD_hanzi
- function 显示16*16汉字 和 16*8 ASCII码字符
- 硬件设备 mini2440开发板
- 索尼X-35 3.5寸液晶屏
- lcd参数 宽和高 240x320
- TFT 16bpp显示
- 完成时间 2011-08-10
- 作者 周茂夫
- problem 暂无
- 修改记录 暂无
- *************************************************/
- #define GLOBAL_CLK 1
- #include <stdlib.h>
- #include <string.h>
- #include "def.h"
- #include "option.h"
- #include "2440addr.h"
- #include "2440lib.h"
- #include "2440slib.h"
- #include "mmu.h"
- #include "profile.h"
- #include "memtest.h"
- #include "zifu.h"
- #define baudrate 115200
- #define LCD_WIDTH 240
- #define LCD_HEIGHT 320
- //#define LCD_CLKCAL 17 //这个我计算出来是17参考程序给的是4 测试俩个都可以
- //影响不大 测试25 30 都还可以
- #define LCD_CLKCAL 17
- #define LCD_RIGHT_MARGIN 25
- #define LCD_LEFT_MARGIN 0
- #define LCD_HSYNC_LEN 4
- #define LCD_UPPER_MARGIN 0
- #define LCD_LOWER_MARGIN 4
- #define LCD_VSYNC_LEN 9
- #define LCD_XSIZE LCD_WIDTH
- #define LCD_YSIZE LCD_HEIGHT
- #define SCR_XSIZE LCD_WIDTH
- #define SCR_YSIZE LCD_HEIGHT
- extern const unsigned char sunflower_240x320[];
- extern const unsigned char GB2312Dot16X16[];
- volatile static unsigned short LCD_BUFFER[SCR_YSIZE][SCR_XSIZE];//LCD BUFFER
- #define M5D(n) ((n)&0x1fffff)//设置显示缓存区时取地址的低21位
- #define LCD_ADDR ((U32)(LCD_BUFFER))
- /********横向取模,字节不倒序,C51格式*******/
- unsigned char zhou[]=
- {
- 0x00,0x00,0x1F,0xFC,0x10,0x84,0x13,0xE4,0x10,0x84,0x10,0x84,0x17,0xF4,0x10,0x04,
- 0x13,0xE4,0x12,0x24,0x12,0x24,0x13,0xE4,0x22,0x24,0x20,0x04,0x40,0x14,0x80,0x08,
- } ;
- unsigned char mao[]=
- {
- 0x04,0x40,0x04,0x40,0xFF,0xFE,0x04,0x40,0x00,0xA0,0x00,0x90,0x3F,0xFE,0x20,0x80,
- 0x20,0x84,0x20,0x48,0x20,0x50,0x20,0x60,0x20,0xA0,0x43,0x12,0x4C,0x0A,0x80,0x04,
- } ;
- unsigned char Y[]=
- {
- 0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,
- } ;
- unsigned char zhao[]=
- {
- 0x00,0x00, 0xF7,0x7E, 0x95,0x04, 0x95,0x04,
- 0x96,0x74, 0x96,0x54, 0x95,0x54, 0x95,0x54,
- 0x95,0x54, 0xF5,0x54, 0x97,0x74, 0x04,0x04,
- 0x04,0x04, 0x04,0x04, 0x04,0x14, 0x04,0x08,
- } ;
- /**********************************
- void delay(int times)
- {
- int i = 1000;
- while(times--)
- {
- for(; i>0;--i)
- ;
- }
- }
- ************************************/
- /***********************************
- UART_int初始化led IO端口GPBCON5-8
- 初始化GPBHCON为串口通信
- 配置串口通信寄存器
- 配置中断寄存器
- ************************************/
- void UART_int_init(void)
- {
- /********configuration LED IO port**********/
- rGPBCON &=~(0xff<<10);
- rGPBCON |= 0x55<<10;
-
- /*******configuration GPHCON to UART*******/
- rGPHCON &=~(0xf<<4);
- rGPHCON |= 0xa