#include "absacc.h"
#include "math.h"
#include "ASCII816.h" //标准ASCII库
#include "HZTable.h" //汉字点阵库(自做)
#include "menu.h" //菜单库(自做)
#define ComPort 0xB101
#define DataPort 0xB000
#define GraphAddr 0x0000 //head of graph
//以8*8字符计算,显示屏横向、纵向可以显示的字符个数
//以240*128为例:
#define LineChar 30 //一行16个字符(8*8)
#define ColumnChar 16 //总共16列
//指令,数据 读写状态检查
#define RWCheck() { unsigned char sta; do{ sta=XBYTE[ComPort] & 0x03; } while(sta!=0x03); }
//数据自动读 状态检查
#define AutoRCheck() { unsigned char sta; do{ sta=XBYTE[ComPort] & 0x04; } while(sta!=0x04); }
//数据自动写 状态检查
#define AutoWCheck() { unsigned char sta; do{ sta=XBYTE[ComPort] & 0x08; } while(sta!=0x08); }
/*------输入/出函数,与T6963通讯------------------------------------------------*/
/*------------------------------------------------------------------------*/
// 向数据口发Data
#define OutPortData(dat ) { RWCheck(); XBYTE[DataPort]=dat; }
//写有 1 个参数命令
#define OutPortCom1(command) { RWCheck(); XBYTE[ComPort]= command; }
//写有 2 个参数命令
#define OutPortCom2(dat, command) { OutPortData(dat); OutPortCom1(command); }
//写有 3 个参数命令
#define OutPortCom3(data1, data2, command) { OutPortData(data1); OutPortData(data2); OutPortCom1(command);}
unsigned char InPortData() { RWCheck(); return(XBYTE[DataPort]); }
/*-----------------------------------------------------------------------------------*/
//显示8*16字符
//lin:行(0-7), column: 列(0-15)
//ch:字符代码(标准ASCII码)
void ShowChar(unsigned char lin,unsigned char column,unsigned char ch)
{
unsigned char i;
unsigned char dat;
unsigned int StartAddr;
StartAddr=lin*LineChar +column; //定位起始行
for(i=0;i<16;i++)
{
dat=ASCII816[ ch-0x20 ][i];
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //set address
OutPortCom2( dat, 0xc4);
StartAddr=StartAddr + LineChar;
}
}
/*----------------------------------------------------------------------------------------------*/
//显示一个汉字(16*16点阵)
//lin:行(0-7), column: 列(0-7)
//hzcode: 汉字代码(自定义的)
void ShowHZ(unsigned char lin,unsigned char column,unsigned int hzcode)
{
unsigned char i;
unsigned int StartAddr;
StartAddr=lin*LineChar + column; //定位起始行
for(i=0;i<16;i++)
{
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24);
OutPortCom2( HZTable[hzcode][i*2], 0xc0); //左半部 地址加一
OutPortCom2( HZTable[hzcode][i*2+1], 0xc4); //右半部 字模地址加一
StartAddr=StartAddr + LineChar;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
//显示一个汉字(16*16点阵)
//lin:行(0-7), column: 列(0-7)
//hzcode: 汉字代码(自定义的)
void ShowHZD(unsigned char lin,unsigned char column,unsigned int hzcode)
{
unsigned char i,j;
unsigned int StartAddr;
StartAddr=lin*LineChar*16 +column; //定位起始行
for(i=0;i<35;i++)
{
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //定位当前操作位置
for(j=0;j<5;j++) OutPortCom2( HZTable[hzcode][i*5+j], 0xc0); //显示当前一行
StartAddr=StartAddr + LineChar;
}
}
////////////////////////////////////////////////////////////////////////////////////////////
/*-----------------------------------------------------------------------------------*/
//显示一行字符串(汉字,字母混排,一行16字节)
//lin:行
//lineheadaddr: 此行汉字代码区首地址
void ShowLine(unsigned char lin,unsigned char column,unsigned char linehead[])
{
unsigned char i,j;
unsigned char byte;
unsigned int hzcode;
for( i= column,j=0; i< column+14 ; )
{ byte=linehead[j];
if(byte < 0x80) //字母
{
ShowChar(lin, i , byte);
i=i+1;j=j+1;
}
else // byte >= 0x80(汉字)
{
byte=byte & 0x7f; //最高位置0,即:减去0x8000
hzcode=byte*256 + linehead[j+1]; //加低8位,组合成整型数地址
ShowHZ( lin,i,hzcode);
i=i+2;j=j+2;
}
}
}
/*-----------------------------------------------------------------------------------*/
//显示一屏汉字
//pageheadaddr:此屏汉字代码地址区首地址
void ShowPage(unsigned char lin,unsigned char column1,unsigned char pagehead[][14])
{
unsigned char i;
for(i=0;i< 4 ;i++)
ShowLine((lin+i*20),column1,pagehead[i]); //1行8个汉字,16字节
}
/*----------------------------------------------------------------------------------------------------*/
//反显一个字符
//lin:行(0-7), column: 列(0-15)
void ReverseShowChar(unsigned char lin,unsigned char column)
{
unsigned char i;
unsigned char dat;
unsigned int StartAddr;
StartAddr=lin*LineChar +column; //定位起始行
for(i=0;i<16;i++)
{
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //set address
OutPortCom1( 0xc5 ); //数据一次读,地址不变
dat=InPortData(); //读入数据
dat=~dat; //取反
OutPortCom2( dat, 0xc4); //送回
StartAddr=StartAddr+ LineChar;
}
}
/*----------------------------------------------------------------------------------------------------*/
//反显一个汉字
//lin:行(0-7), column: 列(0-15)
void ReverseShowHZ(unsigned char lin,unsigned char column)
{
ReverseShowChar(lin,column);
ReverseShowChar(lin,column+1);
}
/*----------------------------------------------------------------------------------------------------*/
//反显一行汉字
//lin:行(0-7)
void ReverseShowLine(unsigned char lin)
{
unsigned char column;
for(column=0; column< ColumnChar; column++) ReverseShowChar(lin,column);
}
//////////////////////////////////////////////////////////////////////////////////////
void ShowPicture(unsigned char Startline,unsigned char Startcolumn,unsigned char LineWidth,unsigned char ColumnWidth,unsigned int address)
{
unsigned char i,j;
unsigned int StartAddr;
StartAddr=Startline*LineChar + Startcolumn; //定位起始位置
for(i=0;i<columnwidth;i++)
{
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //set address
for(j=0;j<linewidth;j++)
{
OutPortCom2( CBYTE[address + i*LineWidth+ j ], 0xc0);
}
StartAddr=StartAddr + LineChar;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//图形函数,用于描点画图
//---------------------------------------------------------------------------
//在指定位置显示一个点
//如果显示屏超过了256*256,请修改这个函数 PointX,PointY的类型
//Mode 1:显示 0:清除该点
Pixel(unsigned char PointX,unsigned char PointY, bit Mode)
{
unsigned int StartAddr=0;
unsigned char dat;
StartAddr=PointX*LineChar + PointY/8;
dat=0xf0+7-PointY%8;
if(Mode) dat=dat|0x08;
OutPortCom3( (unsigned char)(StartAddr),(unsigned char)(StartAddr>>8),0x24 ); //设置该点所在单元地址
OutPortCom1(dat);
}
//-------------------------------------------------------------------------------
//划线函数
void Line( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bit Mode)
{
unsigned char x,y;
double k,b;
if( abs(y1-y2) <= abs(x1-x2) ) // |k|<=1
{
k=(float)(y2-y1) / (float)(x2-x1) ;
b=y1-k*x1;
if( x1 <= x2 )
{
for(x=x1;x<=x2;x++)
{
y=k*x+b;
Pixel(x, y, Mode);
}
}
else
{
for(x=x2;x<=x1;x++)
{ y=k*x+b;
Pixel(x, y, Mode);
}
}
}
else // abs(y1-y2) > abs(x1-x2) |K|>1
{
k=(float)(x2-x1) / (float)(y2-y1) ;
b=x1-k*y1;
if( y1 <= y2 )
{
for(y=y1;y<=y2;y++)
{ x=k*y+b;
Pixel( x , y,Mode );
}
}
else
{
for(y=y2;y<=y1;y++)
{ x=k*y+b;
Pixel( x , y,Mode );
}
}
}
}
/*---------------------------------------------------------------------------------------------------*/
void ClearScreen()
{
unsigned int i;
///////// 清显示 RAM 区 0000h--2000h (8k)
OutPortCom3(0x00,0x00,0x24); //设置指针地址0000H
OutPortCom1(0xb0); //设置自动写状态
for(i=0x00;i<0x2000;i++) OutPortData(0x00); // data=0;
OutPortCom1(0xb2); // 自动写结束
}
//初始化LCD
//需要手动设置
void InitLCD()
{
OutPortCom3( 0x00,0x00,0x42 ); //设置图形显示区域首地址GraphAddr
OutPortCom3( 30,0x00,0x43 ); //设置图形显示区域宽度 : LineChar
// OutPortCom3( 0x00,0x00,0x42 ); //设置图形显示区域首地址GraphAddr
// OutPortCom3( 0x10,0x00,0x43); //设置图形显示区域宽度:10H
OutPortCom1(0xa7); //设置光标形状 cursor size 8x8
OutPortCom1(0x80); //设置显示方式: CGROM方式 文本图形 "或"
OutPortCom1(0x98); //设置显示开关: 1001 1100 图形
ClearScreen();
}