📄 t6963c.cpp
字号:
/*//////////////////////////////////////////////////////////////////////////
Orgnization: Emtronix Incorporated
Filename: T6963C.CPP
Compiler: BC3.1
Authors: ZHL & CS
Date: October, 2002
Revised: ...
Description: function implementations of LCD module based on T6963C
///////////////////////////////////////////////////////////////////////////*/
#include <dos.h>
#include "t6963c.h"
#define DatPort0 0x30
#define CmdPort0 0x31
#define LcdDatPort DatPort0
#define LcdComPort CmdPort0
#define LcdCtlPort CmdPort0
#define GWidth 0x20
union LCDAddr
{
unsigned int AbsAddr;
unsigned char Pos[2];
};
int StatusReady( )
{
for(int i=0;i<1000;i++)
{
if (inportb(LcdComPort) & 0x03==0x03) return 1;
}
return 0;
}
int StatusReady2()
{
for(int i=0;i<1000;i++)
{
if (inportb(LcdComPort) & 0x04==0x04) return 1;
}
return 0;
}
int StatusReady3()
{
for(int i=0;i<1000;i++)
{
if (inportb(LcdComPort) & 0x08==0x08) return 1;
}
return 0;
}
int SendData( char Dat )
{
if( StatusReady( ) )
{
outportb(LcdDatPort, Dat);
return 1;
}
return 0;
}
int SendCmd( char Cmd )
{
if( StatusReady( ) )
{
outportb(LcdComPort, Cmd);
return 1;
}
return 0;
}
void InitLCDinText( )
{
SendData( 0 );
SendData( 0 );
SendCmd( 0x40 );
SendData( 0x40 );
SendData( 0 );
SendCmd( 0x41 );
SendData( 0 );
SendData( 0x08 );
SendCmd( 0x42 );
SendData( GWidth );
SendData( 0 );
SendCmd( 0x43 );
SendCmd( 0xa1 );
SendCmd( 0x84 );
SendCmd( 0x9f );
}
// return = 0: init ok
// = -1: init fail
int InitLCD( )
{
// set start address of text area
SendData( 0 );
SendData( 0 );
SendCmd( 0x40 );
// set width of text area
SendData( 0x40 );
SendData( 0 );
SendCmd( 0x41 );
// set start address of graphics area
SendData( 0 );
SendData( 0x08 );
SendCmd( 0x42 );
// set width of graphics area
SendData( GWidth );
SendData( 0 );
SendCmd( 0x43 );
SendCmd( 0xa1 ); // cursor shap
SendCmd( 0x80 ); //
//graphic on, text off
SendCmd( 0x98 );
return ClearScreen( );
}
// return = 0: init ok
// = -1: LCD fail
int ClearScreen( )
{
SendData( 0 );
SendData( 0 );
SendCmd( 0x24 );
SendCmd(0xb0); // start auto writing
for (int i=0;i<0x4000;i++)
{
if (StatusReady3())
{
outportb(LcdDatPort,0);
}
}
SendCmd(0xb2); // end auto writing
return 0;
}
// input: DotColor = 0: write 0;
// = 1: write 1;
// = 0x81: XOR write
// input x = 0 -- 239
// y = 0 -- 63
// return = 0: ok
// = -1: LCD fail
int WritePixel( int x, int y, int DotColor )
{
LCDAddr Addr;
unsigned char rem, cmd, N3, abyte, mask;
unsigned int col, row;
N3 = 0x08;
col = x / 8;
row = y;
// set addr
Addr.AbsAddr = row*GWidth + col + 0x800;
SendData( Addr.Pos[0] );
SendData( Addr.Pos[1] );
SendCmd( 0x24 );
// read the byte containing the dot need to operation
//SendCmd( 0xc5 ); // read data without changing address
//if( !StatusReady( ) ) return -1;
//abyte = inportb( LcdDatPort );
// bit operation
rem = x % 8;
mask = 1<<rem;
rem = (~rem) & 0x07;
cmd = 0xf0 | rem;
if( DotColor == 0 ) cmd = cmd & ~N3;
else cmd = cmd | N3;
/*
else if( DotColor == 1 ) cmd = cmd | N3;
else
{
abyte = abyte & mask;
if( abyte == 0 ) cmd = cmd | N3;
else cmd = cmd & ~N3;
}
*/
SendCmd( cmd );
return 0;
}
// input col = 0 -- 29 => column
// row = 0 -- 63
int WriteByte( int col, int row, unsigned char aByte )
{
LCDAddr Addr;
// set graphics addr
Addr.AbsAddr = row * GWidth + col + 0x800;
SendData( Addr.Pos[0] );
SendData( Addr.Pos[1] );
SendCmd( 0x24 );
SendData( aByte );
SendCmd( 0xc4 );
return 0;
}
// input col = 0 -- 29 => column
// row = 0 -- 63
// return = 0x0000 -- 0x00ff: ok
// = 0xffff (-1): fail
int ReadByte( int col, int row )
{
LCDAddr Addr;
char abyte;
// set graphics addr
Addr.AbsAddr = row * GWidth + col + 0x800;
SendData( Addr.Pos[0] );
SendData( Addr.Pos[1] );
SendCmd( 0x24 );
SendCmd( 0xc5 ); // read data without changing address
if( !StatusReady( ) ) return -1;
//SendCmd(0xb1); // set auto read
//if( StatusReady2() ) Buf = inportb( LcdDatPort ) + 0x20;
//SendCmd(0xb2); // end auto read
abyte = inportb( LcdDatPort );
return abyte;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -