📄 lcd7920.c
字号:
/****************************************************************************
* *
* File: LCD.C *
* *
* Created: 29/12/05 *
* *
* Author: 王凤秀 *
* *
* Compiler: KEIL C51 V6.23 *
* *
* Description: RT12864液晶屏例程库. *
* *
*****************************************************************************
* *
* Version | Date | Description *
* --------+----------+----------------------------------------------------- *
* V1.0 | 21.11.95 | 原始文本 *
* *
****************************************************************************/
#define _LCD_GLOBALS
#include "Includes.h"
/*******************************************************************************************
* *
* Function:void LCD_Init(void) *
* *
* Input: - *
* Output: - *
* *
* Description: 液晶屏初始化例程. *
* *
*******************************************************************************************/
void LCD_Init(void)
{
LCD_Send_CMD(0x30); //功能设定:8位并口
LCD_Wait_nBysy(); //等待命令处理结束.
delay_1ms(0x0A);
LCD_Send_CMD(0x30); //功能设定:8位并口
delay_1ms(0x0A);
LCD_Wait_nBysy(); //等待命令处理结束.
LCD_Send_CMD(0x0C); //B2=1--整体显示On, B1=1--游标显示On, B0=1--游标反显On.
LCD_Wait_nBysy(); //等待命令处理结束.
LCD_Send_CMD(0x01); //清显示.
LCD_Wait_nBysy(); //等待命令处理结束.
LCD_Send_CMD(0x06); //配置:B1=1--游标右移, B0=1画面整体移动.
LCD_Wait_nBysy(); //等待命令处理结束.
}
/*******************************************************************************************
* *
* Function:uchar Wait_EN_LCD_CMD_Write(void) *
* *
* Input: - *
* Output: - *
* *
* Description: 等待LCD进入命令写使能状态. *
* *
*******************************************************************************************/
void LCD_Wait_nBysy(void)
{
while(LCD_Read_CMD() & 0x80)
{
_nop_();
}
}
/*******************************************************************************************
* *
* Function:uchar LCD_Print_Chinese(uchar _ROW,uchar _COL, code uchar * PT,uchar _Num) *
* *
* Input: -_ROW--起始行号 *
* _COL--起始列号 *
* _PT --字符串指针 *
* _Num--要显示的汉字数. *
* Output: - *
* *
* Description: 显示汉字串. *
* *
*******************************************************************************************/
void LCD_Print_Chinese(uchar _ROW,uchar _COL, uchar code * PT,uchar _Num)
{
uchar data itmp;
uchar data count;
uchar Tmp_Array[0x10];
//计算显示首址
itmp=_Num;
itmp=((_ROW*0x20+_COL) % 0x40) | 0x40;
LCD_Send_CMD(itmp); //置起始行列
count=0;
Tmp_Array[0]=(uchar) itmp;
Tmp_Array[1]=(uchar) (itmp>>8);
Tmp_Array[2]=0x24; //设置显示存储器首址
LCD_Send_CMD(Tmp_Array[0]);
while(count<0xF0)
{
if(PT[count]==0)
break;
Tmp_Array[1]=PT[count]-0x20;
Tmp_Array[2]=0xC0; //设置显示存储器首址
LCD_Send_CMD(Tmp_Array[0]);
++count;
}
}
/*******************************************************************************************
* *
* Function:uchar LCD_Print_Chr(uchar _ROW,uchar _COL, uchar PT) *
* *
* Input: -_ROW--起始行号 *
* _COL--起始列号 *
* _字符串指针 *
* Output: - *
* *
* Description: 显示一个字符. *
* *
*******************************************************************************************/
void LCD_Print_Chr(uchar _ROW,uchar _COL, uchar PT)
{
uint data itmp;
uchar data count;
uchar data Tmp_Array[3];
//计算显示首址
itmp=_ROW*0x10+_COL;
count=0;
Tmp_Array[0]=(uchar) itmp;
Tmp_Array[1]=(uchar) (itmp>>8);
Tmp_Array[2]=0x24; //设置显示存储器首址
LCD_Send_CMD(Tmp_Array[0]);
Tmp_Array[1]=PT-0x20;
Tmp_Array[2]=0xC4; //设置显示存储器首址
LCD_Send_CMD(Tmp_Array[0]);
}
/*******************************************************************************************
* *
* Function:uchar LCD_Print_HEX(uchar _ROW,uchar _COL, uchar _DATA) *
* *
* Input: -_ROW--起始行号 *
* _COL--起始列号 *
* _DATA-要打印的数据 *
* Output: - *
* *
* Description: 显示字符串. *
* *
*******************************************************************************************/
void LCD_Print_HEX(uchar _ROW,uchar _COL, uchar _DATA)
{
uint data itmp;
uchar data count;
uchar data Tmp_Array[3];
//计算显示首址
itmp=_ROW*0x10+_COL;
count=0;
Tmp_Array[0]=(uchar) itmp;
Tmp_Array[1]=(uchar) (itmp>>8);
Tmp_Array[2]=0x24; //设置显示存储器首址
LCD_Send_CMD(Tmp_Array[0]);
count=_DATA>>4;
if (count>0x09)
count=count+0x17;
else
count=count+0x10;
Tmp_Array[1]=count;
Tmp_Array[2]=0xC0; //设置显示存储器首址
LCD_Send_CMD(Tmp_Array[0]);
count=_DATA & 0x0F;
if (count>0x09)
count=count+0x17;
else
count=count+0x10;
Tmp_Array[1]=count;
Tmp_Array[2]=0xC0; //设置显示存储器首址
LCD_Send_CMD(Tmp_Array[0]);
}
/*******************************************************************************************
* *
* Function:void LCD_Send_CMD(uchar _Cmd) *
* *
* Input: - *
* Output: - *
* *
* Description: 对LCD写入指令. *
* *
*******************************************************************************************/
void LCD_Send_CMD(uchar _Cmd)
{
RS=false;
P0=_Cmd;
RnW=false;
E=true;
_nop_();
E=false;
}
/*******************************************************************************************
* *
* Function:void LCD_Send_Data(uchar _Data) *
* *
* Input: - *
* Output: - *
* *
* Description: 对LCD写入数据. *
* *
*******************************************************************************************/
void LCD_Send_Data(uchar _Data)
{
RS=true;
P0=_Data;
RnW=false;
E=true;
_nop_();
E=false;
}
/*******************************************************************************************
* *
* Function:uchar LCD_Read_CMD(void) *
* *
* Input: - *
* Output: - *
* *
* Description: 对LCD写入指令. *
* *
*******************************************************************************************/
uchar LCD_Read_CMD(void)
{
uchar Btmp;
RnW=true;
RS=false;
Btmp=P0;
E=true;
_nop_();
Btmp=P0; //哑读
E=false;
_nop_();
E=true;
_nop_();
Btmp=P0;
E=false;
return(Btmp);
}
/*******************************************************************************************
* *
* Function:uchar LCD_Read_Data(void) *
* *
* Input: - *
* Output: - *
* *
* Description: 对LCD写入指令. *
* *
*******************************************************************************************/
uchar LCD_Read_Data(void)
{
uchar Btmp;
RnW=true;
RS=true;
Btmp=P0;
E=true;
_nop_();
Btmp=P0;
E=false;
_nop_();
E=true;
_nop_();
Btmp=P0;
E=false;
return(Btmp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -