#include "absacc.h"
#include "math.h"
#include "ASCII816.h" //字符点阵库 0x20--0x7F
#include "HZTable.h" //汉字点阵库(自做)
#include "menu.h" //汉字点阵库(自做)
//set following data by user according to LCD
#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 stado{ sta=XBYTE[ComPort] &0x03} while(sta!=0x03)}
//数据自动读 状态检查
#define AutoRCheck() { unsigned char stado{ sta=XBYTE[ComPort] &0x04} while(sta!=0x04)}
//数据自动写 状态检查
#define AutoWCheck() { unsigned char stado{ 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=0i<16i++)
{
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=0i<16i++)
{
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=0i<35i++)
{
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24)//定位当前 *** 作位置
for(j=0j<5j++) 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=0i<column+14 )
{ byte=linehead[j]
if(byte <0x80) //字母
{
ShowChar(lin, i , byte)
i=i+1j=j+1
}
else // byte >= 0x80(汉字)
{
byte=byte &0x7f//最高位置0,即:减去0x8000
hzcode=byte*256 + linehead[j+1]//加低8位,组合成整型数地址
ShowHZ( lin,i,hzcode)
i=i+2j=j+2
}
}
}
/*-----------------------------------------------------------------------------------*/
//显示一屏汉字
//pageheadaddr:此屏汉字代码地址区首地址
void ShowPage(unsigned char lin,unsigned char column1,unsigned char pagehead[][14])
{
unsigned char i
for(i=0i<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=0i<16i++)
{
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=0column<ColumnCharcolumn++) 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=0i<ColumnWidthi++)
{
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24)//set address
for(j=0j<LineWidthj++)
{
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=x1x<=x2x++)
{
y=k*x+b
Pixel(x, y, Mode)
}
}
else
{
for(x=x2x<=x1x++)
{ 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=y1y<=y2y++)
{ x=k*y+b
Pixel( x , y,Mode )
}
}
else
{
for(y=y2y<=y1y++)
{ 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=0x00i<0x2000i++) 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()
}
你可以参考下面这段代码,同样是T6963C,只是显示区域是240*128, *** 作之前先将LCD复位一次,你对着资料将初始化的寄存器改改就可以了,另外电路和你的不同,所以读状态寄存器和写寄存器的方法不同,你的需要 *** 作P0,P1,P3口模拟读和写.其实T6963C可以直接和MCS51外部总线接口的,时序完全满足要求,下面的代码就是将/CE接P2.7,C/D接P2.0,直接用MOVX指令访问的.#define dis_comand XBYTE[0x7fff]//液晶 *** 作命令地址
#define dis_data XBYTE[0x7ffe]//液晶显示数据地址
#define discommand 1//定义液晶 *** 作的常量
#define disdata0
/*****************************************
*液晶初始设置参数
*****************************************/
void dis_set()
{
dis_write_dandc(0xb2,discommand)//先关闭自动写模式
dis_write_dandc(20,disdata)
dis_write_dandc(8,disdata)
dis_write_dandc(0x21,discommand)
dis_write_dandc(0,disdata)
dis_write_dandc(0,disdata)
dis_write_dandc(0x42,discommand)
dis_write_dandc(30,disdata)
dis_write_dandc(0,disdata)
dis_write_dandc(0x43,discommand)
dis_write_dandc(0x3,disdata)
dis_write_dandc(0,disdata)
dis_write_dandc(0x22,discommand)
dis_write_dandc(0xa1,discommand)
dis_write_dandc(0x81,discommand)
dis_write_dandc(0x98,discommand)//液晶初始化完成
}
/******************************************
*写数据到液晶包括命令
******************************************/
void dis_write_dandc(uchar x,bit y)
{
uchar i
lab1:
i=dis_comand
i=i&0x3
if (i!=3) goto lab1 //检查状态
if (y==discommand) dis_comand=x //命令
else dis_data=x //数据
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)