www.pudn.com > LCD20040316.rar > OCM4X8C.c


 
 
// 
//rebuild on 2004/03/16 
//ocm4x8c and with character mold lcd compatible provided 
//pin4:RS(CS) connect to A1 
//pin5:RW     connect to A0 
// 
//!!the follow is important ,please vary the address 0x4000 accord to your hardware!! 
//  
//pin6:EN=(!A_LCD)&(!(WRn&RDn)  ;HARDWARE connect:WRn and RDn is 8031 P3.6,P3.7 respectively; 
//				A_LCD is 74138 output Y2n,also as 8031 address of 0x4000 
//				74138 input A connect to 8031 P2.7(A15),B to P2.6(A14),C to P2.5(A13) 
// 
//pin7:DB0 	connect to D0 
//...		... 
//pin14:DB7	connect to D7 
//pin15:connect to vcc,parallel mode 
//pin16:not used 
//pin17:RESETn   not used 
// 
//D0-D7 is the data bus,and A0-A15 is the address bus(so you must use a 74373) 
// 
// 
 
 
#ifdef OCM4X8C 
#include  
#include "..\h\OCM4X8C.h" 
 
bit CheckBusy(void)		//返回值为1,说明正忙 
{ 
 
if(XBYTE[OCM4X8C_READ_INSTRUCTION]>=0x80)return(1); 
else return(0); 
} 
byte ReadAC(void)		// AC as the ADDRESS COUNTER 
{ 
return(XBYTE[OCM4X8C_READ_INSTRUCTION]&0x7F); 
} 
 
void WaitMode(void) 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=CLEAR_DISPLAY;		//clear all DDRAM(20h),set AC to 00h 
} 
 
void OCM4X8C_initial(void) 
{ 
WaitMode(); 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=DISPLAY_STATUS+7;	//whole display on,index on,index position on 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=SET_ENTRANCE_POINT+2;//index shift right;whole display no move  
} 
 
void IndexShiftLeft(void) 
//index shift left 16 pixels,but not clear display,it will be replaced by the follow character. 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=0x10; 
} 
 
void IndexShiftRight(void) 
//index shift right as 16 pixels,left a space 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=0x14; 
} 
 
void SetCGRAM(byte AC) 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=SET_CGRAM+AC; 
} 
 
void SetDDRAM(byte AC) 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=SET_DDRAM+AC; 
} 
/* 
void WholeShiftLeft(void) 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=0x18; 
} 
 
void WholeShiftRight(void) 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=0x1c; 
} 
*/ 
 
void SetToBasicOperation(void)		//基本指令集动作 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=SET_FUNCTION_BASIC; 
} 
 
void SetToExtendOperation(void)		//扩展指令集动作 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=SET_FUNCTION_EXTEND; 
} 
 
void BackWhite(byte line)		//扩展指令集动作,line=0--3 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=BACK_WHITE+line; 
} 
 
void DrawOn(void)			//扩展指令集动作,绘图显示开 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=DRAW_ON; 
} 
 
void DrawOff(void) 
{ 
while(CheckBusy()); 
XBYTE[OCM4X8C_WRITE_INSTRUCTION]=DRAW_OFF; 
} 
 
void DisplayCGRAM(byte index) 
{ 
//index should be valued in 00h to 03h 
	while(CheckBusy()); 
	XBYTE[OCM4X8C_WRITE_DATA]=0; 
	while(CheckBusy()); 
	XBYTE[OCM4X8C_WRITE_DATA]=2*index; 
} 
 
void SetStartPoisition(byte line,byte x) 
{ 
byte line_real; 
switch(line) 
	{ 
	case 1:line_real=0;break; 
	case 2:line_real=0x10;break; 
	case 3:line_real=8;break; 
	case 4:line_real=0x18;break; 
	} 
SetDDRAM(line_real+x-1); 
} 
void NextLine(void) 
{ 
	while(CheckBusy()); 
	switch(ReadAC()) 
	{ 
	case 0x08:SetDDRAM(0x10);break; 
	case 0x18:SetDDRAM(0x08);break; 
	case 0x10:SetDDRAM(0x18);break; 
	case 0x20:WaitMode();break; 
    } 
 
} 
bit CheckOdd; 
void DisplayChar(byte Char) 
{ 
	while(CheckBusy()); 
	XBYTE[OCM4X8C_WRITE_DATA]=Char; 
	CheckOdd^=1; 
 
	if(!CheckOdd) NextLine(); 
 
} 
void DisplayEChar(byte EChar) 
{ 
//EChar should be valued in 01h to 7fh 
if((EChar>0)&&(EChar<0x80)) 
	{ 
 
	while(CheckBusy()); 
	XBYTE[OCM4X8C_WRITE_DATA]=EChar; 
	CheckOdd^=1; 
 
	if(!CheckOdd) NextLine(); 
 
	} 
} 
 
void DisplayCChar(word CChar) 
{ 
//CChar should be valued in 0xa1a1 to 0xf7fe, 
//in which ,0xa1a0 to 0xa9ff is special characters, 
//0xb0a1 to 0xd7fe is the class 1 chinese characters, 
//0xd8a1 to 0xf7fe is the class 2 chinese characters. 
byte high,low; 
high=CChar>>8; 
low=CChar; 
if((high>0xa0)&&(high<0xf8)&&(low>0xa0)&&(low<0xff)) 
	{ 
 
	while(CheckBusy()); 
	XBYTE[OCM4X8C_WRITE_DATA]=high;	//higer 8bit,should be bigger than or equal to 0xa0 
	while(CheckBusy()); 
	XBYTE[OCM4X8C_WRITE_DATA]=low;	//lower 8bit,should be bigger than or equal to 0xa0 
 
	NextLine(); 
	} 
 
} 
 
void DisplayString(byte *string) 
{ 
byte i=0; 
while(*(string+i)!=LCD_STRING_END) 
	{ 
	DisplayChar(*(string+i)); 
	i++; 
	} 
} 
 
 
void DisplayNumber(word number) 
{ 
byte NumDisplay[5]; 
byte i,*string; 
bit rtn=0; 
 
	NumDisplay[0]=number/10000;			//最高位 
	number-=NumDisplay[0]*10000; 
 
	NumDisplay[1]=number/1000; 
	number-=NumDisplay[1]*1000; 
 
	NumDisplay[2]=number/100; 
	number-=NumDisplay[2]*100; 
 
	NumDisplay[3]=number/10; 
	number-=NumDisplay[3]*10; 
 
	NumDisplay[4]=number; 
 
	string=NumDisplay; 
	 
for(i=0;(i<5)&&(rtn==0);i++)			//寻找第一个不为0的数字位置//保证至少输出一个数字 
	{ 
	 if(*(string+i)!=0) rtn=1; 
	 	 
	} 
 
 
for(i-=1;i<5;i++) 
	{ 
	  DisplayEChar(*(string+i)+0x30); 
    } 
 
} 
 
 
 
 
#endif