⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sed1335.cpp

📁 英创386的LCD控制协议和函数,还有例程
💻 CPP
字号:
/*//////////////////////////////////////////////////////////////////////////
Orgnization:	Emtronix Inc.
Filename:	SED1335.CPP
Compiler:	BC3.1
Authors:	Wang Ping
Date:		Sept. 1998
Modified:	CS & ZHL   Feb. 2003
///////////////////////////////////////////////////////////////////////////*/
#include <dos.h>
#include "sed1335.h"

#define LcdDatPort   0x30
#define LcdComPort   0x31
#define LcdCtlPort   0x32

// return =  0: init ok
//        = -1: init fail
int InitLCD( )
{
   asm mov ax, 0x0004
   asm int 10h
   return ClearScreen();
}

int ClearScreen( )
{
   outportb( LcdComPort, 0x4c );
   outportb( LcdComPort, 0x46 );
   outportb( LcdDatPort, 0x00 );
   outportb( LcdDatPort, 0x00 );
   outportb( LcdComPort, 0x42 );
   for( int i=0; i<240; i++ )
      {
      for( int j=0; j<40; j++ )
	 {
	 outportb( LcdDatPort, 0x00 );
	 }
      }
   return 0;
}

// input: DotColor = 0:    write 0;
//                 = 1:    write 1;
//                 = 0x81: XOR write
// return =  0: ok
//        = -1: LCD fail
int WritePixel( int x, int y, int DotColor )
{
   unsigned int  x1, Z;
   unsigned char TmpDat, MByte;
   x1 = x>>3;			// x/8;
   Z  = x1+y*40;

   // set cursor address
   outportb( LcdComPort, 0x4c );
   outportb( LcdComPort, 0x46 );
   outportb( LcdDatPort, Z );
   outportb( LcdDatPort, Z>>8 );

   // read data from display RAM
   outportb( LcdComPort, 0x43 );
   TmpDat = inportb( LcdComPort );

   // set cursor address
   outportb( LcdComPort, 0x4f );
   outportb( LcdComPort, 0x46 );
   outportb( LcdDatPort, Z );
   outportb( LcdDatPort, Z>>8 );

   // write data into display RAM
   outportb( LcdComPort, 0x42 );

   MByte = 0x80 >> (x%8);
   switch( DotColor )
      {
      case 0:    			// write 0
	   outportb( LcdDatPort, TmpDat&~MByte );
	   break;
      case 1:    			// write 1
	   outportb( LcdDatPort, TmpDat|MByte );
	   break;
      case 0x81: 			// XOR operation
	   outportb( LcdDatPort, TmpDat^MByte );
	   break;
      }

   return 0;
}

void WriteByte( int x, int y, unsigned char abyte )
{
   unsigned int  x1, Z;

   x1 = x>>3;			// x/8;
   Z  = x1+y*40;

   // set cursor increment direction
   outportb( LcdComPort, 0x4c );
   // set cursor address
   outportb( LcdComPort, 0x46 );
   outportb( LcdDatPort, Z );
   outportb( LcdDatPort, Z>>8 );

   // write data into display RAM
   outportb( LcdComPort, 0x42 );
   outportb( LcdDatPort, abyte );
}

void WriteByteBlock( int x, int y, unsigned char* hfont, int NumOfBytes )
{
   unsigned int  x1, Z, i;

   x1 = x>>3;			// x/8;
   Z  = x1+y*40;

   // set cursor increment direction
   outportb( LcdComPort, 0x4f );

   // set cursor address
   outportb( LcdComPort, 0x46 );
   outportb( LcdDatPort, Z );
   outportb( LcdDatPort, Z>>8 );

   // write data into display RAM
   outportb( LcdComPort, 0x42 );
   for( i=0; i<NumOfBytes; i++ )
      {
      outportb( LcdDatPort, hfont[i] );
      }
}

unsigned char ReadByte( int x, int y )
{
   unsigned int  x1, Z;
   unsigned char TmpDat;

   x1 = x>>3;			// x/8;
   Z  = x1+y*40;

   // set cursor increment direction
   outportb( LcdComPort, 0x4c );

   // set cursor address
   outportb( LcdComPort, 0x46 );
   outportb( LcdDatPort, Z );
   outportb( LcdDatPort, Z>>8 );

   // read data from display RAM
   outportb( LcdComPort, 0x43 );
   TmpDat = inportb( LcdComPort );
   return TmpDat;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -