📄 ks0108.c
字号:
ch_w=ASC_16[k].Msk[j];
ch_w=ch_w<<4;
ch_w|=ch_r;
SetPageCol(uPage,uCol+j);
if(uCol+j<64) write_LCD(LEFT,DATA,ch_w);
else write_LCD(RIGHT,DATA,ch_w);
}
SetPageCol(uPage+1,uCol);
for(j=0;j<width;j++)
{
SetPageCol(uPage+1,uCol+j);
ch_r=ASC_16[k].Msk[j];
ch_w=ASC_16[k].Msk[ASC_CHR_WIDTH+j];
ch_r=ch_r>>4;
ch_w=ch_w<<4;
ch_w|=ch_r;
SetPageCol(uPage+1,uCol+j);
if(uCol+j<64) write_LCD(LEFT,DATA,ch_w);
else write_LCD(RIGHT,DATA,ch_w);
}
}
}
SetPageCol(uPage,uCol+width);
}
void disp_hz(unsigned char *hz)
{
unsigned char k,j,uPage,uCol,ch_r,ch_w;
uPage = GetPage();
uCol = GetCol();
for(k=0;k<sizeof(GB_16)/sizeof(GB_16[0]);k++)
{
if(hz[0] == GB_16[k].Index[0] && hz[1] == GB_16[k].Index[1])
break;
}
if(CurOffset==1)
{
for(j=0;j<ASC_HZ_WIDTH;j++)
{
SetPageCol(uPage,uCol+j);
ch_w=GB_16[k].Msk[j];
if(uCol+j<64) write_LCD(LEFT,DATA,ch_w);
else write_LCD(RIGHT,DATA,ch_w);
}
SetPageCol(uPage+1,uCol);
for(j=0;j<ASC_HZ_WIDTH;j++)
{
SetPageCol(uPage+1,uCol+j);
if(uCol+j<64) ch_r=read_LCD(LEFT);
else ch_r=read_LCD(RIGHT);
ch_r&=0xf0;
ch_w=GB_16[k].Msk[ASC_HZ_WIDTH+j]&0x0f;
ch_w|=ch_r;
SetPageCol(uPage+1,uCol+j);
if(uCol+j<64) write_LCD(LEFT,DATA,ch_w);
else write_LCD(RIGHT,DATA,ch_w);
}
SetPageCol(uPage,uCol+ASC_HZ_WIDTH);
}
else //汉字上半部是写半个字节
{
for(j=0;j<ASC_HZ_WIDTH;j++)
{
SetPageCol(uPage,uCol+j);
if(uCol+j<64) ch_r=read_LCD(LEFT);
else ch_r=read_LCD(RIGHT);
ch_r&=0x0f;
ch_w=GB_16[k].Msk[j];
ch_w=ch_w<<4;
ch_w|=ch_r;
SetPageCol(uPage,uCol+j);
if(uCol+j<64) write_LCD(LEFT,DATA,ch_w);
else write_LCD(RIGHT,DATA,ch_w);
}
SetPageCol(uPage+1,uCol);
for(j=0;j<ASC_HZ_WIDTH;j++)
{
SetPageCol(uPage+1,uCol+j);
ch_r=GB_16[k].Msk[j];
ch_w=GB_16[k].Msk[ASC_HZ_WIDTH+j];
ch_r=ch_r>>4;
ch_w=ch_w<<4;
ch_w|=ch_r;
SetPageCol(uPage+1,uCol+j);
if(uCol+j<64) write_LCD(LEFT,DATA,ch_w);
else write_LCD(RIGHT,DATA,ch_w);
}
SetPageCol(uPage,uCol+ASC_HZ_WIDTH);
}
}
void disp_str(unsigned char *p)
{
unsigned char i=0;
while(p[i]>0)
{
if(p[i] < 128)
{ /* ASCII */
disp_ch(p[i]);
}
else
{ /* 中文 */
disp_hz(&p[i]);
i++;
}
i++;
}
}
/*************************************/
/* 绘点函数 */
/*************************************/
/* XX--(0-128) YY--(0-63) FLAG=1绘点 FLAG=0 清点 */
void pixel(unsigned char xx,unsigned char yy,unsigned char flag)
{
unsigned int y,ch;
ch=yy%8; //余数
y=1;
for(;ch!=0;)
{
y=y*2;
ch--;
}
if(xx<64)
{
set_page_L(yy/8);
set_col_addr_L(xx);
ch=read_LCD(LEFT);
set_col_addr_L(xx);
if(flag)
write_LCD(LEFT,DATA,ch|y);
else
{
y=~y;
ch&=y;
write_LCD(LEFT,DATA,ch|y);
}
}
else
{
set_page_R(yy/8);
set_col_addr_R(xx-64);
ch=read_LCD(RIGHT);
set_col_addr_R(xx-64);
if(flag)
write_LCD(RIGHT,DATA,ch|y);
else
{
y=~y;
ch&=y;
write_LCD(RIGHT,DATA,ch|y);
}
}
}
/*void point(void)
{
uchar x1, y1, y;
x1 = CurCol;
y1 = CurRow;
CurRow = y1 >> 3; //取Y方向分页地址
Rddata(); // get cbyte on screen
y = y1 & 0x07; //字节内位置计算
Wrdata(cbyte | (1 << y)); //画上屏幕 /
CurCol = x1; ///恢复xy坐标 /
CurRow = y1;
} */
/************************************************/
/*画圆。数学方程(X-Ox)^2+(Y-Oy)^2=Rx^2 */
/************************************************/
/*void circle(uchar Ox, uchar Oy, uchar Rx)
{
unsigned int xx, rr, xt, yt, rs;
yt = Rx;
rr = Rx * Rx + 1; //补偿 1 修正方形
rs = (yt + (yt >> 1)) >> 1; //(*0.75)分开1/8圆弧来画
for (xt = 0; xt <= rs; xt++)
{
xx = xt * xt;
while ((yt * yt) > (rr - xx))
yt--;
col = Ox + xt; //第一象限
row=Oy-yt;
point();
col = Ox - xt; //第二象限
point();
row = Oy + yt; //第三象限
point();
col = Ox + xt; //第四象限
point();
// ***************45度镜象画另一半***************
col = Ox + yt; //第一象限
row = Oy - xt;
point();
col = Ox - yt; //第二象限
point();
row = Oy + xt; //第三象限
point();
col = Ox + yt; //第四象限
point();
}
}
*/
/************************************************/
/*画线。任意方向的斜线,直线数学方程 aX+bY=1 */
/************************************************/
/*void Linexy(uchar x0,uchar y0,uchar xt,uchar yt)
{
uchar t;
int xerr = 0, yerr = 0, delta_x, delta_y, distance;
int incx, incy;
delta_x = xt - x0; // 计算坐标增量
delta_y = yt - y0;
col = x0;
row = y0;
if (delta_x > 0)
{
incx = 1; // 水平+方向
}
else if (delta_x == 0 )
{
incx = 0; // 垂直线
}
else
{
incx =- 1; //水平负方向
delta_x =- delta_x;
}
if (delta_y > 0)
{
incy = 1; // 垂直+方向
}
else
if (delta_y == 0)
{
incy = 0; // 水平线
}
else
{
incy =- 1; //垂直-方向
delta_y =- delta_y;
}
if (delta_x > delta_y)
distance = delta_x; //选取基本增量坐标轴
else
distance = delta_y;
for (t = 0; t <= distance + 1; t++)
{ // 画线输出
point(); // 画点
xerr += delta_x;
yerr += delta_y;
if (xerr > distance)
{
xerr -= distance;
col += incx;
}
if (yerr > distance)
{
yerr -= distance;
row += incy;
}
}
}
*/
void Linexy(uchar x0,uchar y0,uchar xt,uchar yt,uchar s)
{
register uchar t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x = xt-x0; //计算坐标增量
delta_y = yt-y0;
uRow = x0;
uCol = y0;
if(delta_x>0) incx=1; //设置单步方向
else if( delta_x==0 ) incx=0; //垂直线
else {incx=-1;delta_x=-delta_x;}
if(delta_y>0) incy=1;
else if( delta_y==0 ) incy=0; //水平线
else {incy=-1;delta_y=-delta_y;}
if( delta_x > delta_y ) distance=delta_x; //选取基本增量坐标轴
else distance=delta_y;
for( t=0;t <= distance+1; t++ )
{ //画线输出
pixel(uRow,uCol,s); //画点
xerr += delta_x ;
yerr += delta_y ;
if( xerr > distance )
{
xerr-=distance;
uRow+=incx;
}
if( yerr > distance )
{
yerr-=distance;
uCol+=incy;
}
}
}
/************************************************/
/*画圆。数学方程(X-Ox)^2+(Y-Oy)^2=Rx^2 */
/************************************************/
void circle(uchar Ox,uchar Oy,uchar Rx,uchar s)
{
unsigned int xx,rr,xt,yt,rs,row,col;
yt=Rx;
rr=Rx*Rx+1; //补偿 1 修正方形
rs=(yt+(yt>>1))>>1; //(*0.75)分开1/8圆弧来画
for (xt=0;xt<=rs;xt++)
{
xx=xt*xt;
while ((yt*yt)>(rr-xx))yt--;
row=Ox+xt; //第一象限
col=Oy-yt;
pixel(row,col,s);
row=Ox-xt; //第二象限
pixel(row,col,s);
col=Oy+yt; //第三象限
pixel(row,col,s);
row=Ox+xt; //第四象限
pixel(row,col,s);
/***************45度镜象画另一半***************/
row=Ox+yt; //第一象限
col=Oy-xt;
pixel(row,col,s);
row=Ox-yt; //第二象限
pixel(row,col,s);
col=Oy+xt; //第三象限
pixel(row,col,s);
row=Ox+yt; //第四象限
pixel(row,col,s);
}
}
void delay(int tt)
{
int i;
int j;
while((j++)>1000000)
{
for(i=0;i<tt;i++)
{
NOP();
}
}
}
void main()
{
unsigned int i;
//init_port();//自己加,主要是控制线所在端口为输出
DDRB = 0xff;
init_lcd();
SetRowCol(1,0);
disp_str("液晶显示的第1行");
SetRowCol(2,0);
disp_str("液晶显示的第2行");
SetRowCol(3,0);
disp_str("液晶显示的第3行");
SetRowCol(4,0);
disp_str("液晶显示的第4行");
SetRowCol(5,0);
disp_str("液晶显示的第5行");
//clr_lcd();
//for(i=0;i<64;i++) pixel(127,i,1);
//for(i=0;i<64;i++) pixel(0,i,1);
//for(i=0;i<128;i++) pixel(i,0,1);
//for(i=0;i<128;i++) pixel(i,63,1);
//for(i=0;i<40;i++)
//{
//circle(20,45,i,1); // 画圆
//}
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -