📄 lcdp.c
字号:
#include <reg51.h>
#include <intrins.h>
#include "LCDP.h"
#define NOP _nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
/*********************************************************/
/* 液晶显示模块控制函数(外设扩充方式)
/* 液晶显示屏大小:128*64
/* 控制器:HD61202/3
/* 控制方式:单片机扩展端口方式控制
/* 作者:mudfish 最后修改:2005-11-13 11:43
/*********************************************************/
/*********************************************************/
/* 读控制器状态函数 */
/* 参数:chip 0:第1片控制器, 非0:第2片控制器 */
/* 返回:状态字 */
/*********************************************************/
unsigned char LCD_Status(unsigned char chip)
{
unsigned char c;
if(chip == 0)
c = CRADD1;
else
c = CRADD2;
NOP;
return c;
}
/*********************************************************/
/* 控制显示屏开关函数 */
/* 参数:onoff 0:关, 1:开, 不可取其它值 */
/*********************************************************/
void LCD_OnOff(unsigned char onoff)
{
while( LCD_Status(0) & 0x90 );
NOP;
CWADD1 = 0x3E | (onoff & 0x01);
NOP;
while( LCD_Status(1) & 0x90 );
NOP;
CWADD2 = 0x3E | (onoff & 0x01);
NOP;
}
/*********************************************************/
/* 设置起始显示行函数 */
/* 参数:line 起始显示行,取值范围0~63 */
/*********************************************************/
void LCD_SetStartLine(unsigned char line)
{
while( LCD_Status(0) & 0x90 );
NOP;
CWADD1 = 0xC0 | (line & 0x3F);
NOP;
while( LCD_Status(1) & 0x90 );
NOP;
CWADD2 = 0xC0 | (line & 0x3F);
NOP;
}
/*********************************************************/
/* 设置X地址(页地址,对应显示屏的行,8行一组)函数 */
/* 参数:chip 控制器芯片号; x 页地址,取值范围0~7 */
/*********************************************************/
void LCD_SetXAddress(unsigned char chip, unsigned char x)
{
if( chip == 0)
{
while( LCD_Status(0) & 0x90 );
NOP;
CWADD1 = 0xB8 | (x & 0x07);
NOP;
}
else
{
while( LCD_Status(1) & 0x90 );
NOP;
CWADD2 = 0xB8 | (x & 0x07);
NOP;
}
}
/*********************************************************/
/* 设置Y地址函数(列地址,对应显示屏的列) */
/* 参数:chip 控制器芯片号; y 列地址,取值范围0~64 */
/*********************************************************/
void LCD_SetYAddress(unsigned char chip, unsigned char y)
{
if(chip == 0)
{
while( LCD_Status(0) & 0x90 );
NOP;
CWADD1 = 0x40 | (y & 0x3F);
NOP;
}
else
{
while( LCD_Status(1) & 0x90 );
NOP;
CWADD2 = 0x40 | (y & 0x3F);
NOP;
}
}
/*********************************************************/
/* 向显示屏写数据函数 */
/* 参数:c 数据 */
/* x,y 对应的行/列地址 */
/*********************************************************/
void LCD_WriteData(unsigned char c, unsigned char x, unsigned char y)
{
if(x<64)
{
LCD_SetXAddress(0,y);
NOP;
LCD_SetYAddress(0,x);
NOP;
DWADD1 = c;
NOP;
}
else
{
LCD_SetXAddress(1,y);
NOP;
LCD_SetYAddress(1,x-64);
NOP;
DWADD2 = c;
NOP;
}
}
/*********************************************************/
/* 读LCD显示数据函数 */
/* 参数:x,y 对应的行/列地址 */
/* 返回:读出的数据 */
/*********************************************************/
unsigned char LCD_ReadData(unsigned char x, unsigned char y)
{
unsigned char c;
if(x<64)
{
LCD_SetXAddress(0,y);
NOP;
LCD_SetYAddress(0,x);
NOP;
c = DRADD1;
NOP;
}
else
{
LCD_SetXAddress(1,y);
NOP;
LCD_SetYAddress(1,x-64);
NOP;
c = DRADD2;
NOP;
}
return c;
}
/*********************************************************/
/* 显示屏复位 */
/*********************************************************/
void LCD_Reset(void)
{
LCD_OnOff(1);
LCD_SetStartLine(0);
}
/*********************************************************/
/* 显示屏清屏并填充字符 */
/* 参数:c 填充字符的ASCII码 */
/*********************************************************/
void LCD_ClrScr(unsigned char c)
{
unsigned char x,y;
for(y=0;y<=7;y++)
{
for(x=0;x<=127;x++)
{
LCD_WriteData(c,x,y);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -