|
求教!!t6963c的程序,没有任何字符或者汉字显示出来。用c写的。
[复制链接]
#ifndef _lcd_
#define _lcd_
#include
#include
#define LineChar 30
#define ColumnChar 16
#define comport 0x8001
#define dataport 0x8000
#define unchar unsigned char
#define unint unsigned int
sfr AUXR = 0x8E;
sbit ce = P4^3;
sbit cd = P0^0;
sbit wr = P3^6;
sbit rd = P3^7;
sbit P1_0 = P1^0;
unsigned char count_l;
void RWCheck() //指令,数据读写状态检查
{unsigned char sta;
do
{ PSW = 0X00;
P0= 0xFF; //置高电平。可用可不要
rd = 0;// SET RD=L
wr = 1; //WR=H
ce = 0; //使能信号CE=L
cd = 1; //C/D=H
P1_0 = 1;
sta=XBYTE[comport]&0x03;
}
while(sta!=0x03);
rd = 1;
}
void AutoWCheck() //数据自动写状态检查
{
unsigned char sta;
do
{
PSW = 0X00;
P0= 0xFF; //置高电平。可用可不要
rd = 0;// SET RD=L
wr = 1; //WR=H
ce = 0; //使能信号CE=L
cd = 1; //C/D=H
P1_0 = 1;
sta=XBYTE[comport]&0x08;
}
while(sta!=0x08);
rd = 1;
}
//P4.3ce。A0即P0.0是C/D,P3.6WR P3.7RD ,在写入的过程中是否应一直使能 C/D
void OutPortData(unsigned char data1) //写一个数据
{
RWCheck(); //先进行读写检查
wr = 0;
ce = 0;//使能信号。CE = L;
cd = 0;//C/D=L有P3.3控制,当为低时说明有数据写入,如果为高说明写入的是命令。?
rd = 1; //RD = H
XBYTE[dataport] = data1;
rd = 1; //置高电平
}
void OutPortCom1(unsigned char command) //写命令
{
RWCheck(); //先进行读写检查
ce = 0;//使能CE=L
cd = 1;//C/D=H
rd = 1; //RD = H
wr = 0; // WR = L
XBYTE[comport]= command;
rd = 1;//置高电平
}
void OutPortCom2(unsigned char data1,unsigned char command)
{
OutPortData(data1);
OutPortCom1(command);
}
void OutPortCom3(unsigned char data1,unsigned char data2,unsigned char command)
{
OutPortData(data1);
OutPortData(data2);
OutPortCom1(command);
}
//以上是检测的和写命令的程序。
//编写一下clear程序。
/*
在自己的现时的系统中,管脚的连接如下:P4.3使能。A0即P0.0是C/D,P3.6WR P3.7RD Reset是P1.1
*/
void ClearScreen()
{
unsigned short i;
///////// 清显示 RAM 区 0000h--2000h (8k)
OutPortCom3(0x00,0x00,0x24); //设置指针地址0000H
OutPortCom1(0xb0); //设置自动写状态
for(i=0x00;i<0x0780;i++)
{
AutoWCheck();
OutPortData(0x00);
}// data=0;
OutPortCom1(0xb2); // 自动写结束
}
void InitLCD()//初始化
{
AUXR = 0x02;
OutPortCom3( 0x00,0x00,0x42 ); //设置图形显示区域首地址GraphAddr
OutPortCom3( 30,0x00,0x43 ); //设置图形显示区域宽度 : LineChar// OutPortCom3( 0x00,0x00,0x42 ); //设置图形显示区域首地址GraphAddr
OutPortCom1(0xa7); //设置光标形状 cursor size 8x8
//OutPortCom1(0x80); //设置显示方式: CGROM方式 文本\图形 "或"
OutPortCom1(0x81); //test采用异或方式
OutPortCom1(0x98); //设置显示开关: 1001 1100 图形ClearScreen();,文本关 图形开。
ClearScreen();
}
void ShowPicture(unsigned char Startline,unsigned char Startcolumn,unsigned char LineWidth,unsigned char ColumnWidth)//,unsigned short address)
{
unsigned char i,j;
unsigned short StartAddr;
StartAddr=Startline*LineChar + Startcolumn; //定位起始位置
for(i=0;i
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //set address
for(j=0;j
{
OutPortCom2( huadong[i*LineWidth+ j], 0xc0);
}
StartAddr=StartAddr + LineChar;
}
//参数:1。起始行 2。起始列 3。宽 4。高 5。起始位置。
//图形模式开,文本模式关。
void ShowChar(unsigned char lin,unsigned char column,unsigned char* ch) //ch为标准的ASCII码。
{
unsigned char i;
unsigned char dat;
unsigned short StartAddr;
StartAddr=lin*LineChar +column; //定位起始行
for(i=0;i<16;i++)
{
dat=ASCII816[*ch-0x20];
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //set address
OutPortCom2( dat, 0xc4);//c0与c4的区别,great,c4地址不增加,c0地址增加
StartAddr=StartAddr + LineChar;
}
}
void ShowReChar(unsigned char lin,unsigned char column,unsigned char ch) //ch为标准的ASCII码。
{
unsigned char i;
unsigned char dat;
unsigned short StartAddr;
StartAddr=lin*LineChar +column; //定位起始行
for(i=0;i<16;i++)
{
dat=ASCII816[ch-0x20];
dat=~dat;
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //set address
OutPortCom2( dat, 0xc4);//c0与c4的区别,great,c4地址不增加,c0地址增加
StartAddr=StartAddr + LineChar;
}
}
//显示一个汉字的程序。
void ShowHZ(unsigned char lin,unsigned char column,unsigned char *hzcode)
{
unsigned char i;
unsigned short StartAddr;
unsigned char hz_ma[2];
//unsigned char temp = *src;
unsigned long addr; //存储的位置
unsigned char qu_ma; //区码
unsigned char wei_ma; //位码
unsigned char p4_val; //p4口的值,片选的值8片中的一片。
unsigned int fla_val; //在一片中的地址
//unsigned char lcd_val; //读书的点阵的值
StartAddr=lin*LineChar + column; //定位起始行
qu_ma = (*hzcode)-161;
hzcode++;
wei_ma = (*hzcode)-161;
addr =((unsigned long)qu_ma*94+wei_ma)*32; //计算出存储的一个起始地址地址
p4_val = addr/65536;
fla_val = addr%65536;
AUXR = 0x02; //使用外部的扩展RAM。
P1_0 = 0; //片选信号先给,应该是低电平
// ce = 1; //T6963的片选信号是高电平
P4 =8|p4_val; //给出8片的片选信号t
// AUXR = 0x20; //读取外部Flash中的点阵。
//lcd_val = XBYTE[fla_val]; //第二步通过连续32次的读取来画出字符
for(i=0;i<16;i++)
{
P1_0 = 0; //片选信号先给,应该是低电平
ce = 1;
hz_ma[0] = XBYTE[fla_val++];
hz_ma[1] = XBYTE[fla_val++];
P1_0 = 1;
OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24);
OutPortCom2( hz_ma[0] , 0xc0); //左半部 地址加一
OutPortCom2( hz_ma[1], 0xc4); //右半部 字模地址加一
StartAddr=StartAddr + LineChar;
}
}
//显示一行字符串
//显示一行字符串(汉字,字母混排,一行16字节)
//lin:行
//lineheadaddr: 此行汉字代码区首地址
void showline1(unsigned char lin,unsigned char column,unsigned char *linehead)
{
unsigned char *p_show = linehead;
unsigned char i =column;//j;
unsigned char byte = 28-column;
// unsigned int hzcode;
// unsigned char length = strlen
// while((*p_show)!='\0')
for(count_l=0;count_l
{
if((*p_show) < 0x80) //字母
{
ShowChar(lin, i , p_show); //very good//
i=i+1;
count_l++;
p_show++;
}
else // byte >= 0x80(汉字)
{
// byte=byte & 0x7f; //最高位置0,即:减去0x8000
//hzcode=byte*256 + linehead[j+1]; //加低8位,组合成整型数地址
ShowHZ( lin,i,p_show);
p_show++;
p_show++;
i=i+2;
count_l = count_l+2;
}
}//end while;
}
void ShowLine(unsigned char lin,unsigned char column,unsigned char *linehead)
{
unsigned char *p_show = linehead;
unsigned char i =column;
//unsigned char byte;
// unsigned int hzcode;
// unsigned char length = strlen
while((*p_show)!='\0')
{
if((*p_show) < 0x80) //字母
{
ShowChar(lin, i , p_show); //very good//
i=i+1;
p_show++;
}
else // byte >= 0x80(汉字)
{
// byte=byte & 0x7f; //最高位置0,即:减去0x8000
//hzcode=byte*256 + linehead[j+1]; //加低8位,组合成整型数地址
ShowHZ( lin,i,p_show);
p_show++;
p_show++;
i=i+2;
}//end while;
}//end ShowLine
}
//显示一屏汉字
//pageheadaddr:此屏汉字代码地址区首地址
void Show_Page(unsigned char lin,unsigned char column1,unsigned char* pagehead)
{
unsigned char length;
length = strlen((char*)pagehead);
if (length<27) //一行即可显示完毕。
ShowLine(lin,column1,pagehead);//按照这个思路来走
//for(i=0;i< 4 ;i++)
else
{
showline1(lin,column1,pagehead);
ShowLine((lin+16),3,pagehead+count_l); //1行8个汉字,16字节
}
}
#endif //ShowPage
--------------------------------------------
void main(void)
{
unchar code STR1[9]={0x54,0x52,0x40,0x4a,0x31,0x36,0x42,0x56,'\0'};
p3_3=0;//背光
InitLCD();
Lcddelay(800);
while(1)
{
p3_3 = 0;
Lcddelay(900);
ShowLine(1,0,STR1);
p3_3 = 1;
Lcddelay(900);
}
}
----------------------------
现在程序执行的时候液晶屏可以一亮一灭的,但是没有任何字符或汉字的显示。请大虾指点,谢谢!
也在其他地方看到说这种问题很可能是初始化的问题,有哪位能说得详细点么?谢谢!
用的液晶是240*64的,8×8的字体。
这个问题找了快一个周了!第一次用液晶....汗...
|
|