为何我的程序不显示呢?
/******内部驱动子程序开始***********************/
static uchar ReadState()
{
uchar Data;
TFT_IO = 0x0FF;
TFT_CD = 1;
TFT_RD = 0;
TFT_CS = 0;
//至少延时150ns
nop();nop();
Data = TFT_IO;
nop();
//至少延时50ns
TFT_RD = 1;
TFT_CS = 1;
return(Data);
}
//判断状态位STA1,STA0子程序
static void RW_Check()
{
uchar State;
do{State=ReadState();}while(!(State&0x03));
}
//判断状态位STA2的子程序
static void AutoReadCheck()
{
uchar State;
do{State=ReadState();}while(!(State&0x04));
}
//判断状态位STA3的子程序
static void AutoWriteCheck()
{
uchar State;
do{State=ReadState();}while(!(State&0x08));
}
//写数据
static void WriteData(uchar Data)
{
RW_Check();
TFT_CD = 0;
TFT_CS = 0;
TFT_WR = 0;
TFT_IO = Data;
nop();
//至少延时40ns
TFT_CD = 1;
TFT_CS = 1;
TFT_WR = 1;
}
//写命令
static void WriteCommand(uchar Command)
{
RW_Check();
TFT_CD = 1;
TFT_CS = 0;
TFT_WR = 0;
TFT_IO = Command;
nop();
//至少延时40ns
TFT_CD = 1;
TFT_CS = 1;
TFT_WR = 1;
}
//写数据命令
static void WriteDataCommand(uchar Data,uchar Command)
{
WriteData(Data);//写数据
WriteCommand(Command);
}
//写双数据命令
static void WriteData2Command(uchar Data1,uchar Data2,uchar Command)
{
WriteData(Data1);//写数据
WriteData(Data2);//写数据
WriteCommand(Command);
}
//自动写数据
static void AutoWriteData(uchar Data)
{
AutoWriteCheck();//判断状态位STA3子程序
TFT_CD = 0;
TFT_CS = 0;
TFT_WR = 0;
TFT_IO = Data;
nop();
//至少延时40ns
TFT_CD = 1;
TFT_CS = 1;
TFT_WR = 1;
}
//文本方式初始化
static void TftTextInit()
{
//WriteData2Command(0x01,0x00,CursorPointer);//CursorPointer 0x21
WriteData2Command(0x00,0x00,TextHomeAddr);//TextHomeAddr 0x40
WriteData2Command(LineChar,0x00,TextArea);//TextArea 0x41
WriteCommand(TextOn);//TextOn 0x94
WriteCommand(CursorPattern);//一线模式A0
WriteCommand(OrMode);//OrMode 0x80
}
//图形方式初始化
static void TftGraphicInit()
{
WriteData2Command(0x00,0x08,GraphicHomeAddr);//GraphicHomeAddr 0x42
WriteData2Command(LineChar,0x00,GraphicArea);//GraphicArea 0x43
WriteCommand(CursorPattern);//一线模式A0
WriteCommand(OrMode);//OrMode 0x80
WriteCommand(GraphicOn);//GraphicOn 0x98
}
//CGRAM函数
static void CreatCGRam()
{
uint16 data i;
WriteData2Command(0x03,0x00,OffsetReg);//OffsetReg 0x22
WriteData2Command(0x00,0x1c,AddressPointer);//AddressPointer 0x24
WriteCommand(DataAutoWrite);//DataAutoWrite 0x0B0
for(i=0;i<1264;i++)
{
AutoWriteCheck();
WriteData(CGTAB[i]);
}
WriteCommand(ExitAutoRW);//ExitAutoRW 0x0B2
}
//用Text方式在(x,y)显示一个汉字
static void WriteOneHzText(uchar xAddr,uchar yAddr,uchar uData)
{
uint16 i,j;
i=LineChar;
j=i*yAddr+xAddr;
WriteData2Command(j%256,j/256,AddressPointer);//AddressPointer 0x24
//写入左上半部汉字代码
WriteDataCommand(uData,DataWAddrI);//DataWAddrI 0x0C0
//写入右上半部汉字代码
WriteDataCommand(uData+0x02,DataWAddrI);//DataWAddrI 0x0C0
j=j+i+0x20;//显示RAM地址修正
WriteData2Command(j%256,j/256,AddressPointer);//AddressPointer 0x24
//写入左下半部汉字代码
WriteDataCommand(uData+0x01,DataWAddrI);//DataWAddrI 0x0C0
//写入右下半部汉字代码
WriteDataCommand(uData+0x03,DataWAddrI);//DataWAddrI 0x0C0
}
//用Graphic方式在(x,y)显示一个汉字
static void WriteOneHzGraphic(uchar xAddr,uchar yAddr,uchar uData)
{
uint16 i,j,count1;
i=LineChar;
j=i*yAddr+xAddr+0x0800;/*图形显示区首地址为0x0800*/
for(count1=0;count1<16;count1++)
{
WriteData2Command(j%256,j/256,AddressPointer);//AddressPointer 0x24
WriteDataCommand(CCTAB[uData][count1],DataWAddrI);//DataWAddrI 0x0C0
WriteDataCommand(CCTAB[uData][count1+16],DataWAddrI);//DataWAddrI 0x0C0
j=j+i;
}
}
static void TftWriteChar(uchar xAddr,uchar yAddr,uchar uData)
{//西文字符写入(文本属性)函数
uint16 data i,j;
i=LineChar;
j=i*yAddr+xAddr;
WriteData2Command(j%256,j/256,AddressPointer);//AddressPointer 0x24
WriteDataCommand(uData,DataWAddrNV);//DataWAddrNV 0x0C4
WriteData2Command(uData,0x08,AddressPointer);//AddressPointer 0x24
WriteDataCommand(0,DataWAddrNV);//DataWAddrNV 0x0C4
}
/******内部驱动子程序结束***********************/
/////////////////////////////////////////////////
//液晶屏初始化
void TftInit()
{
TftTextInit();//文本方式初始化
TftGraphicInit();//图形方式初始化
}
//清屏
void TftClearScreen()
{
uint16 data i;
WriteData2Command(0x00,0x00,AddressPointer);//AddressPointer 0x24
WriteCommand(DataAutoWrite);//数据自动写DataAutoWrite 0x0B0
for(i=0;i<8192;i++)//8k
{
WriteData(0x00);//写数据
}
WriteCommand(ExitAutoRW);//退出数据自动读写模式ExitAutoRW 0x0B2
}
//显示汉字
void DisplayScreen()
{
CreatCGRam();//建立CGRAM
WriteOneHzText(0x00,0x00,0x80);
TftWriteChar(0x05,0x05,0x00);
WriteOneHzGraphic(0x00,0x00,0x00);
}
main()
{
TftInit();//液晶屏初始化
TftClearScreen();//清屏
void DisplayScreen();//显示汉字和字母
} |