📄 lcd12864l.c
字号:
/*************************************************************************
* LCD LPC2131
PIN4 RS PIN40 P1.22
PIN5 R/W PIN36 P1.23
PIN6 EN PIN44 P1.21
PIN7 DB0 PIN46 P0.16
PIN8 DB1 PIN39 P0.13
PIN9 DB2 PIN38 P0.12
PIN10 DB3 PIN37 P0.11
PIN11 DB4 PIN45 P0.15
PIN12 DB5 PIN11 P0.27
PIN13 DB6 PIN9 P0.25
PIN14 DB7 PIN10 P0.26
PIN15 CS1 PIN8 P1.18
PIN16 CS2 PIN12 P1.17
PIN17 /RST PIN13 P0.28
*
*************************************************************************/
#include "config.h"
#define LCD_RS (1<<22)
#define SET_LCD_RS() (IO1SET = LCD_RS)
#define CLR_LCD_RS() (IO1CLR = LCD_RS)
#define LCD_RW (1<<23)
#define SET_LCD_RW() (IO1SET = LCD_RW)
#define CLR_LCD_RW() (IO1CLR = LCD_RW)
#define LCD_EN (1<<21)
#define SET_LCD_EN() (IO1SET = LCD_EN)
#define CLR_LCD_EN() (IO1CLR = LCD_EN)
#define LCD_DB0 (1<<16)
#define SET_LCD_DB0() (IO0SET = LCD_DB0)
#define CLR_LCD_DB0() (IO0CLR = LCD_DB0)
#define LCD_DB1 (1<<13)
#define SET_LCD_DB1() (IO0SET = LCD_DB1)
#define CLR_LCD_DB1() (IO0CLR = LCD_DB1)
#define LCD_DB2 (1<<12)
#define SET_LCD_DB2() (IO0SET = LCD_DB2)
#define CLR_LCD_DB2() (IO0CLR = LCD_DB2)
#define LCD_DB3 (1<<11)
#define SET_LCD_DB3() (IO0SET = LCD_DB3)
#define CLR_LCD_DB3() (IO0CLR = LCD_DB3)
#define LCD_DB4 (1<<15)
#define SET_LCD_DB4() (IO0SET = LCD_DB4)
#define CLR_LCD_DB4() (IO0CLR = LCD_DB4)
#define LCD_DB5 (1<<27)
#define SET_LCD_DB5() (IO0SET = LCD_DB5)
#define CLR_LCD_DB5() (IO0CLR = LCD_DB5)
#define LCD_DB6 (1<<25)
#define SET_LCD_DB6() (IO0SET = LCD_DB6)
#define CLR_LCD_DB6() (IO0CLR = LCD_DB6)
#define LCD_DB7 (1<<26)
#define SET_LCD_DB7() (IO0SET = LCD_DB7)
#define CLR_LCD_DB7() (IO0CLR = LCD_DB7)
#define LCD_CS1 (1<<18)
#define SET_LCD_CS1() (IO1SET = LCD_CS1)
#define CLR_LCD_CS1() (IO1CLR = LCD_CS1)
#define LCD_CS2 (1<<17)
#define SET_LCD_CS2() (IO1SET = LCD_CS2)
#define CLR_LCD_CS2() (IO1CLR = LCD_CS2)
#define LCD_RST (1<<28)
#define SET_LCD_RST() (IO0SET = LCD_RST)
#define CLR_LCD_RST() (IO0CLR = LCD_RST)
void OutData(uint8 OutDat)
{
if( (OutDat&(1<<0)) != 0 ) {SET_LCD_DB0();} else {CLR_LCD_DB0();}
if( (OutDat&(1<<1)) != 0 ) {SET_LCD_DB1();} else {CLR_LCD_DB1();}
if( (OutDat&(1<<2)) != 0 ) {SET_LCD_DB2();} else {CLR_LCD_DB2();}
if( (OutDat&(1<<3)) != 0 ) {SET_LCD_DB3();} else {CLR_LCD_DB3();}
if( (OutDat&(1<<4)) != 0 ) {SET_LCD_DB4();} else {CLR_LCD_DB4();}
if( (OutDat&(1<<5)) != 0 ) {SET_LCD_DB5();} else {CLR_LCD_DB5();}
if( (OutDat&(1<<6)) != 0 ) {SET_LCD_DB6();} else {CLR_LCD_DB6();}
if( (OutDat&(1<<7)) != 0 ) {SET_LCD_DB7();} else {CLR_LCD_DB7();}
}
TCOLOR gui_disp_buf[GUI_LCM_YMAX/8][GUI_LCM_XMAX]; // 声明GUI显示缓冲区
#define LCM_DISPON 0x3f
#define LCM_STARTROW 0xc0
#define LCM_ADDRSTRX 0xb8
#define LCM_ADDRSTRY 0x40
void Delay5(void)
{
uint8 i;
for(i = 0;i <4;i++);
}
void LCM_WrCommand(uint8 command)
{
CLR_LCD_EN();
CLR_LCD_RS();
OutData(command);
Delay5();
SET_LCD_EN();
Delay5();
CLR_LCD_EN();
Delay5();
}
void LCM_WrData(uint8 wrdata)
{
CLR_LCD_EN();
SET_LCD_RS();
OutData(wrdata);
Delay5();
SET_LCD_EN();
Delay5();
CLR_LCD_EN();
Delay5();
}
void LCM_WriteByte(uint8 x,uint8 y,uint8 wrdata)
{
x = x&0x7f;
y = y&0x3f;
CLR_LCD_CS1();
CLR_LCD_CS2();
y = y>>3;
gui_disp_buf[y][x] = wrdata;
if(x<64)
{
SET_LCD_CS1();
}
else
{
SET_LCD_CS2();
x= x - 64;
}
LCM_WrCommand(LCM_ADDRSTRY+x);
LCM_WrCommand(LCM_ADDRSTRX+y);
LCM_WrData(wrdata);
}
uint8 LCM_ReadByte(uint8 x,uint8 y)
{
x = x&0x7f;
y = y&0x3f;
y = y>>3;
return(gui_disp_buf[y][x]);
}
void LCM_DispFill(uint8 filldata)
{
uint8 x,y;
SET_LCD_CS1();
SET_LCD_CS2();
LCM_WrCommand(LCM_STARTROW);
for(x = 0;x < 8;x++)
{
LCM_WrCommand(LCM_ADDRSTRX+x);
LCM_WrCommand(LCM_ADDRSTRY);
for(y = 0;y < 64;y++)
{
LCM_WrData(filldata);
}
}
CLR_LCD_CS1();
CLR_LCD_CS2();
}
void LCM_DispIni(void)
{
uint32 i;
//P0引脚设置
P0_GPIOInit(LCD_DB0,1);
P0_GPIOInit(LCD_DB1,1);
P0_GPIOInit(LCD_DB2,1);
P0_GPIOInit(LCD_DB3,1);
P0_GPIOInit(LCD_DB4,1);
P0_GPIOInit(LCD_DB5,1);
P0_GPIOInit(LCD_DB6,1);
P0_GPIOInit(LCD_DB7,1);
P0_GPIOInit(LCD_RST,1);
//P1引脚设置
PINSEL2 &= (~(1<<3));
IO1DIR |= (LCD_RS|LCD_RW|LCD_CS1|LCD_CS2|LCD_EN);
CLR_LCD_RST();
for(i = 0;i < 5000;i++);
SET_LCD_RST();
for(i = 0;i < 5000;i++);
SET_LCD_CS1();
SET_LCD_CS2();
LCM_WrCommand(LCM_DISPON);
LCM_WrCommand(LCM_STARTROW);
LCM_WrCommand(LCM_ADDRSTRX);
LCM_WrCommand(LCM_ADDRSTRY);
}
void GUI_FillSCR(TCOLOR dat)
{
uint32 i,j;
for(i = 0;i < (GUI_LCM_YMAX/8);i++)
{
for(j = 0;j < (GUI_LCM_XMAX);j++)
{
gui_disp_buf[i][j] = dat;
}
}
LCM_DispFill(dat);
}
void GUI_Initialize(void)
{
LCM_DispIni();
GUI_FillSCR(0x00);
}
uint8 GUI_Point(uint8 x,uint8 y,TCOLOR color)
{
uint8 bak;
if( x >= GUI_LCM_XMAX) return (0);
if( y >= GUI_LCM_YMAX) return (0);
bak = LCM_ReadByte(x,y);
if(0==color)
{
bak &= (~(1<<(y&0x07)));
}
else
{
bak |= (1<<(y&0x07));
}
LCM_WriteByte(x,y,bak);
return 1;
}
uint8 GUI_ReadPoint(uint8 x,uint8 y,TCOLOR *ret)
{
uint8 bak;
if( x >= GUI_LCM_XMAX) return (0);
if( y >= GUI_LCM_YMAX) return (0);
bak = LCM_ReadByte(x,y);
if( (bak&(1<<(y&0x07))==0) )
{
*ret = 0x00;
}
else
{
*ret = 0x01;
}
return 1;
}
void GUI_HLine(uint8 x0,uint8 y0,uint8 x1,TCOLOR color)
{
uint8 bak;
if(x0>x1)
{
bak = x1;
x1 = x0;
x0 = bak;
}
do
{
GUI_Point(x0,y0,color);
x0++;
}
while(x1>=x0);
}
void GUI_RLine(uint8 x0,uint8 y0,uint8 y1,TCOLOR color)
{
uint8 bak;
uint8 wr_dat;
if(y0>y1)
{
bak = y1;
y1 = y0;
y0 = bak;
}
do
{
bak = LCM_ReadByte(x0,y0);
if( (y0>>3) != (y1>>3) )
{
wr_dat = 0xff<<(y0&0x07);
if(color)
{
wr_dat = bak | wr_dat;
}
else
{
wr_dat = ~wr_dat;
wr_dat = bak & wr_dat;
}
LCM_WriteByte(x0,y0,wr_dat);
y0 = (y0 + 8) & 0x38;
}
else
{
wr_dat = 0xff << (y0&0x07) ;
wr_dat = wr_dat & (0xff>>(7-(y1&0x07)));
if(color)
{
wr_dat = bak | wr_dat;
}
else
{
wr_dat = ~wr_dat;
wr_dat = bak & wr_dat;
}
LCM_WriteByte(x0,y0,wr_dat);
return;
}
}
while(y1>=y0);
}
void GUI_ClearSCR(void)
{
LCM_DispFill(0x00);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -