📄 qudong.c
字号:
#include <reg51.h>
/**********************控制端口定义*********************
sbit rst p2^5
sbit cd p2^6
sbit ce p2^7
sbit wr p3^6
sbit rd p3^7
/*************定义标志位****************/
#define ture 1
#define flase 0
/*********定义通道地址***********/
#define code1 0x8100 /*****指令通道地址****/
#define data1 0x8000 /*****数据通道地址****/
/***************状态字检测***************/
CheckState()
{
unsigned char dat;
if((code&0x03)==0x03)
return ture;
else
return flase;
}
/***********指令参数设置**************/
void OutPortData(unsigned char para)
{
CheckState(); //状态检查
cd=0; //写数据
wr=0;
data1=para;
wr=1;
cd=1;
}
/**************写没有参数的指令**************/
void OutPortCom(unsigned char command)
{
CheckState(); //状态检查
wr=0; //写指令
code1=command;
wr=1;
cd=1;
}
/***************写有一个参数的指令***************/
void OutPortCom1(unsigned char dat, unsigned char command)
{
OutPortData(dat);
OutPortCom(command);
}
/******************写两个参数的指令***************/
void OutPortCom2(unsigned char d1, unsigned char d2, unsigned char command)
{
OutPortData(d1);
OutPortData(d2);
OutPortCom(command);
}
/*********************清屏*******************/
void ClearScreen()
{
unsigned int i;
OutPortCom2(0x00, 0x00, 0x24); //设置地址指令,RAM地址0x0000
OutPortCom(0xb0); //自动写指令
for(i=0;i<0x2000;i++)
{
OutPortData(0x00); //data=0
}
OutPortCom(0xb2); //自动写结束指令
}
/******************延时函数*****************/
void delay()
{
int x=2000;
do
{ x=x-1;
}
while(x>1);
}
/**************LCD初始化*************/
void initlcd()
{
delay();
OutPortCom2(0x00, 0x00, 0x42); //设置图形显示区域首地址
OutPortCom2(0x20, 0x00, 0x43); //文本显示区域宽度32字节
outportcom2(0x00,0x00,0x40); //设定文本显示区域首地址
outportcom2(0x20,0x00,0x41); //文本显示区域宽度32字节
OutPortCom(0xa7); //设置光标形状
OutPortCom(0x80); //设置显示方式:
OutPortCom(0x98); //设置显示开关
ClearScreen();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -