/*************************************************************************
文件名:T6963C-240128BUS.C(T6963C-240×128图形液晶显示器驱动程序_总线方式)
(240*128每行宽30字节 ),控制芯片:T6963C ,总线接口,/CS:HC138译码:3×××H,
C/D:P2.0,/RD:/RD,/WR:/WR
取模方式为:先上下,后左右
V1.1
MCU时钟频率:12MHz
/*************************************************************************/
#include
#include
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define lcmcom XBYTE[0x3fff] /*T6963C写命令口地址,读数据口地址*/
#define lcmdata XBYTE[0x3eff] /*T6963C写数据口地址*/
uchar code ctable[]; /*汉字库必须先声明,以便字库可以安排在程序的任意位置*/
/***********************************************************
函数功能:判忙,空闲则返回
参数说明:flag为读取的状态位,flag中相应位为需要判断的位
/***********************************************************/
void busy_lcm(uchar flag)
{
uchar i;
i=flag;
while(i==lcmcom&flag);
}
/*******************************************************************
函数功能:写数据、写指令
参数说明:数据(data1,data2)、指令(lcmcom)
判别(count),count=1,只写指令(com);
count="2",写数据1和指令(data1,lcmcom);
count="3",写数据1数据2和指令(data1,data2,lcmcom);
/*******************************************************************/
void write_lcm(uchar count,uchar com,uchar data1,uchar data2)
{
switch(count)
{
case 1:busy_lcm(0x3);lcmcom=com;break;
case 2:busy_lcm(0x3);lcmdata=data1;busy_lcm(0x3);lcmcom=com;break;
case 3:busy_lcm(0x3);lcmdata=data1;busy_lcm(0x3);lcmdata=data2;busy_lcm
(0x3);lcmcom=com; break;
default:break;
}
}
/**************************************************************
函数功能:图形方式单个汉字显示
参数说明:x 为水平坐标,以汉字为单位(0-14)(240×128)
y 为垂直坐标,以汉字为单位(0-7)(240×128)
caddr 指针指向要显示的汉字在字符表中此字的绝对地址(32个字节)
*****************************************************************/
void display_1c(uchar caddr,uchar x,uchar y)
{
uchar i,j,*p;uint w;
p=ctable+caddr*32;
x="x"<<1;
for(i=0;i<=1;i++)
{x=x+i;
for(j=0;j<16;j++)
{w=y*16*30+x+32+j*30; //x(以汉字为单位)+显示区首址(32)+y(以汉字为单位)
//×16字节/汉字×显示区宽度(30字节)+j×显示区宽
度(30)
write_lcm(0x3,0x24,w%256,w>>8);//w%256为低位字节,w>>8为高位字节
write_lcm(0x2,0xc2,*p,NULL);
p++;
}
}
}
/**************************************************************
函数功能:图形方式单个半角西文或数字显示(8×16)
参数说明:x为水平坐标,以字为单位(0-29)(240×128)
y为垂直坐标,以字为单位(0-15)(240×128)
caddr为欲显示的半角西文或数字字符表中此字的绝对地址(偏移量)
如显0,d=0;显A,d=11
*****************************************************************/
void display_1e(uchar caddr,uchar x,uchar y)
{
uchar j,*p;uint w;
p="ctable"+caddr*32;
for(j=0;j<16;j++)
{w=y*16*30+x+32+j*30; //x(以汉字为单位)+显示区首址(32)+y(以汉字为单
位)
//×16行×显示区宽度(16)+j×显示区宽度(16)
write_lcm(0x3,0x24,w%256,w>>8);
write_lcm(0x2,0xc2,*p,NULL);
p++;
}
}
/***************************************************************
函数功能:图形方式清屏
参数说明:自动写模式
/**************************************************************/
void clear_lcm()
{
uint i;
write_lcm(0x3,0x24,0x0,0x0); /*设置显示RAM首地址*/
write_lcm(0x1,0xb0,NULL,NULL); /*设置自动写方式*/
for (i=0;i<9600;i++) /*最大显示点阵为:320×240=9600*/
{busy_lcm(0x0c);lcmdata=0x0;} /*写00H清屏*/
busy_lcm(0x0c);lcmcom=0xb2; /*设置自动写结束*/
}
/***************************************************************
函数功能:图形方式初始化
参数说明:自动写模式
/**************************************************************/
void init_lcm()
{
write_lcm(0x1,0xa1,NULL,NULL); //设置光标形状为8(列)×1(行)
write_lcm(0x3,0x21,0x0,0x0); //设置光标指针
write_lcm(0x3,0x40,0x0,0x0); //设置文本显示区域首址
write_lcm(0x3,0x41,0x1,0x0); //设置文本显示区域宽度,即每一行显示所占字节数
write_lcm(0x3,0x42,32,0x0); //设置图形显示区域首址为32
write_lcm(0x3,0x43,30,0x0); //设置图形显示区域宽度为30字节
write_lcm(0x1,0x80,NULL,NULL); //设置显示为逻辑“或”方式
write_lcm(0x1,0x9c,NULL,NULL); //设置显示开关,图形/文本显示均开启
}
/**************************************************************
函数功能:16×16汉字显示(图形方式)
参数说明:caddr:汉字在字符表中的相对首地址
x:列地址,以汉字为单位(0~14)(240×128)
y:行地址,以汉字为单位(0~7)(240×128)
n:显示汉字的个数
/**************************************************************/
void display_c(uchar caddr,uchar x,uchar y,uchar n)
{ uchar w;
//uchar *p;
//p=ctable+caddr*32;
for (w=0;w {
display_1c (caddr,x,y);
caddr++;
x="x"+1;
}
}
/**************************************************************
函数功能:绘点(图形方式)
参数说明:px 点的水平坐标(0~239)(240×128)
Py 点的垂直坐标(0~127)(240×128)
/*************************************************************/
void display_p(uchar px,uchar py)
{ uint b;
volatile uchar a,c;
a="px/8"; //a化为字节数
c="px"%8; //c化为单字节的数据
b="py"*16+a+32;
a="0x80">>c; //根据c,变为小数点的位置
write_lcm(0x3,0x24,b%256,b>>8); //设置显示地址
busy_lcm(0x0c);lcmcom=0xc5;
busy_lcm(0x0c);c=lcmdata; //读该位原来的数据
a="a|c";
write_lcm(0x2,0xc4,a,NULL); //写显示数据
}
/**************************************************************
函数功能:显示演示(图形方式)
参数说明:第一行:0123456789.ABC(半角)
第二行: 0 1 2 3 4 5 (全角16×16)
第三行: 绘水平直线
/**************************************************************/
void main()
{
uchar d,x,y;
init_lcm(); //LCM初始化
clear_lcm(); //LCM清屏
for(d=0;d<14;d++)
{x=d+7;
display_1e(d,x,0);
} //显示“0123456789.ABC”(半角)
display_c (0,4,2,6); //显示“012345”(全角)
x=60;y=120;
for(d=0;d<100;d++)
{
display_p(x,y);
x="x"+1;
} //绘水平直线
while(1);
}
uchar code ctable[]=
{
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,//0=0 ,以字为单位的相对地址
0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,//1
0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,//2
0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,//3
0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,//4
0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,//5
0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,//6
0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,//7
0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,//8
0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,//9
0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//.
0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x10,0x18,0x28,0x28, //A=11
0x24,0x3C,0x44,0x42,0x42,0xE7,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xF8,0x44,0x44,0x44,0x78, //B
0x44,0x42,0x42,0x42,0x44,0xF8,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3E,0x42,0x42,0x80,0x80, //C
0x80,0x80,0x80,0x42,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
文章评论(0条评论)
登录后参与讨论