📄 character.c
字号:
/*
* $Id: character.c,v 1.2 2003/08/29 03:13:18 casic Exp $
*
* character.c : display characters on LCD
*
* Copyright (C) 2003 ynding ( haoanian@263.net )
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "color.h"
#include "graphic.h"
#include "character.h"
#include "hzk16x16.h"
#include "ascii.h"
/*
* display an ascii character
* x,y : coordinate of the start pixel
* ascii_codes : the the bytes serial to be displayed
* the size of the ascii characters is 8*16
* color : the color of the character
*/
void display_ascii(unsigned int x, unsigned int y, unsigned char* ascii_codes, COLOR color)
{
int i = 0;
/* total 16 bytes codes*/
for ( i=0;i<16;++i ) {
int j = 0;
x += 8;
for ( j=0;j<8;++j ) {
--x;
if ( ( ascii_codes[i] >> j ) & 0x1 ) {
draw_dot(x,y,color);
}
}
/* move to the next line : x axis unchanged, y axis increase 1 */
++y;
}
return;
}
/*
* display a Chinese character
* x,y : coordinate of the start pixel
* cnc_codes : the bytes serial to be displayed
* the size of the Chinese characters is 16*16
* color : the color of the character
*/
void display_cnc(unsigned int x, unsigned int y, unsigned char* cnc_codes, COLOR color)
{
int i;
/* total 2*16 bytes codes */
for(i=0;i<16;i++) {
int j = 0;
for (j=0;j<2;++j) {
int k = 0;
x += 8*(j+1);
for ( k=0;k<8;++k ){
--x;
if ( ( cnc_codes[2*i+j] >> k) & 0x1 ) {
draw_dot(x,y,color);
}
}
}
/* move to the next line : x axis unchanged, y axis increase 1 */
x -= 8;
++y;
}
return;
}
/*
* display a string,the string can contain
* not only ascii characters but also Chinese characters
*
* x,y : the beginning coordinate of the string to be displayed
* 0<=x<=39 : each line holds 40 bytes (each byte contain 8 pixels) horizontally
* 0<=y<=14 : each line holds 16 pixels vertically
*
* so the whole LCD can display 40*15 ascii characters,
* or 20*15 Chinese characters
*
* color : the color of the string
*/
void display_string(unsigned int x, unsigned int y, char* str, COLOR color)
{
unsigned char* ptr;
unsigned int ch;
unsigned int cl;
unsigned int offset;
while (*str){
ch = (unsigned int)str[0];
cl = (unsigned int)str[1];
if ( (ch>=0xa1)&&(ch<0xf8) && (cl>=0xa1)&&(cl<0xff) ) { /* Chinese characters */
/* if x reaches the end of a line,turn to the next line */
if ( x==39 || x==40 ){
x = 0;
y += 1;
}
/* calculate the offset of the character in the array */
offset = ( (ch-0xa1)*94+(cl-0xa1) )*32;
/* calculate the pointer of the character */
ptr = GB2312_16X16_FONT_BITMAP + offset;
/* display the character */
display_cnc(x*8, y*16, ptr, color);
/* x axis increase 2 */
x += 2;
/* move to the next character */
str += 2; /* a Chinese character holds 2 bytes */
}else{ /* ascii character */
/* if x reaches the end of a line,turn to the next line */
if ( x == 40 ) {
x = 0;
y += 1;
}
/* calculate the pointer of the character */
ptr = ASCII_FONT_BITMAP + 16*ch;
/* display the character */
display_ascii(x*8, y*16, ptr, color);
/* x axis increase 1 */
x += 1;
/* move to the next character */
str++; /* an ascii character holds 1 byte */
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -