📄 12864lcd.h
字号:
#include <reg51.H>
#endif
#ifndef __ABSACC_H__
#define __ABSACC_H__
#define CBYTE ((unsigned char volatile code *) 0)
#define DBYTE ((unsigned char volatile data *) 0)
#define PBYTE ((unsigned char volatile pdata *) 0)
#define XBYTE ((unsigned char volatile xdata *) 0)
#define CWORD ((unsigned int volatile code *) 0)
#define DWORD ((unsigned int volatile data *) 0)
#define PWORD ((unsigned int volatile pdata *) 0)
#define XWORD ((unsigned int volatile xdata *) 0)
#ifdef __CX51__
#define FVAR(object, addr) (*((object volatile far *) (addr)))
#define FARRAY(object, base) ((object volatile far *) (base))
#define FCVAR(object, addr) (*((object const far *) (addr)))
#define FCARRAY(object, base) ((object const far *) (base))
#else
#define FVAR(object, addr) (*((object volatile far *) ((addr)+0x10000L)))
#define FCVAR(object, addr) (*((object const far *) ((addr)+0x810000L)))
#define FARRAY(object, base) ((object volatile far *) ((base)+0x10000L))
#define FCARRAY(object, base) ((object const far *) ((base)+0x810000L))
#endif
#endif
#ifndef __12864LCD_H__
#define __12864LCD_H__
#define LBYTE(x) (unsigned char)x
#define HBYTE(x) (unsigned)(x >> 8)
#define dCGHomeAdd_H 0x00
#define dCGHomeAdd_L 0x00
#define dCGHomeAdd 0x0000
#define dTextHomeAdd_H 0x0f
#define dTextHomeAdd_L 0x00
#define dTextHomeAdd 0x0f00
#define dSecTextAdd_H 0x1e
#define dSecTextAdd_L 0x00
#define dSecTextAdd 0x1e00
#define dGraphHomeAdd_H 0x2d
#define dGraphHomeAdd_L 0x00
#define dGraphHomeAdd 0x2d00
#define dSecGraphAdd_H 0x3c
#define dSecGraphAdd_L 0x00
#define dSecGraphAdd 0x3c00
#define DATA_PORT XBYTE[0x2000]
#define COMM_PORT XBYTE[0x2001]
void delay(unsigned time);
void LongDelay(unsigned char time);
unsigned char ReadState_LCD(void);
bit IsBusy_LCD(void);
unsigned char ReadData_LCD(void);
void WriteData_LCD(unsigned char cData);
void SendCommand_LCD(unsigned char cCom, unsigned char cData1, unsigned char cData2);
void Init_LCD(void);
void SetScrMode_LCD(unsigned char Graph, unsigned char Text, unsigned char Cur);
void ClrScrText_LCD(unsigned char cbSel);
void SetPos_LCD(unsigned char x, unsigned char y);
void PutStrXY_LCD(unsigned char* str, unsigned char x, unsigned char y);
void PutStr_LCD(unsigned char* str);
void PutNumXY_LCD(unsigned Num, unsigned char Len, unsigned char x, unsigned char y);
void SetCurXY_LCD(unsigned char x, unsigned char y);
void SetCurLine_LCD(unsigned char Line);
void ClrScrGraph_LCD(unsigned char cbSel);
void PutPixel_LCD(unsigned char x, unsigned char y, bit Bit);
void LineY_LCD(unsigned char x, unsigned char y, register unsigned char l, bit Bit);
void LineX_LCD(unsigned char x, unsigned char y, register unsigned char l, bit Bit);
void SetPointer_LCD(unsigned uAdd);
void SetMem_LCD(unsigned uAdd, unsigned char cData);
void PutPicture_LCD(unsigned char x,unsigned char y,unsigned char *p,unsigned char px,unsigned char py);
void SetCurMem_LCD(unsigned char cData);
unsigned char ReadMem_LCD(unsigned uAdd);
void ClearMem_LCD(void);
void Clrscr_LCD(void);
void delay(unsigned time)
{
while ( time-- );
}//
void LongDelay(unsigned char time)
{
while(time--)
delay(60000);
}//
unsigned char ReadState_LCD(void)
{
unsigned char i = 0;
i = COMM_PORT;
return i;
}
bit IsBusy_LCD(void)
{
unsigned char i = 0;
i = COMM_PORT;
return (i & 0x03) != 3;
}
void WriteCommand_LCD(unsigned char cCom)
{
while (IsBusy_LCD());
COMM_PORT = cCom;
}
unsigned char ReadData_LCD(void)
{
unsigned char i;
while (IsBusy_LCD());
i = DATA_PORT;
return i;
}
void WriteData_LCD(unsigned char cData)
{
while (IsBusy_LCD());
DATA_PORT = cData;
}
void SendCommand_LCD(unsigned char cCom, unsigned char cData1, unsigned char cData2)
{
WriteData_LCD(cData1);
WriteData_LCD(cData2);
WriteCommand_LCD(cCom);
}
void Init_LCD(void)
{
WriteCommand_LCD(0x90); //Display Mode
SendCommand_LCD(0x24, 0x00, 0x00);
SendCommand_LCD(0x40, dTextHomeAdd_L, dTextHomeAdd_H); // Control Word set
SendCommand_LCD(0x41, 0x20, 0x00); // Control Word set
SendCommand_LCD(0x42, dGraphHomeAdd_L, dGraphHomeAdd_H); // Control Word set
SendCommand_LCD(0x43, 0x20, 0x00); // Control Word set
WriteCommand_LCD(0x80); //Mode set
SetScrMode_LCD(1, 1, 0);
Clrscr_LCD();
SetPos_LCD(0x00, 0x00);
}
void SetScrMode_LCD(unsigned char Graph, unsigned char Text, unsigned char Cur)
{
WriteCommand_LCD(0x90 + (Graph << 3) + (Text << 2) + (Cur << 1) + 1); // Control Word set
}
void ClrScrText_LCD(unsigned char cbSel)
{
unsigned i = 1000;
unsigned char cbOffset_L = cbSel ? dSecTextAdd_L : dTextHomeAdd_L;
unsigned char cbOffset_H = cbSel ? dSecTextAdd_H : dTextHomeAdd_H;
SendCommand_LCD(0x24, cbOffset_L, cbOffset_H); //定义寄存器变量
while (i--)
{
WriteData_LCD(0x00);
WriteCommand_LCD(0xc0);
}
SendCommand_LCD(0x24, cbOffset_L, cbOffset_H); //定义寄存器变量
SendCommand_LCD(0x21, 0, 0); //定义寄存器变量
}
void SetPos_LCD(unsigned char x, unsigned char y)
{
unsigned m = y * 32;
unsigned nOffset = dTextHomeAdd + m + x;
SendCommand_LCD(0x24, LBYTE(nOffset), HBYTE(nOffset)); //定义寄存器变量
}
void PutStrXY_LCD(unsigned char* str, unsigned char x, unsigned char y)
{
SetPos_LCD(x, y);
PutStr_LCD(str);
}
void PutStr_LCD(unsigned char* str)
{
while (*str)
{
WriteData_LCD( (*str++) - 32 );
WriteCommand_LCD(0xc0); //Data read Write
}
}
void PutNumXY_LCD(unsigned Num, unsigned char Len, unsigned char x, unsigned char y)
{
register unsigned char i;
SetPos_LCD(x + Len - 1, y);
for (i = 0; i < Len; i++)
{
WriteData_LCD(Num % 10 + 16);
WriteCommand_LCD(0xc2); //Data read Write
Num /= 10;
}
}
void SetCurXY_LCD(unsigned char x, unsigned char y)
{
SendCommand_LCD(0x21, x, y); //定义寄存器变量
}
void SetCurLine_LCD(unsigned char Line)
{
WriteCommand_LCD(0x9f + Line); //Display Mode
}
void ClrScrGraph_LCD(unsigned char cbSel)
{
unsigned i = 0x1000;
unsigned char cbOffset_L = cbSel ? dSecGraphAdd_L : dGraphHomeAdd_L;
unsigned char cbOffset_H = cbSel ? dSecGraphAdd_H : dGraphHomeAdd_H;
SendCommand_LCD(0x24, cbOffset_L, cbOffset_H); //定义寄存器变量
while (i--)
{
WriteData_LCD(0x00);
WriteCommand_LCD(0xc0); //Data read Write
}
SendCommand_LCD(0x24, cbOffset_L, cbOffset_H); //定义寄存器变量
}
void PutPixel_LCD(unsigned char x, unsigned char y, bit Bit)
{
unsigned uGraphOffset = (y << 7) + x;
unsigned uTextOffset = (uGraphOffset >> 3) + dGraphHomeAdd;
unsigned char cBitOffset = 7 - uGraphOffset % 8;
while (IsBusy_LCD());
DATA_PORT = (unsigned char)(uTextOffset & 0x00ff);
while (IsBusy_LCD());
DATA_PORT = (unsigned char)(uTextOffset >> 8);
while (IsBusy_LCD());
COMM_PORT = 0x24;
while (IsBusy_LCD());
COMM_PORT = (Bit ? 0xf8 : 0xf0) + cBitOffset; // Bit Set/Reset
}
void LineY_LCD(unsigned char x, unsigned char y, register unsigned char l, bit Bit)
{
while (l--)
PutPixel_LCD(x, y + l, Bit);
}
void LineX_LCD(unsigned char x, unsigned char y, register unsigned char l, bit Bit)
{
while (l--)
PutPixel_LCD(x + l, y, Bit);
}
void SetPointer_LCD(unsigned uAdd)
{
while (IsBusy_LCD());
DATA_PORT = (unsigned char)(uAdd & 0x00ff);
while (IsBusy_LCD());
DATA_PORT = (unsigned char)(uAdd >> 8);
while (IsBusy_LCD());
COMM_PORT = 0x24; //定义寄存器变量
}
void SetMem_LCD(unsigned uAdd, unsigned char cData)
{
SendCommand_LCD(0x24, (unsigned char)(uAdd & 0x00ff), (unsigned char)(uAdd >> 8)); //定义寄存器变量
WriteData_LCD(cData); //定义寄存器变量
WriteCommand_LCD(0xc4); //Data read Write
}
void PutPicture_LCD(unsigned char x,unsigned char y,unsigned char *p,unsigned char px,unsigned char py)
{
unsigned char i;
unsigned char j;
SetPointer_LCD(dGraphHomeAdd+y*32+x);
WriteCommand_LCD(0xb0);
for(j=0;j<py;j++)
{
for(i=0;i<px/8;i++)
{
while(!(ReadState_LCD()&0x08));
WriteData_LCD(*p++);
}
}
while(!(ReadState_LCD()&0x08));
WriteCommand_LCD(0xb2);
}
void SetCurMem_LCD(unsigned char cData)
{
WriteData_LCD(cData);
WriteCommand_LCD(0xc0);
}
unsigned char ReadMem_LCD(unsigned uAdd)
{
SendCommand_LCD(0x24, (unsigned char)(uAdd & 0x00ff), (unsigned char)(uAdd >> 8)); //定义寄存器变量
WriteCommand_LCD(0xc5);
return ReadData_LCD();
}
void ClearMem_LCD(void)
{
unsigned i;
SetPos_LCD(0x00, 0x00);
for (i = 0x0000; i < 0x8000; i++)
{
WriteData_LCD(0x00);
WriteCommand_LCD(0xc0);
}
}
void Clrscr_LCD(void)
{
ClrScrText_LCD(0);
ClrScrGraph_LCD(0);
}
void PutHz16(char * str,int x,int y)
{
int i,j;
bit a;
char s;
for(i = 0; i < 32; i+=2)
{
s = str[i];
for(j = 0 ; j < 8 ; j++)
{
s<<=1;
a = CY;
PutPixel_LCD(x+j,y+i,a);
}
s = str[i+1];
for(j = 8 ; j < 16 ; j++)
{
s<<=1;
a = CY;
PutPixel_LCD(x+j,y+i,a);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -