📄 gra.c
字号:
/*******************************************************************/
/*文件名:GRA.c */
/*功能: 基础图形库 */
/*作者: 张驿风 */
/*时间: 20060112 */
/*******************************************************************/
//20060203 Ver0.01 支持ASCII字符,汉字显示
#include "ks0108.h"
#include "board.h"
#include "KS0108.h"
#include <iom8v.h>
#include "init.h"
#include "serial.h"
#include <macros.h>
#include "printzk.h"
#include "math.h"
#include "gra.h"
struct BRUSH Brush;
struct PEN Pen;
void outdot(u8 x, u8 y,u8 character){
u8 i,j,k,uData,uDot;
#if DEBUG_DOT
printf("Write character:\r\n");
sendhexstr8(character);
printf(",Adjust write character:\r\n");
sendhexstr8(uTemp);
printf("\r\n");
#endif
for(i=0;i<16;i++){
uData = ZK[character][i];
#if DEBUG_DOT
printf("Line ");
sendhexstr8(i);
printf(" Data = ");
sendhexstr8(uData);
printf("\r\n");
#endif
for(j=0,k=7;j<8;j++,k-=1){
uDot = uData >> k;
uDot = uDot & 0x01;
pixel(i+x,j+y,uDot);
//DelayMs(100);
}
}
}
/*******************************************************************/
/*名称:outchar */
/*功能:写一个字符到KS0108C */
/* :我采用8x16的ASCII编码方式以兼容我的微型打印以及能够借用我的 */
/* :PickZk.exe字库提取程序(UCDOS字库) */
/*参数: */
/* :x横坐标,y纵坐标,character写入字符 */
/*******************************************************************/
void outchar(u8 x, u8 y,u8 character){
outdot(x,y,character - 0x20); //这里-0x20是由于使用的不是全字库
}
/*******************************************************************/
/*名称:outtext */
/*功能:写一串字符到KS0108C */
/* :一行能够写16个ASCII字符,共能够写4行,依赖outchar的实现 */
/*参数: */
/* :x横坐标,y纵坐标,*p写入数据缓冲区地址 */
/*******************************************************************/
void outtext(u8 x, u8 y,u8 *p){
u8 j;
j = 0;
while(*p){
outchar(x,j+y,*(p++));
j += 8;
if(j>=128) break;
}
}
/*******************************************************************/
/*名称:outhz */
/*功能:写一个汉字到KS0108C */
/* :一行能够写8个汉字(16x16字库提取请使用PickZk,在hm30投币秤代码*/
/* :备份目录 hm-30-sour-TWO-a\LTP1524_C下能够找到该程序), */
/* :共能够写4行,依赖outchar的实现 */
/*参数: */
/* :x横坐标,y纵坐标,hz我将汉字分左右各8x16点阵的字库显示时显示*/
/* :时同时将两部分显示在相邻的2个ASCII字符位置上方便英汉混排。 */
/*******************************************************************/
void outhz(u8 x, u8 y,u8 hz){
outdot(x,y,hz);
outdot(x,y + 8,hz + 1);
}
void outtexthz(u8 x,u8 y,u8 const *p){
u8 j;
j = 0;
while(*p){
#if DEBUG_OUTTEXT_HZ
printf("write data = ");
sendhexstr8(*p);
#endif
outhz(x,y+j,*(p++));
j += 16;
if(j>128) break;
}
}
#if USE_DRAW_SIN
void DrawSin(void){
float i;
u16 x,y;
#define M_PI 3.14
#define Y_MULTIPLE 5
#define X_MULTIPLE 30
for(i=0;i<8*M_PI;i+=0.01){
y = i * Y_MULTIPLE;
x = sin(i) * X_MULTIPLE + 32;
pixel(x,y,1);
}
}
#endif
#if MOVE_TO
//------------------------------------------------
void MoveTo(u16 x,u16 y){
Pen.X = x;
Pen.Y = y;
}
#endif
#if LINE_TO
//------------------------------------------------
//画线函数
//Pen.x,Pen.y 起点坐标
//x,y终点坐标
//设计目的为简单实用,没有加入过多的控制所以要求
//使用该函数时要千万小心,有一个原则是x,y的值一定
//要大于Pen.x,Pen.y
//------------------------------------------------
u8 LineTo(u16 x,u16 y){
u16 i;
u16 TempX,TempY,Temp;
if((x<Pen.X)||(y<Pen.Y))
return false;
TempX = x-Pen.X;
TempY = y-Pen.Y;
if(TempY == 0){ //如果是一条水平直线
for(i=Pen.X;i<=x;i++){
pixel(Pen.X,i,Pen.Color);
}
}
if(TempX==0){ //如果是一条垂直线
for(i=0;i<=TempY;i++){
pixel(i,Pen.Y,Pen.Color);
}
}
if((TempX!=0)&(TempY!=0)){ //是一条斜线,循环TempY次画完,每次 X 加 Temp
}
return true;
}
#endif
#if RECTANGLE
//=================================================//
// rectangle() //
// FUNCTION:draw a rectangle use spcial left,top,
// width,height.
// IN:
// left :the rectangle x'start.
// top :the rectangle y'start.
// width :the rectangle width
// height :the rectangle height
// OUT:
// if draw successful return 0 else return -1
//=================================================//
u8 rectangle(u16 left,u16 top,u16 width,u16 height){
u16 i,j;
if(Brush.Mode==0){ //不填充
MoveTo(left,top);
LineTo(left+width,top);
LineTo(left,top+height);
MoveTo(left+width,top);
LineTo(left+width,top+height);
MoveTo(left,top+height);
LineTo(left+width,top+height);
}
if(Brush.Mode==1){ //实心填充
j = left;
for(i=top;i<=top+height;i++){
for(j=0;j<width;j++){
pixel(i,j,Pen.Color);
}
}
}
return true;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -