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

📄 lcd_part_12864j.c

📁 C51单片机对st7920并行方式驱动128*64液晶驱动,实现任意位置坐标位置写入图片;自动画线;自动画圆;任意位置反显等功能。
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
Copyright 2009 
All rights reserved.

文件名	: .c
模块名称:st7920 并行方式驱动128*64液晶驱动
功能概要:st7920显示驱动

取代版本:0.0.2
修改人	:lujian
完成日期:2009.3.16
升级说明:create
CPU: stc89c58   主频:11.0592M
液晶型号:       生产厂家:        驱动芯片:st7920
******************************************************************************/

#include <AT89X52.H>
#include <string.h>

typedef unsigned char  uchar;         	//无符号8位数
typedef signed   char  schar;         	//有符号8位数
typedef unsigned int   uint;        	//无符号16位数
typedef signed   int   sint;        	//有符号16位数
typedef unsigned long  ulong;        	//无符号32位数
typedef signed   long  slong;        	//有符号32位数
typedef float          FP32;          	//单精度浮点数
typedef double         FP64;          	//双精度浮点数

#define FALSE	0
#define TRUE   	1

//初始化指令
#define FUN_MODE		0x30			//工作模式:8位基本指令集(ASCII工作方式)
#define DISPLAY_OFF		0x34			//显示关(工作模式:8位扩展指令集)
#define DISPLAY_ON		0x36			//显示开(工作模式:8位扩展指令集)

#define comm  0
#define dat   1


sbit E    = P2^0;     					//时钟端(从高变低时数据输入)
sbit RW   = P2^7;    					//数据读(H)/写(L)选择
sbit RS   = P2^6;      					//数据(H)/状态(L)寄存器选择

/*------------------------------------------------
B Bit Registers
------------------------------------------------*/
sbit B_0 = B^0;
sbit B_1 = B^1;
sbit B_2 = B^2;
sbit B_3 = B^3;
sbit B_4 = B^4;
sbit B_5 = B^5;
sbit B_6 = B^6;
sbit B_7 = B^7;

sbit ACC_7 = ACC^7;

bit lcd_point(uchar x,uchar y);
bit lcd_display(uchar Byte[], uchar x, uchar y, uchar xrange, uchar yrange);
void wr_lcd(bit dat_comm,unsigned char content);
void XYadr(unsigned char x,unsigned char y);
unsigned char rd_lcd(void);

/******************************************************************************************
* 函数名称    :lcd_line 
* 功能描述    :画线函数
* 参数        :  参数名称:	输入/输出   	类型		  描述
* 					  x1		  input			uchar   第一点行位置数据(0-127)
*					  y1		  input			uchar   第一点列位置数据(0-63)
* 					  x2		  input		    uchar   第二点位置数据(0-127)
*					  y2		  input			uchar   第二点位置数据(0-63)
* 返回值      :
* 作者        :lujian
* 创建日期    :2003-12-19
* 全局变量    :
* 全局静态变量:
* 局部静态变量:
*----------------------------------------修改历史------------------------------------------
* 当前版本    :0.0.2 			 修改人:lujian                  修改日期:2009-3-16
* 修改说明    :
******************************************************************************************/

bit lcd_line(uchar x1, uchar y1, uchar x2, uchar y2)
{
	FP32 a = 0;
 	schar b = 0,c = 0,t = 0,e = 0,f = 0;

	if(	x1 < 0 || x1 > 127 ||
		x2 < 0 || x2 > 127 ||	
		y1 < 0 || y1 > 63  ||
		y2 < 0 || y2 > 63)
	{
		return FALSE;
	}
	else if(x1 == x2)
	{
		if(y1 > y2)
		{
			for(b = y1 - y2; b >= 0; b--)
			lcd_point(x1, y2+b);
		}
		else
		{
			for(b = y2-y1; b >= 0; b--)
			lcd_point(x1, y1+b);
		}
	}
	else if(y1 == y2)
	{
		if(x1 > x2)
		{
			for(b = x1-x2; b >= 0; b--)
			lcd_point(x2+b, y1);
		}
		else
		{
			for(b = x2-x1; b >= 0; b--)
			lcd_point(x1+b, y1);
		}
	}
	else
	{
		if(x1 < x2)
		{
			t = x1;
			x1 = x2;
			x2 = t;
			t = y1;
			y1 = y2;
			y2 = t;
		}
		if(y1 > y2)
		{
			e = x1-x2;
			f = y1-y2;
			a = (float)e/(float)f;
			for(b = f; b >= 0; b--)
			{
				c = b * a;
				lcd_point(x2+c, y2+b);
			}
		}
		else
		{
			e = y2-y1;
			f = x1-x2;
			a = (float)e/(float)f;
			for(b = f; b >= 0; b--)
			{
				c = a * b;
				lcd_point(b+x2, y2-c);
			}
		}
	}
	return TRUE;
}

/******************************************************************************************
* 函数名称    :lcd_Point 
* 功能描述    :画点函数
* 参数        :  参数名称:	输入/输出   	类型		  描述
* 					  x		      input			uchar   第一点行位置数据(0-127)
*					  y		      input			uchar   第一点列位置数据(0-63)
* 返回值      :正确:1; 错误:0,x或y值超范围
* 作者        :lujian
* 创建日期    :2003-12-19
* 全局变量    :
* 全局静态变量:
* 局部静态变量:
*----------------------------------------修改历史------------------------------------------
* 当前版本    :0.0.2 			 修改人:lujian                  修改日期:2009-3-16
* 修改说明    :
******************************************************************************************/

bit lcd_point(uchar x,uchar y)
{
	uchar a, d1, d2;
	uchar code Dot1[16] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,
					0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
	uchar code Dot2[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
					0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};

	if(0 <= x && x <= 127)
	{
		a = x & 0x0f;
		x = x >> 4;
	}
	else return FALSE;

	if(y > 63)
	{
		return FALSE;
	}

	wr_lcd(comm,DISPLAY_OFF);
	XYadr(x,y);			//x(0-7),y(0-63)

	rd_lcd();
	d1 = rd_lcd();
	d2 = rd_lcd();
	d1 = d1 ^ Dot1[a];
	d2 = d2 ^ Dot2[a];

	XYadr(x,y);
	wr_lcd(dat,d1);
	wr_lcd(dat,d2);
	wr_lcd (comm,DISPLAY_ON);
	return TRUE;
}

/******************************************************************************************
* 函数名称    :lcd_display 
* 功能描述    :图像填入函数支持图像最大分辨率255*255(x,y都为0时)
*				LCD实际显示最大128*64,后面数据消隐
* 参数        :  参数名称:	输入/输出   	类型		        描述
*					Byte[]		  input			uchar		数据组(max 65535 byte)
* 					  x		      input			uchar    	起始行位置数据(0-127)
*					  y		      input			uchar    	起始列位置数据(0-63)
* 					xrange		  input			uchar    	图像行分辨率(1-255)
*					yrange		  input			uchar    	图像列分辨率(1-255)
* 返回值      :正确:1; 错误:0,x或y值超范围
* 作者        :lujian
* 创建日期    :2003-12-19
* 全局变量    :
* 全局静态变量:
* 局部静态变量:dstate, start, end,  xstd, xetd, xedl, tlen, ovxend, xend, yend;
*----------------------------------------修改历史------------------------------------------
* 当前版本    :0.0.2 			 修改人:lujian                  修改日期:2009-3-16
* 修改说明    :
******************************************************************************************/

bit lcd_display(uchar Byte[], uchar x, uchar y, uchar xrange, uchar yrange)
{
	uchar dstate, start, end,  xstd, xetd, xedl, tlen, ovxend;
	uint xend, yend;
	uchar xsdl, dlen,  gcount, g, g1, temp1, yt, sd1, sd2, ed1, ed2;
	uint bcount;
	bit error = 1;

//-------------------------------------------------------
// Boundary detection

	yend = y + yrange;
	xend = x + xrange;
	if(xend > 0x00ff || y > 0x00ff || x > 127 || y > 63)
		return FALSE;

	wr_lcd(comm,DISPLAY_OFF);		//Entry mode set

	if(xend > 128)
	{
		ovxend = xend;
		xrange = 128 - x;
		xend = 128; 
		error = 0;
	}

	if(yend > 64)
	{
		yrange = 64 - y;
		yend = 64; 
		error = 0;
	}
	
	start = (x /16)*16;
	xstd = x % 16;			 		//开始位置LCD原始数据的位数
	xetd = xend % 16;
	if(xetd!=0)
		xetd = 16 - xetd;			//结尾位置LCD原始数据的位数
	end = xend + xetd;
	tlen = end - start;

	yt = 0;
	bcount = 0;
//-------------------------------------------------------

//main program

//-------------------------------------------------------
// preprocessing
	for(yt = y;yt < yend; yt++)
	{	
		dlen = xrange;
		xsdl = xstd;
		xedl = xetd;

		if(xsdl != 0)				//If the start data equal to zero, do not need to read data. 
		{
			temp1 = x /16;			//Reading the start data form lcd.
			XYadr(temp1,yt);
			rd_lcd();
			sd1 = rd_lcd();
			sd2 = rd_lcd();
		}

		if(xedl != 0)				//If the end of data's number equal to zero, do not need to read data.
		{
			temp1 = xend /16;		//Reading the end of data form lcd
			XYadr(temp1,yt);
			rd_lcd();
			ed1 = rd_lcd();
			ed2 = rd_lcd();
		}

		temp1 = x /16;
		XYadr(temp1,yt);
		dstate = 0;
		g1 = 7;
		g = 0;
		gcount = 0;
//-------------------------------------------------------

//  writing lcd's data program

//-------------------------------------------------------
//  set data into the launcher
		while(tlen > g)
		{
			if(gcount == 0)			//data empty!!装子弹!!
			{
				switch (dstate)

⌨️ 快捷键说明

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