#include<12864.h>
#include<math.h>
#include <intrins.h>
uchar table[]= " 欢迎选购 ";
uchar table1[]=" 芯嵌电子 ";
uchar table2[]=" STC-52 ";
uchar table3[]=" www.simkeim.com ";
void delay(uint i) //延时函数
{
while(--i);
}
/********************************************************************
* 名称 : read_busy()
* 功能 : 读忙标志
* 输入 : 无
* 输出 : 无
***********************************************************************/
void read_busy() //读忙标志
{
RS=0;
RW=1;
EN=1;
while(P0 & 0x80);
EN=0;
}
void write_LCD_command(uchar value) //写命令函数
{
read_busy(); //每次读写前都要惊醒“忙”判断
RS=0;
RW=0;
delay(10);
EN=1; //EN从1---0锁存有效数据
P0=value;
delay(10);
EN=0;
}
void write_LCD_data(uchar value)//写数据函数
{
read_busy(); //每次读写前都要惊醒“忙”判断
RS=1;
RW=0;
delay(10);
EN=1; //EN从1---0锁存有效数据
P0=value;
delay(10);
EN=0;
}
uchar ReadByte() //读取函数
{
uchar readbyte;
read_busy();
P0=0xff;
RS=1;
RW=1;
EN=0;
EN=1;
readbyte=P0;
EN=0;
return readbyte;
}
/**********************************************************************
0,0------------------------------------127,0
| |
| |
| |
| |
0,63----------------------------------127,63
0,0代表屏幕的左上角,127,63代表屏幕的右下角。
对于屏幕上面任意一个点,如果我们想要点亮它,必须先读出此点的状态,然后再修改该点,
最后送出去,即 读----修改----写。按照这个步骤,然后再运用C语言中的位操作运算符
可以很方便的完成画点的函数
Color: 1---涂黑 0---变白 2---若反转
*************************************************************************/
void Draw_dots(uchar x,uchar y,uchar color)
{
uchar ROW,xlabel,xlabel_bit;
uchar Read_H,Read_L; //读LCD中的数据
write_LCD_command(0x34); //扩充指令
write_LCD_command(0x36); //打开绘图指令
xlabel=x>>4; //取16*16首地址
xlabel_bit=x & 0x0F; //计算该点在16位数据的第几位
if(y<32) //如果是上半屏,上下半屏y都是0--31
{
ROW=y;
}
else //显示的是下半屏
{
ROW=y-32;
xlabel+=8; //规定显示在下半屏
}
write_LCD_command(ROW+0x80); //送入垂直地址
write_LCD_command(xlabel+0x80);//再送入水平地址
ReadByte(); //读取当前GDRAM数据前腰进行一次空读,接下来就可以读出数据了
Read_H=ReadByte(); //读高8位
Read_L=ReadByte(); //读低8位
write_LCD_command(ROW+0x80); //送入垂直地址
write_LCD_command(xlabel+0x80); //再送入水平地址
if(xlabel_bit<8)
{
switch(color)
{
case 0:Read_H &= (~(0x01<<(7-xlabel_bit)));//若变白
break;
case 1:Read_H |= (0x01<<(7-xlabel_bit));//若涂黑
break;
case 2:Read_H ^= (0x01<<(7-xlabel_bit));//若反转
break;
default:break;
}
write_LCD_data(Read_H);//将数据写入GDRAM
write_LCD_data(Read_L);//先写高位,再写低位(地址指针顺序)
}
else
{
switch(color)//color设置
{
case 0: Read_L &= (~(0x01<<(15-xlabel_bit)));//若变白
break;
case 1: Read_L |= (0x01<<(15-xlabel_bit));//若涂黑
break;
case 2: Read_L ^= (0x01<<(15-xlabel_bit));//若反转
break;
default:break;
}
write_LCD_data(Read_H);
write_LCD_data(Read_L);//写入数据
}
write_LCD_command(0x30);//回到普通模式
}
void Drawline_X(uchar X0,uchar X1,uchar Y,uchar Color)//画 X轴水平线
{
uchar temp;
if (X0>X1)
{
temp=X1;
X1=X0;
X0=temp;
}
for(;X0<X1;X0++)
{
Draw_dots(X0,Y,Color);
}
}
void Drawline_Y(uchar X,uchar Y0,uchar Y1,uchar Color)//画 Y轴水平线
{
uchar temp;
if (Y0>Y1)
{
temp=Y1;
Y1=Y0;
Y0=temp;
}
for(;Y0<Y1;Y0++)
{
Draw_dots(X,Y0,Color);
}
}
void Drawline(uchar X0, uchar Y0, uchar X1 ,uchar Y1, uchar Color)//画斜线
{
int t, distance; /*根据屏幕大小改变变量类型(如改为int型)*/
int x = 0 , y = 0 , delta_x, delta_y ;
char incx, incy ;
delta_x = X1 - X0 ;
delta_y = Y1 - Y0 ;
if( delta_x > 0 )
{
incx = 1;
}
else if( delta_x == 0 )
{
Drawline_Y( X0, Y0, Y1, Color ) ;
return ;
}
else
{
incx = -1 ;
}
if( delta_y > 0 )
{
incy = 1 ;
}
else if(delta_y == 0 )
{
Drawline_X( X0, X1, Y0, Color ) ;
return ;
}
else
{
incy = -1 ;
}
delta_x = abs( delta_x );
delta_y = abs( delta_y );
if( delta_x > delta_y )
{
distance = delta_x ;
}
else
{
distance = delta_y ;
}
Draw_dots( X0, Y0, Color ) ;
/* Draw Line*/
for( t = 0 ; t <= distance+1 ; t++ )
{
Draw_dots( X0, Y0, Color ) ;
x += delta_x ;
y += delta_y ;
if( x > distance )
{
x -= distance ;
X0 += incx ;
}
if( y > distance )
{
y -= distance ;
Y0 += incy ;
}
}
}
void Draw_lingxing(uchar X0,uchar Y0,uchar R) //画菱形
{
uchar a,b;
uchar di;
if(R>31||R==0) return;
a=0;
b=R;
di=3-2*R;//判断下个点位置的标志
while(a<=b)
{
Draw_dots(X0-b,Y0-a,1);//3
Draw_dots(X0+b,Y0-a,1);//0
Draw_dots(X0-a,Y0+b,1);//1
Draw_dots(X0-b,Y0-a,1);//7
Draw_dots(X0-a,Y0-b,1);//2
Draw_dots(X0+b,Y0+a,1);//4
Draw_dots(X0+a,Y0-b,1);//5
Draw_dots(X0+a,Y0+b,1);//6
Draw_dots(X0-b,Y0+a,1);
a++;
//******使用bresenham算法画圆****/
if(di<0)
di+=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
Draw_dots(X0+a,Y0+b,1);
}
}
void Draw_circle(uchar X0,uchar Y0,uchar R) //画圆
{
char a,b;
char di;
if(R>31||R==0) return;
a=0;
b=R;
di=3-2*R;//判断下个点位置的标志
while(a<=b)
{
Draw_dots(X0-b,Y0-a,1);//3
Draw_dots(X0+b,Y0-a,1);//0
Draw_dots(X0-a,Y0+b,1);//1
Draw_dots(X0-b,Y0-a,1);//7
Draw_dots(X0-a,Y0-b,1);//2
Draw_dots(X0+b,Y0+a,1);//4
Draw_dots(X0+a,Y0-b,1);//5
Draw_dots(X0+a,Y0+b,1);//6
Draw_dots(X0-b,Y0+a,1);
a++;
//******使用bresenham算法画圆****/
if(di<0)
di+=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
Draw_dots(X0+a,Y0+b,1);
}
}
void Clear_GDRAM() //清除GDRAM
{
uchar x,y;
for(y=0;y<64;y++)
{
for(x=0;x<16;x++)
{
write_LCD_command(0x34);
write_LCD_command(y+0x80); //先送垂直地址
write_LCD_command(x+0x80); //后送水平地址
write_LCD_command(0x30); //基本指令
write_LCD_data(0x00); //写入数据0
write_LCD_data(0x00);
}
}
}
void init_LCD() //LCD12864初始化
{
// delay(100);
write_LCD_command(0x30);//8位数据格式,基本指令显示
// delay(100); //延时时间
write_LCD_command(0x30);//8位数据格式,基本指令显示
// delay(37);
write_LCD_command(0x0C);//开显示、关闭光标
// delay(100);
write_LCD_command(0x01);//清屏指令
// delay(100); //延时
write_LCD_command(0x06);//设置显示点:指针自加1
}
没有合适的资源?快使用搜索试试~ 我知道了~
51单片机课设实验源码-LCD12864液晶绘图和显示中英文字符STC51单片机例程源码.zip
共19个文件
h:2个
obj:2个
c:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 101 浏览量
2024-05-24
07:32:15
上传
评论
收藏 55KB ZIP 举报
温馨提示
51单片机课设实验源码-LCD12864液晶绘图和显示中英文字符STC51单片机例程源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
51单片机课设实验源码-LCD12864液晶绘图和显示中英文字符STC51单片机例程源码.zip (19个子文件)
51单片机课设实验源码-LCD12864液晶绘图和显示中英文字符STC51单片机例程源码
test.M51 21KB
test.hex 5KB
12864.LST 13KB
test.uvopt 6KB
test_uvproj.bak 13KB
test.c 2KB
test.plg 218B
12864.c 7KB
test.build_log.htm 1KB
test.uvgui.junzh 70KB
test.OBJ 5KB
test_uvopt.bak 56KB
test.LST 3KB
test 22KB
test.uvproj 14KB
test.lnp 54B
12864.h 871B
12864.OBJ 21KB
STC.h 17KB
共 19 条
- 1
资源评论
GJZGRB
- 粉丝: 1983
- 资源: 7116
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功