📄 lcd_ctrl.c
字号:
#include <at89x52.h>
#include <absacc.h>
#include <intrins.h>
#include <math.h>
#include "lcd_ctrl.h"
#include "mcu_main.h"
//xdata unsigned char WCMD _at_ (CMDADDR);//
//xdata unsigned char WDAT _at_ (DATADDR);
xdata unsigned char Op_Port0 _at_ (LcdPort0);//
xdata unsigned char Op_Port1 _at_ (LcdPort1);//
xdata unsigned char Op_Port2 _at_ (LcdPort2);//
xdata unsigned char Op_Port3 _at_ (LcdPort3);//
//////////////////////////////////////////////////////////////////////////
void SetParameter(unsigned char CtrReg)
{
unsigned char ch;
Op_Port1 =CtrReg | 0x44;
_nop_();
ch=Op_Port1;
}
///////////////////////////////////////////////////////
//画点的函数----坐标和颜色
//Row参数是行(0--234),x参数是列(0--319,479)
void DrawDot(unsigned int X_coor,unsigned int Y_coor,unsigned char color)
{
Op_Port2 =Y_coor>>8;
Op_Port2 =Y_coor;
Op_Port1 =X_coor>>8;
Op_Port1 =X_coor;
Op_Port0 =color;
}
/////////////////////////////////////////////////////////////////////////
////////////////////////clear LCD ///////////////////////////////////////
////////////////////////dual scan////////////////////////////////////////
void ClearLcd(unsigned char color)
{
unsigned int i;
unsigned char j;
IE &= 0x67; //禁止中断
// Color_CSJ=0;
for(j=0;j<LcdHeight;j++)
{
Op_Port2 = 0x00;
Op_Port2 = j;
Op_Port1 =0x00;
Op_Port1 =0x00;
for(i=0;i<LcdWidth;i++)
{
// while (LCD_BUSY);
Op_Port0 = color;
_nop_();
}
Op_Port2 =0x01;
Op_Port2 = j;
Op_Port1 =0x00;
Op_Port1 =0x00;
for(i=0;i<LcdWidth;i++)
{
// while (LCD_BUSY);
Op_Port0 = color;
_nop_();
}
}
// Color_CSJ=1;
IE |= 0x98; //打开中断
}
////////////////////////////////////////////////////////////////////////
/*画线。任意方向的斜线,直线数学方程 aX+bY=1 */
//////////////////////////////////////////////////////
//画线的函数 入口参数---线的起点和终点----color
void DrawLine(unsigned int xsta,unsigned int ysta,unsigned int xend,
unsigned int yend, unsigned char color)
{
int Xerr=0;
int Yerr=0;
int DeltaX;
int DeltaY;
int Distance;
int IncY;
int IncX;
unsigned int X; //列号,列间距
unsigned int Y; //两行之间的间距
unsigned int i;
DeltaX=xend-xsta; /*计算坐标增量 */
DeltaY=yend-ysta;//行间距
X=xsta; //把地址变化方式设为列方向增加
Y=ysta;
if(DeltaX > 0) //
{
IncX = 1; /*设置单步方向 */
}
else if (DeltaX == 0)
{
IncX = 0; /*垂直线 */
}
else
{
IncX=-1;
DeltaX=-DeltaX;
}
if(DeltaY > 0)
{
IncY = 1; /*设置单步方向 */
}
else if (DeltaY == 0)
{
IncY = 0; /*水平线 */
}
else
{
IncY=-1;
DeltaY=-DeltaY;
}
if(DeltaX > DeltaY)
{
Distance = DeltaX;
}
else
{
Distance = DeltaY;
}
for (i=0;i<Distance + 1;i++)
{ /*画线输出 */
DrawDot(X,Y,color);
Xerr += DeltaX;
Yerr += DeltaY;
if(Xerr > Distance)
{
Xerr -= Distance;
X += IncX; //
}
if(Yerr > Distance)
{
Yerr -= Distance;
Y += IncY; //
}
}
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//在一个320X240的平面上画圆
void circle(int x,y,r,char color)
{
/*
float xdata angle;
int xdata CoodX,CoodY;
*/
float angle;
int CoodX,CoodY;
for(angle=0;angle<6.28;angle+=0.01)
{
//drawPixel(x+r*cos(angle),y+r*sin(angle));
CoodY=y+r*cos(angle);//x 是列坐标,Y是行坐标
CoodX=x+r*sin(angle);
DrawDot(CoodY,CoodX,color);
// DrawInitail(CoodY,CoodX);
// WriteData(color);
}
}
/////////////////////////////////////////////////////////////////////
//用对称的方式画圆,速度比较快
/*画圆。数学方程(X-Ox)^2+(Y-Oy)^2=Rx^2 */
void circle1(unsigned int Ox,Oy, unsigned char Rx,color)
{
// unsigned int xdata xx,rr,xt,yt,rs,row,col;
unsigned int xx,rr,xt,yt,rs,row,col;
yt=Rx;
rr=Rx*Rx+1; //补偿 1 修正方形
rs=(yt+(yt>>1))>>1; //(*0.75)分开1/8圆弧来画
//SetReg(0x00,0x0c);
for (xt=0;xt<=rs;xt++)
{
xx=xt*xt;
while ((yt*yt)>(rr-xx)) yt--;
row=Ox+xt; //第一象限
col=Oy-yt;
//W_DOT(row,col);
DrawDot(row,col,color);
row=Ox-xt; //第二象限
//W_DOT(row,col);
DrawDot(row,col,color);
col=Oy+yt; //第三象限
//W_DOT(row,col);
DrawDot(row,col,color);
row=Ox+xt; //第四象限
//W_DOT(row,col);
DrawDot(row,col,color);
/***************45度镜象画另一半***************/
row=Ox+yt; //第一象限
col=Oy-xt;
//W_DOT(row,col);
DrawDot(row,col,color);
row=Ox-yt; //第二象限
//W_DOT(row,col);
DrawDot(row,col,color);
col=Oy+xt; //第三象限
//W_DOT(row,col);
DrawDot(row,col,color);
row=Ox+yt; //第四象限
//W_DOT(row,col);
DrawDot(row,col,color);
}
}
/////////////////////////////////////////////////////
/////disp_char/////////////////////////////////////
void disp_char(unsigned int Ox,Oy,unsigned char CharX,CharY, const unsigned char CharData[] ,unsigned char color)
{
unsigned char CharByte;
unsigned int Xindex,Yindex;
unsigned char i,temp_char;
for (Yindex=0;Yindex<CharY;Yindex++)
{
for(Xindex=0;Xindex<CharX;Xindex++)
{
CharByte = CharData[Yindex*Xindex + Xindex]; //
temp_char = 0x01;
for(i=0;i++;i<8)
{
if(CharByte&temp_char)
DrawDot(Ox,Oy,color);
temp_char *=2;
Ox++;
}
}
Ox -= CharX*8; //?
Oy++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -