📄 hanz.i
字号:
send_com(0x71,0x00); //BGCM: 设定水平移动模式下移动的起始X位置
send_com(0x72,0xEF); //EDCM: 设定水平移动模式下移动终止X位置 239
send_com(0x80,0x60); //BTMR: 设置光标闪烁频率 闪烁时间 = [80h]Bit[7..0] x (1/Frame_Rate)
send_com(0x81,0x40); //FRCA: 通用寄存器,设置为0x40(must do that when reset the lcd)
send_com(0x90,0x0F); //SCCR: 设定XCL周期,即刷新频率,数值越大,刷新越慢
send_com(0xF0,0xA0); //简体字型(512kB) 字体ROM选择范围:ASCII自行解码
send_com(0xF1,0x0F); //字体大小置 正常
}
//清屏函数,将文本层和图形层全清空
void clear_screen()
{
unsigned int i;
send_com(0x12,0xB3); //光标先水平移动在垂直移动,显示两个图层
//关系为或,同时存取数据
send_com(0x60,0x00); //光标回到左上角
send_com(0x70,0x00); //光标回到左上角
for(i=0;i<3840;i++)post_msg(0x00);
}
//---显示字符串,包括中文字符,可混合中英文即符号 数字*************
//X0:列设置(0-29) Y0:行设置0 to 128=16*8 ****not (0-15)******************
//a chinese word width is 8 byte for the function ,lt's height is 16 byte***
void show_text(unsigned char x,unsigned char y,unsigned char daxiao,unsigned char *text)
{
unsigned char temp=0x0f;
send_com(0x00,0xcd); //到文字模式
switch(daxiao)
{case 0: temp=0x0f; break;
case 1: temp=0x5f; break;
case 2: temp=0xaf; break;
case 3: temp=0xff; break;
}
send_com(0xf1,temp); //设定放大倍数
send_com(0x12,0xB1); //光标右移 双层图层 or 操作图层1
send_com(0xf0,0xa0); //换字符表到表0 //进入文本图层
send_com(0x60,x); //光标的位置
send_com(0x70,y);
while((*text)>0)
{
post_msg(*text);delay_us(50);
text++;
}
}
/**************************************************************************
x表示行坐标,每一个象点表示一行
y表示列坐标,每一个字符表示一列,自动与字符大小匹配
daxiao表示的是字符放大系数,高四位表示横向放大,低四位表示纵向放大倍数
p表示需要显示的字符的ASCII码,所有的显示均使用标准ASCII码
*************************************************************************/
void word(unsigned char x,unsigned char y,unsigned char daxiao,unsigned char p)
{unsigned char temp=0;
temp=daxiao-0x11;//转化为内部的实际寄存器值
daxiao=temp;
daxiao=daxiao<<6;
temp|=0x0f;
temp|=daxiao;
send_com(0xf1,temp);
send_com(0x12,0xB1);
send_com(0xf0,0xa0); //换字符表到表0
send_com(0x60,x); //x,y与液晶的实际地址刚好是反的
send_com(0x70,y);
post_msg(p);
}
/*==---显示单个数字============================
此函数还可以显示单个的英文字符,对应的为其ASCII值A=17,a=49
/*********************for each chinese or engligh word ,each of x
show_num(12,64,7);
show_num(12,80,'7'-48); is different
************************8 bite of y,change a state************
//*** x range 0 to 29,for y,each 8 bite will change state *****/
void show_num(unsigned char x,unsigned char y,unsigned char num)
{ send_com(0x00,0xcd); //到文字模式
send_com(0x12,0xB1);
send_com(0x60,x); //光标的位置
send_com(0x70,y);
post_msg(num+48); //48+number i=ASCII value
}
/*************************************************************************
专门用来显示数字的
在调用xianshi_8803的时候在地址后length_long 内不能送数据
x行坐标,y列坐标k为要显示的数,weishu为要控制保留小数的位数,和串口的显示函数是一个意思
函数会自动补零,自动识别负数
the function change one state when x change 1 unit or y change 16 units
*************************************************************************/
void xianshi_8803(unsigned char x,unsigned char y,long k,unsigned char weishu)
{
unsigned char *p="12345678";
unsigned char i;
unsigned int temp;
ltoa(k,p); //shift long int k to char string p
temp=strlen(p); //return the length of p
if(temp<=weishu)
{
if((*p)=='-'){ show_num(x++,y,'-'-48) ; p++;temp-=1;}
show_num(x++,y,'0'-48) ;show_num(x++,y,'.'-48) ;
for(i=0;i<weishu-temp;i++) show_num(x++,y,'0'-48) ;
for(i=0;i<temp;i++) show_num(x++,y,*(p++)-48) ;
}
else
{
if((*p)=='-'){ show_num(x++,y,'-'-48) ;p++;temp-=1;}
for(i=0;i<temp-weishu;i++) show_num(x++,y,*(p++)-48) ;
show_num(x++,y,'.'-48) ;
for(i=temp-weishu;i<temp;i++)show_num(x++,y,*(p++)-48) ;
for(i=temp;i<8;i++) show_num(x++,y,' '-48) ; //set the number length use i=8.9....
}
}
//---显示bmp位图,利用那个软件把一幅图片生成01代码
//然后把代码粘贴到zimo.c里面 然后编译 下面的flash不能省
//只能是240*128的 其他的都不能 因此生成代码时也必须是240*128的
//大了不行
//其实应该是可以显示小的的,只要把下面的for语句改一下 不要让它把全屏都那个了
//生成小一点的图片然后把相应的地方那个了就可以了,但是不试了,没多大的意义。
void show_picture(flash unsigned char *picture)
{
unsigned long i=0;
send_com(0x12,0xB2); //图层
send_com(0x00,0xc5); // 到图形模式
send_com(0x60,0);
send_com(0x70,0);
for(i=0;i<3840;i++)
post_msg(picture[i]);
}
//************************************ 读数据 *******************
//读语句 temp=DATA_IN; 必须在 RD=1(读关闭)之后,否则不能正确读取。
unsigned char read_data(unsigned char x,unsigned char y)
{ unsigned char temp;
send_com(0x12,0xb2);
send_com(0x60,x);
send_com(0x70,y);
delay_us(1);
PORTA =0xff;
DDRA =0x00;
PORTD.6 =1;
PORTD.5 =0;
PORTD.4 =0;
delay_us(10);
PORTD.4 =1;
temp=PINA ;
PORTD.5 =1;
PORTA =0;
DDRA =0xFF;
return (temp);
}
/***************************************************************************
/*****a word width is 16 byte for the function ,lt's height is 16 byte*****
**************************************************************************/
//*打一个点 x,y为其精确位置
void point(unsigned char x,unsigned char y)
{unsigned char temp=0;
temp=x%8;
temp=1<<(7-temp);
send_com(0x00,0xc5); //进入图形模式
send_com(0x12,0xB2);
send_com(0x60,x/8);
send_com(0x70,y);
temp|=read_data(x/8,y); //这个很重要 可以使所有内容不互相遮蔽
post_msg(temp);
}
//画横线 x,y为精确位置
void line_x(unsigned char x1,unsigned char x2,unsigned char y)
{ unsigned char temp1=0,temp2=0,i=0,j=1;
for(i=0;i<=x2-x1;i++)
{ point(x1+i,y);
temp1|=read_data(x1/8,y);
if(i==x2-x1) //如果在8个小单位以内
{ post_msg(temp1);}
else
if(temp1&0x01==1)
{ post_msg(temp1);
temp1=0;
x1=x1+i+1;
while(x1+8<=x2) //中间全部为高
{
send_com(0x60,x1/8);
send_com(0x70,y);
post_msg(0xff);
x1=x1+8;
}
for(i=0;i<=x2-x1;i++)
{ point(x1+i,y);
temp1|=read_data(x1/8,y);
if(i==x2-x1)
{ post_msg(temp1);
temp1=0;}
}
break;
}
}
}
/*****************a word width is 16 byte for the function ,lt's height is 16 byte********
//==============画竖线=== k为某行的某一小行,值为0-7=======================================
*******************************************************************************************/
void line_y(unsigned char x,unsigned char y1,unsigned char y2)
{
unsigned char temp=0;
send_com(0x00,0xc5); //到图形模式
if(y1>y2){temp=y2;y2=y1;y1=temp;}
for(temp=y1;temp<=y2;temp++)
{ point(x,temp);}
}
/************************************************************************/
//y1 为初始位置,y2 为结束位置,它是通过滚动所选的屏幕范围来实现字的滚动
//0x03中高4 位必须为高,否则无输出,光标始终是不跟着移动的。
//每次移动一个像素,移动频率和光标闪烁频率相同,所以可以控制光标闪烁来控制
//移动速度,即控制寄存器0x80来控制移动速度
//垂直移动时y1,y2的控制不起作用,是整个屏幕的卷动。
void gundong_row(unsigned char y1,unsigned char y2) //row 排
{send_com(0x03,0xf3); //f3为水平移动,f4为垂直移动
send_com(0x71,y1);
send_com(0x72,y2);
}
void gundong_line(unsigned char y1,unsigned char y2) //line 列 向上垂直滚动整个屏幕
{send_com(0x03,0xf4); //f3为水平移动,f4为垂直移动
send_com(0x71,y1);
send_com(0x72,y2);
}
//*******画圆 输入中心坐标和半径*******************************
//利用双向输出显示以弥补双方的不足
void huayuan(unsigned char x,unsigned char y,unsigned int r)
{
unsigned char i=0;
unsigned int b=0,a=0,c=0,d=0;
a=x-r; //a为最左边的那个点的横坐标
for(i=0;i<=2*r;i++)
{
b=(unsigned int)sqrt(r*r-(x-a)*(x-a));
point(a,b+y);
point(a,y-b);
a++; //横坐标每加一次就输出相应的y坐标
}
c=y-r;
for(i=0;i<=2*r;i++)
{
d=(unsigned int)sqrt(r*r-(y-c)*(y-c));
point(x-d,c);
point(x+d,c);
c++;
}
}
//********正弦函数显示**************************
//四个参数分别为:x,y为原点坐标(精确位置);t为周期;f为振幅。
void zhengxian (unsigned char x,unsigned char y,unsigned char t,unsigned char f)
{ unsigned char i=0,j=0,m=0,p=0,q=0;
m=x;
line_x(x-5,230,y);
line_y(x,y-f-10,y+f+10);
//******虽然这个语言上比那个复杂,但运行效率比那个高 (是否是的我也不是很确定)
point(x,y-(unsigned char)f*sin(0));
for(i=0;i<=230-m;i++)
{
if(i!=0)
{
p=q ;
point(x,p);}
else p=y;
j++; x++;
q=y-(unsigned char)f*sin(6.28*j/t);
line_y(x,p,q);
if(j==t)
{ j==0;}
}
}
//#include "zimo.c"
unsigned char text1[]={"你好"}; //只能在分号里面 如果是在外面
unsigned char text2[]={"电子设计与创新"}; // 出现的可能会错或出现图形
unsigned char text3[]={"LOVE WITN YOU !"};
void main()
{
LCD_INIT(); //初始化
clear_screen(); //清屏
//大小位置测试 ******************
// show_text(1,8,0,text1);
// show_text(10,24,1,text1); //可以控制大小
// show_text(10,24,0,text3); //大小要恢复 否则后面显示的都是设定大小
//xianshi_8803(8,40, -1122254,5);
//xianshi_8803(8,60, -12122254,5);
//xianshi_8803(8,80, 112254,8);
//show_number(8,60, 1122.334,5);
//show_number(24,80,1,3);
//show_number(24,100,11001,0);
//show_num(14,100,6); //只是对应一些单个的字符
//show_num(0,114,8);
//show_text(5,30,0,text3);
//show_num(0,55,19);
//平动卷动测试************************
//show_text(10,50,1,text2);
//show_text(5,34,0,text1);
//gundong_row(34,49) ;
//画线测试**************************
//line_y(11,0,128);
//line_y(12,0,128);
//line_x(2,6,105 );
//line_x(2,6,106 );
//point(80,70);
//point(81,71);
//point(34,105);
//draw_dot(36,105,1);
//huayuan(120,80,20);
zhengxian(25,65,60,30);
//***********************************
//*******************显示bmp位图 *************
//show_picture(li);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -