1 Proteus教程:LCD12864中英文显示-德赢Vwin官网 网

Proteus教程:LCD12864中英文显示

描述

视频教程:https://www.bilibili.com/video/BV1rR4y177NK

 LCD12864LCD12864LCD12864
#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)
	{
		
	}
}

   审核编辑:汤梓红

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表德赢Vwin官网 网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分