📄 lcd_display.c
字号:
/**************************************************************
菜单调试程序
*****************************************************/
#include <stdio.h> /* standard I/O .h-file */
#include <reg51f.h>
#include <absacc.h>
#include "lcd.h"
#include "x5045.h"
sbit lcd_rs = P1^5;
sbit lcd_e = P1^7;
sbit lcd_rw = P1^6;
xdata struct TIME /* structure of the clock record */
{
unsigned char hour; /* hour */
unsigned char min; /* minute */
unsigned char sec; /* second */
};
xdata struct DATE
{
unsigned char year;
unsigned char mon;
unsigned char day;
unsigned char week;
};
/**********
延时子程序
**********/
void Delay(void)
{
unsigned char i;
i = 8;
while(--i);
}
/**********
写指令子程序
**********/
void LcdCommand(unsigned char tt)
{
Delay();
lcd_rs = 0;
lcd_rw = 0;
lcd_e = 1;
Delay();
LCD = tt;
Delay();
lcd_e = 0;
Delay();
}
/**************
写数据子程序
**************/
void LcdData( unsigned char temp )
{
Delay(); //以确保上一指令/数据模块已经接收处理完
lcd_rs = 1;
lcd_rw = 0;
lcd_e = 1;
Delay();
LCD = temp;
Delay();
lcd_e = 0;
Delay();
}
/* 初始化LCD*/
void InitLcd(void)
{ unsigned char i;
LcdCommand(0x30); // 30---基本指令操作 //8 位控制接口,基本指令集动作
// Delay();
LcdCommand(0x01); // 指令#01H为:清除屏幕文字,把地址指针指向00H单元
for(i=0;i<201;i++)
Delay();
PrintStr(0,0," ");
// Delay();
// LcdCommand(0x02);
// LcdCommand(0x06); // 指定在资料写入或读取时,设定游标的移动方向及指定显示的移位
// Delay();
// LcdCommand(0x0C);
}
/**************************************************
SEARCH ADDRESS
目的是为了转换地址单元为DDRAM地址单元,以方便定义显示位置
汉字显示DDRAM位置为:第一行:80H----87H
第二行:90H----97H
*****************************************************/
unsigned char ChangeAddr(first_lin, first_add)
unsigned char first_lin, first_add;
{
unsigned char StarAddr;
switch( first_lin )
{
case 0: //first line
StarAddr = 0x80;
break;
case 1: //second line
StarAddr = 0x90;
break;
case 2: //first line
StarAddr = 0x88;
break;
case 3: //second line
StarAddr = 0x98;
break;
}
return( StarAddr + first_add );
}
/********************
在指定位置显示汉字,字符
y: 显示的纵坐标 0-3
x: 显示的横坐标 0-7
*********************/
void PrintStr(y, x, p)
unsigned char y, x, *p;
{
unsigned char addr;
while( *p )
{
addr = ChangeAddr(y,x); //调用调整地址单元子程序
LcdCommand(addr); //设定DDRAM地址,显示位置地址
LcdData( *p ); //因为要连续输入机内码高位(区码)、低位(位码)
p++;
if ( !(*p) ) //如果是串尾则返回
return;
LcdData( *p ); //所以要输入两次数据,如果是字符就是输入两个字符字符代码
p++;
x++;
if (x>7)
return;
}
}
/**********************
清除图形显示
***********************/
void ClearGraph(void)
{
unsigned char row,column,i,j;
//watchdog();
row = 0x80; //列
column = 0x80; //行
for(j=0;j<=33;j++)
{
for(i=0;i<=17;i++)
{
LcdCommand(0x34); //关闭绘图显示功能
LcdCommand(column+j); //起始行
LcdCommand(row+i); //起始列
LcdCommand(0x30); //基本指令集
LcdData(0); //输入显示数据(横向高8位数据)
LcdData(0); //输入显示数据(横向低8位数据)
}
}
LcdCommand(0x36); //打开绘图显示功能
LcdCommand(0x30);
}
/*****************************************************************************************
反白显示行line = 0~3
第一、三行由一片IC控制
第二、四行由一片IC控制
第一行纵坐标80h-8fh(以点为单位),横坐标80H-87H(以字为单位);第三行纵坐标80h-8fh,横坐标88H-8FH
第二行纵坐标80h-8fh(以点为单位),横坐标90H-97H(以字为单位);第四行纵坐标80h-8fh,横坐标98H-9FH
******************************************************************************************/
void ReverseLine(unsigned char line)
{
unsigned char row,column,i,j;
ClearGraph();
switch(line) //选择行列的起始位置
{
case 0:
column = 0x80;
row = 0x80;
break;
case 1:
column = 0x90;
row = 0x80;
break;
case 2:
column = 0x80;
row = 0x88;
break;
case 3:
column = 0x90;
row = 0x88;
break;
}
for(j=0;j<=15;j++)
{
for(i=0;i<=7;i++)
{
LcdCommand(0x34);
LcdCommand(column+j); //起始行
LcdCommand(row+i); //起始列
// LcdCommand(0x30); //
LcdData(0xff); //输入显示数据(横向高8位数据)
LcdData(0xff); //输入显示数据(横向低8位数据)
}
}
LcdCommand(0x36);
LcdCommand(0x30);
}
/***********************************
大图表显示 通讯设置函数用
y=0~3 ; x=0~15
************************************/
/*
void Reverse(y,x1,x2)
unsigned char y,x1,x2;
{
unsigned char row,column,x,j;
ClearGraph();
for(x = x1; x <= x2; x++)
{
switch(y)
{
case 0:
column = 0x80;
row = 0x80 + x/2;
break;
case 1:
column = 0x90;
row = 0x80 + x/2;
break;
case 2:
column = 0x80;
row = 0x88 + x/2;
break;
case 3:
column = 0x90;
row = 0x88 + x/2;
break;
}
if (x%2) //if the location is odd
{
for(j=0;j<=15;j++)
{
LcdCommand(0x34);
LcdCommand(column+j); //起始行
LcdCommand(row); //起始列
// LcdCommand(0x30); //
//半字
LcdData(0); //输入显示数据(横向高8位数据)
LcdData(0xff); //输入显示数据(横向低8位数据)
}
}
else if(x<x2)
{
for(j=0;j<=15;j++)
{
LcdCommand(0x34);
LcdCommand(column+j); //起始行
LcdCommand(row); //起始列
// LcdCommand(0x30); //
//半字
LcdData(0xff); //输入显示数据(横向高8位数据)
LcdData(0xff); //输入显示数据(横向低8位数据)
}
x++;
}
else
{
for(j=0;j<=15;j++)
{
LcdCommand(0x34);
LcdCommand(column+j); //起始行
LcdCommand(row); //起始列
// LcdCommand(0x30); //
LcdData(0xff); //输入显示数据(横向高8位数据)
LcdData(0); //输入显示数据(横向低8位数据)
}
}
LcdCommand(0x36);
LcdCommand(0x30);
}
}*/
/***********************************
图形显示程序步骤:
1、写Y坐标
2、写X坐标
3、写D15-D8
4、写D7-D0
***********************************/
/*
void pic_show(p)//y,x,
unsigned char *p;//y,x,
{
unsigned char i,j;
LcdCommand(0x36);
for(i=0x80;i<0xa0;i++) //写上半屏
{
for(j=0x80;j<0x88;j++)
{
LcdCommand(i);
LcdCommand(j);
LcdData(*p);
LcdData(*(p+1));
p = p + 2;
}
}
for(i=0x80;i<0xa0;i++) //写下半屏
{
for(j=0x88;j<0x90;j++)
{
LcdCommand(i);
LcdCommand(j);
LcdData(*p);
LcdData(*(p+1));
p = p + 2;
}
}
LcdCommand(0x36);
LcdCommand(0x30);
} */
/*
void main()
{ struct TIME time;
struct DATE date;
unsigned char temp[10];
time.sec = 30;
time.min = 12;
time.hour =15;
date.day = 0x15;
date.mon = 0x10;
date.year =0x07;
date.week =0x01;
InitLcd();
AUXR=0x01; //在使用MOVX指令时访问外部RAM,如果AUXR = 0X01
//则在使用MOVX时访问片内自带RAM
init5045();
LED=0X86;
ClearGraph();
X5045WriteStatus(0x00);
init5045();
for(;;){
PrintStr(0,0,"X1227 芯片调试 ");
temp[0]=time.hour/10+0x30;
temp[1]=time.hour%10+0x30;
temp[2]=':';
temp[3]=time.min/10+0x30;
temp[4]=time.min%10+0x30;
temp[5]=':';
temp[6]=time.sec/10+0x30;
temp[7]=time.sec%10+0x30;
PrintStr(1,0,"时间: ");
PrintStr(1,3,temp);
PrintStr(2,0,"日期:");
PrintStr(3,0,"星期:");
watchdog();
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -