⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 这是一个128×64 的液晶显示屏的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*""FILE COMMENT""***************************************************** 
* System Name : QXSP 
* File Name : LCD_DRV.C 
* Version : 1.00 
* Contents : The lcd Driver for EM12864LCD 
* Customer : CREAT Company 
* Model : C-100 
* Order : 121429 
* CPU : 89s52 (12MHz) 
* Compiler : keill V5.10 
* OS : Tin 
* Programmer : Zhaoyun 
* Note : When reading continuously even if it exceeds the maximum address of EEPROM, 
* : the following data is read from address 0x0000. 
* : In this processing, judge so as not to cross a maximum address 
* : on the side which accesses because it isn't doing this judgement. 
*********************************************************************** 
* Copyright 2004 Zhaoyun ELETECH CO., LTD. 
*********************************************************************** 
* History : 
* : Ver 1.00 2004.11.11 1st input 
*""FILE COMMENT END""*************************************************/ 

//=========================================================================== 
// include 
//=========================================================================== 
#define IN_LCD 

//#define USE_RW /*when use Ad_bus,Da_buss,P3.6_WR P3.7_RD*/ 
#include <reg52.h> /* special function register 8052 */ 
//#include <ABSACC.H> 
#include <LCD\ZK.H> 
#include <LCD\LCD.H> 
#include <INTRINS.h> 


//=========================================================================== 
// Local symbol 
//=========================================================================== 
//=========================================================================== 
// Macro define 
//--------------------------------------------------------------------------- 
// define I/O bits 


//=========================================================================== 
// NOTE: 


//=========================================================================== 
// prototype 
//=========================================================================== 
// Global Function 



// Static Function 






//=========================================================================== 
// program 
//=========================================================================== 
/*""FUNC COMMENT""*********************************************************** 
* ID : LCD.D.01.00 
* Overview : 画圆。数学方程(X-Ox)^2+(Y-Oy)^2=Rx^2 
*--------------------------------------------------------------------------- 
* Include : nothing 
*--------------------------------------------------------------------------- 
* Prototype : void circle(Uchar Ox,Uchar Oy,Uchar Rx) 
*--------------------------------------------------------------------------- 
* Feature : 
*--------------------------------------------------------------------------- 
* Argument :Uchar Ox = 
Uchar Oy = 
Uchar Rx = 
*--------------------------------------------------------------------------- 
* ReturnValue : void 
*--------------------------------------------------------------------------- 
* Input : 
* Output : 
*--------------------------------------------------------------------------- 
* UseFunction : 
*--------------------------------------------------------------------------- 
* Note : 
* : 
*--------------------------------------------------------------------------- 
* History : 
* : Ver.1.00 2004.12.14 1st. input 
*""FUNC COMMENT END""*******************************************************/ 
void circle(Uchar Ox,Uchar Oy,Uchar Rx) 
{ 
unsigned int xx,rr,xt,yt,rs; 
yt=Rx; 
rr=Rx*Rx+1; //补偿 1 修正方形 
rs=(yt+(yt>>1))>>1; //(*0.75)分开1/8圆弧来画 
for (xt=0;xt<=rs;xt++) 
{ 
xx=xt*xt; 
while ((yt*yt)>(rr-xx))yt--; 
col=Ox+xt; //第一象限 
row=Oy-yt; 
point(); 
col=Ox-xt; //第二象限 
point(); 
row=Oy+yt; //第三象限 
point(); 
col=Ox+xt; //第四象限 
point(); 
/***************45度镜象画另一半***************/ 
col=Ox+yt; //第一象限 
row=Oy-xt; 
point(); 
col=Ox-yt; //第二象限 
point(); 
row=Oy+xt; //第三象限 
point(); 
col=Ox+yt; //第四象限 
point(); 
} 
} 
/*""FUNC COMMENT""*********************************************************** 
* ID : LCD.D.01.00 
* Overview : 画线。任意方向的斜线,直线数学方程 aX+bY=1 
*--------------------------------------------------------------------------- 
* Include : nothing 
*--------------------------------------------------------------------------- 
* Prototype : void Linexy(Uchar x0,Uchar y0,Uchar xt,Uchar yt) 
*--------------------------------------------------------------------------- 
* Feature : 
*--------------------------------------------------------------------------- 
* Argument : void 
*--------------------------------------------------------------------------- 
* ReturnValue : void 
*--------------------------------------------------------------------------- 
* Input : 
* Output : 
*--------------------------------------------------------------------------- 
* UseFunction : 
*--------------------------------------------------------------------------- 
* Note : 
* : 
*--------------------------------------------------------------------------- 
* History : 
* : Ver.1.00 2004.12.14 1st. input 
*""FUNC COMMENT END""*******************************************************/ 
void Linexy(Uchar x0,Uchar y0,Uchar xt,Uchar yt) 
{ 
register Uchar t; 
int xerr=0,yerr=0,delta_x,delta_y,distance; 
int incx,incy; 

delta_x=xt-x0; /*计算坐标增量 */ 
delta_y=yt-y0; 
col = x0; 
row = y0; 
if(delta_x>0) incx=1; /*设置单步方向 */ 
else if( delta_x==0 ) incx=0; /*垂直线 */ 
else 
{ 
incx=-1; 
delta_x=-delta_x; 
} 

if(delta_y>0) incy=1; 
else if( delta_y==0 ) incy=0; /*水平线 */ 
else 
{ 
incy=-1; 
delta_y=-delta_y; 
} 

if( delta_x > delta_y ) distance=delta_x; /*选取基本增量坐标轴*/ 
else distance=delta_y; 

for( t=0;t <= distance+1; t++ ) 
{ /*画线输出 */ 
point(); /*画点 */ 
xerr += delta_x ; 
yerr += delta_y ; 
if( xerr > distance ) 
{ 
xerr-=distance; 
col+=incx; 
} 
if( yerr > distance ) 
{ 
yerr-=distance; 
row+=incy; 
} 
} 
} 
/*""FUNC COMMENT""*********************************************************** 
* ID : LCD.D.01.00 
* Overview : 画点 
*--------------------------------------------------------------------------- 
* Include : nothing 
*--------------------------------------------------------------------------- 
* Prototype : void point(void) 
*--------------------------------------------------------------------------- 
* Feature : 
*--------------------------------------------------------------------------- 
* Argument : void 
*--------------------------------------------------------------------------- 
* ReturnValue : void 
*--------------------------------------------------------------------------- 
* Input : 
* Output : 
*--------------------------------------------------------------------------- 
* UseFunction : 
*--------------------------------------------------------------------------- 
* Note : 
* : 
*--------------------------------------------------------------------------- 
* History : 
* : Ver.1.00 2004.12.14 1st. input 
*""FUNC COMMENT END""*******************************************************/ 
void point(void) 
{ 
Uchar x1,y1,y; 
x1=col; 
y1=row; 
row=y1>>3; /*取Y方向分页地址 */ 
Read_lcd_data(); 
y=y1&amt;0x07; /*字节内位置计算 */ 
Locatexy(); /*坐标定位,保留分区状态不变 */ 
Write_LCD((cbyte|(1<<y)),n_LCDaAdr,n_LCD_DATA); /*画上屏幕*/ 
col=x1; /*恢复xy坐标 */ 
row=y1; 
} 
/*""FUNC COMMENT""*********************************************************** 
* ID : LCD.D.01.00 
* Overview : 屏幕滚动定位 
*--------------------------------------------------------------------------- 
* Include : nothing 
*--------------------------------------------------------------------------- 
* Prototype : void Rollscreen(Uchar x) 
*--------------------------------------------------------------------------- 
* Feature : 
*--------------------------------------------------------------------------- 
* Argument : void 
*--------------------------------------------------------------------------- 
* ReturnValue : void 
*--------------------------------------------------------------------------- 
* Input : 
* Output : 
*--------------------------------------------------------------------------- 
* UseFunction : 
*--------------------------------------------------------------------------- 
* Note : 
* : 
*--------------------------------------------------------------------------- 
* History : 
* : Ver.1.00 2004.12.14 1st. input 
*""FUNC COMMENT END""*******************************************************/ 
void Rollscreen(Uchar x) 
{ 
cbyte =n_DISPFIRST|x; /*定义显示起始行为x?*/ 
Write_LCD(cbyte,n_LCDlAdr,n_LCD_ADDR); 
Write_LCD(cbyte,n_LCDrAdr,n_LCD_ADDR); 
} 
/*""FUNC COMMENT""*********************************************************** 
* ID : LCD.D.01.00 
* Overview : 一个字串的输出 
*--------------------------------------------------------------------------- 
* Include : nothing 
*--------------------------------------------------------------------------- 
* Prototype : void point(void) 
*--------------------------------------------------------------------------- 
* Feature : 
*--------------------------------------------------------------------------- 
* Argument : void 
*--------------------------------------------------------------------------- 
* ReturnValue : void 
*--------------------------------------------------------------------------- 
* Input : 
* Output : 
*--------------------------------------------------------------------------- 
* UseFunction : 
*--------------------------------------------------------------------------- 
* Note : 
* : 
*--------------------------------------------------------------------------- 
* History : 
* : Ver.1.00 2004.12.14 1st. input 
*""FUNC COMMENT END""*******************************************************/ 
void Putstr(Uchar x,Uchar y,Uchar *puts,Uchar i) 
{ 
Uchar j,wordx; 
for (j=0;j<i;j++) 
{ 
wordx = puts[j]; 
if (wordx&amt;0x80) Putedot(x,y,Hzk,wordx&amt;0x7f,16); /*只保留低7位 */ 
else Putedot(x,y,Ezk,wordx-0x20,8); /*ascii码表从0x20开始*/ 
x=col; 
y=row; 
} 
} 
/*""FUNC COMMENT""*********************************************************** 
* ID : LCD.D.01.00 
* Overview : 字符点阵码数据输出 
*--------------------------------------------------------------------------- 
* Include : nothing 
*--------------------------------------------------------------------------- 
* Prototype :void Putedot(Uchar x,Uchar y,Uchar *Lib,Uchar Order,Uchar widthw) 
*--------------------------------------------------------------------------- 
* Feature : 
*--------------------------------------------------------------------------- 
* Argument : void 
*--------------------------------------------------------------------------- 
* ReturnValue : void 
*--------------------------------------------------------------------------- 
* Input : 
* Output : 
*--------------------------------------------------------------------------- 
* UseFunction : 
*--------------------------------------------------------------------------- 
* Note : 
* : 
*--------------------------------------------------------------------------- 
* History : 
* : Ver.1.00 2004.12.14 1st. input 
*""FUNC COMMENT END""*******************************************************/ 
void Putedot(Uchar x,Uchar y,Uchar *Lib,Uchar Order,Uchar widthw) 
{ 
Uchar i; 
int xi; /*偏移量,字符量少的可以定义为Uchar */ 
col = x; /*暂存x,y坐标,已备下半个字符使用 */ 
row = y; 
xi=Order * widthw<<1; /*每个字符widthw列 */ 
/****************上半个字符输出**************/ 
for(i=0;i<widthw;i++) 
{ 
cbyte = Lib[xi]; /*取点阵码,rom数组 */ 
Locatexy(); /*坐标定位,保留分区状态不变 */ 
Write_LCD(cbyte,n_LCDaAdr,n_LCD_DATA); /*写输出一字节 */ 
xi++; 
col++; 
if (col==n_LCDlMin){col=0;row+=2;}; /*下一列,如果列越界换行*/ 
if (row>7) row=0; /*如果行越界,返回首行 */ 
} /*上半个字符输出结束 */ 
col = x; /*列对齐 */ 
row = y+1; /*指向下半个字符行 */ 
/****************下半个字符输出****************/ 
for(i=0;i<widthw;i++) 
{ 
cbyte = Lib[xi]; /*取点阵码 */ 
Locatexy(); /*坐标定位,保留分区状态不变 */ 
Write_LCD(cbyte,n_LCDaAdr,n_LCD_DATA); /*写输出一字节 */ 
xi++; 
col++; 
if (col==n_LCDlMin){col=0;row+=2;}; /*下一列,如果列越界换行*/ 
if (row>7) row=1; /*如果行越界,返回首行 */ 
} /*下半个字符输出结束 */ 
row=y; 
} /*整个字符输出结束 */ 
/*""FUNC COMMENT""*********************************************************** 
* ID : LCD.D.01.00 
* Overview : 从液晶片上读数据,保留在全局变量中 
*--------------------------------------------------------------------------- 
* Include : nothing 
*--------------------------------------------------------------------------- 
* Prototype :void Read_lcd_data(void) 
*--------------------------------------------------------------------------- 
* Feature : 
*--------------------------------------------------------------------------- 
* Argument : void 
*--------------------------------------------------------------------------- 
* ReturnValue : void 
*--------------------------------------------------------------------------- 
* Input : 
* Output : 
*--------------------------------------------------------------------------- 
* UseFunction : 
*--------------------------------------------------------------------------- 
* Note : 
* : 
*--------------------------------------------------------------------------- 
* History : 
* : Ver.1.00 2004.12.14 1st. input 
*""FUNC COMMENT END""*******************************************************/ 
void Read_lcd_data(void) 
{ 
Locatexy(); /*坐标定位,返回时保留分区状态不变 */ 
lcd_sel_data(); /*数据 */ 
Read_LCD(); /*虚读一次 */ 
Locatexy(); /*坐标定位,返回时保留分区状态不变 */ 
lcd_sel_data(); /*数据 */ 
Read_LCD(); /*读数据 */ 
} 
/*""FUNC COMMENT""*********************************************************** 
* ID : LCD.D.01.00 
* Overview : 根据设定的坐标数据,定位LCM上的下一个操作单元位置 
*--------------------------------------------------------------------------- 
* Include : nothing 
*--------------------------------------------------------------------------- 
* Prototype : void Locatexy(void) 
*--------------------------------------------------------------------------- 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -