视频教程:https://www.bilibili.com/video/BV1rR4y177NK
#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器
#define uchar unsigned char
#define uint unsigned int
typedef unsigned int u16; //对数据类型进行声明定义
typedef unsigned char u8;
sbit wr=P2^0; //数据写
sbit rd=P2^1; //数据读
sbit ce=P2^2; //片选
sbit cd=P2^3; //指令数据通道,1指令,0数据
sbit rst=P2^4; //复位信号
uchar code HZ0[][32]={
{0x02,0x00,0x02,0x00,0x02,0x00,0x03,0xFC,0x02,0x00,0x02,0x00,0x3F,0xF0,0x20,0x10,
0x20,0x10,0x20,0x10,0x3F,0xF0,0x00,0x00,0x24,0x88,0x22,0x44,0x42,0x44,0x80,0x04},/*"点",0*/
{0x00,0x80,0x00,0x80,0xFC,0x80,0x04,0xFC,0x05,0x04,0x49,0x08,0x2A,0x40,0x14,0x40,
0x10,0x40,0x28,0xA0,0x24,0xA0,0x45,0x10,0x81,0x10,0x02,0x08,0x04,0x04,0x08,0x02},/*"欢",0*/
{0x00,0x00,0x20,0x80,0x13,0x3C,0x12,0x24,0x02,0x24,0x02,0x24,0xF2,0x24,0x12,0x24,
0x12,0x24,0x12,0xB4,0x13,0x28,0x12,0x20,0x10,0x20,0x28,0x20,0x47,0xFE,0x00,0x00},/*"迎",1*/
{0x10,0x40,0x10,0x40,0x1F,0xFE,0x20,0x40,0x20,0x40,0x67,0xFC,0x64,0x44,0xA4,0x44,
0x27,0xFC,0x20,0x40,0x22,0x40,0x21,0x40,0x20,0x80,0x21,0x40,0x22,0x30,0x2C,0x0E},/*"使",2*/
{0x00,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,
0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x41,0x08,0x41,0x28,0x80,0x10},/*"用",3*/
};
uchar code SZ[][16]={
{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",0*/
{0x00,0x00,0x00,0x08,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"1",1*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",2*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x02,0x04,0x18,0x04,0x02,0x42,0x42,0x3C,0x00,0x00},/*"3",3*/
{0x00,0x00,0x00,0x04,0x0C,0x0C,0x14,0x24,0x24,0x44,0x7F,0x04,0x04,0x1F,0x00,0x00},/*"4",4*/
{0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x78,0x44,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",5*/
{0x00,0x00,0x00,0x18,0x24,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x22,0x1C,0x00,0x00},/*"6",6*/
{0x00,0x00,0x00,0x7E,0x42,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",7*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",8*/
{0x00,0x00,0x00,0x38,0x44,0x42,0x42,0x42,0x46,0x3A,0x02,0x02,0x24,0x18,0x00,0x00},/*"9",9*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",10*/
};
void delay(uint t) //延时函数
{
uint i,j;
for(i=0;i< 1;i++);
}
void Delay_xms(uint x)
{
uint i,j;
for(i=0;i< x;i++)
for(j=0;j< 112;j++);
}
uchar read_status() //读取lcd12864的状态
{
uchar status;
P0=0;//端口b置为输入
rd=0;
wr=1;
ce=0;
cd=1;
status=P1;
return status;
}
void check_status()//检查lcd12864的状态
{
uchar s;
P0=0Xff;//端口b置为输出
while((s&0x80)!=0x80)
s=read_status();//等待位1,2置为。命令读写准备好。数据读写准备好
}
void write_data(uchar dat)//写数据
{
rd=1;
cd=0;
ce=0;
wr=0;
P0=dat;
delay(1);
wr=1;
ce=1;
cd=1;
}
void write_cmd1(uchar cmd)//写数据1
{
rd=1;
cd=1;
ce=0;
wr=0;
P0=cmd;
delay(1);
wr=1;
ce=1;
cd=0;
}
//先送参数,再送指令
void write_cmd2(uchar dat,uchar cmd)
{
check_status();
write_data(dat);
check_status();
write_cmd1(cmd);
}
void write_cmd3(uchar data1,uchar data2,uchar cmd)//发送参数并发指令再发送数据
{
check_status();
write_data(data1);
check_status();
write_data(data2);
check_status();
write_cmd1(cmd);
}
void init()//LCD12864的初始化
{
P2=0Xff;
P1=0Xff;
rst=1;
delay(10);
rst=0;
wr=1;
rd=1;
ce=1;
cd=1;
rst=1;
check_status();
write_cmd3(0x01,0x00,0x21);//光标指针设置
check_status();
write_cmd3(0x00,0x00,0x42);//图形区首地址
check_status();
write_cmd3(16,0x00,0x43);//图形区宽度
check_status();
write_cmd1(0x80);//显示方式设置,正常显示
check_status();
write_cmd1(0x98);//图形方式显示,不显示字母,只打点
check_status();
write_cmd1(0xa0);//光标形状设置1 0 1 0 0 N2 N1 N0
}
//汉字显示函数,处在x y处显示汉字
void display_HZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-7
{
uchar i,j=0;
for(i=0;i< 16;i++)
{
write_cmd3(((j/2)< <4)|(y*2),x,0x24);//地址指针设置..低地址,高地址,命令
write_cmd2(hz[j++],0xc0);
write_cmd2(hz[j++],0xc0);
}
}
void display_SZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-14
{
uchar i,j=0;
for(i=0;i< 16;i++)
{
write_cmd3(((j)< <4)|y,x,0x24);//地址指针设置..低地址,高地址,命令
write_cmd2(hz[j++],0xc0);
}
}
void main()
{
u8 dat;
init();
Delay_xms(10);
display_HZ(0,0,HZ0[1]);
display_HZ(0,1,HZ0[2]);
display_HZ(0,2,HZ0[3]);
display_HZ(0,3,HZ0[4]);
dat = 0;
display_SZ(2,2,SZ[dat]);
Delay_xms(1000);
dat = 9;
display_SZ(2,2,SZ[dat]);
while(1)
{
}
}
审核编辑:汤梓红
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。
举报投诉
-
Proteus
+关注
关注
79文章
1692浏览量
106368 -
点阵
+关注
关注
6文章
194浏览量
72469 -
LCD12864
+关注
关注
7文章
232浏览量
44836 -
复位信号
+关注
关注
0文章
53浏览量
6299
发布评论请先 登录
相关推荐
LABVIEW程序怎么设置中英文切换
我做了一个程序,上级要求最好能做成中英双文(不是软件语言,是写出来的程序的语言),然后我就像通过控件标签文本属性来设置,做一个中英文的枚举,英文显示默认标签,中文
发表于 02-29 21:20
使用Proteus仿真LCD12864液晶显示动画的程序免费下载
本文档的主要内容详细介绍的是使用Proteus仿真LCD12864液晶显示动画的程序免费下载。
发表于 09-11 10:32
•91次下载
评论