📄 lcd.c
字号:
#include"lpc214x.h"
#include"PCF8833.H"
#include"8x16.h"
#include"GB16x16.h"
#define LCD_RST 0x00000020
#define LCD_CS 0x00000080
#define LCD_DATA 0x00000040
#define LCD_CLK 0x00000010
void delay()
{
int a,b;
for(a=2000;a>0;a--)
for(b=100;b>0;b--)
;
}
void SPIINIT()
{
PCONP |= 0x00000100; //??SPI0??,?????
PINSEL0|= 0x00001100;// ?????????,?P0.4?P0.6???????
S0SPCCR = 0x08; // ??SPI?????
S0SPCR = 0x934; // ??SPI????? ,MSTR=1,CPOL=1,CPHA=1,LSBF=0
}
WriteCommand(INT8U data)
{
INT16U temp=data;
temp=temp&0xff;
IO0CLR=LCD_CS;
S0SPSR=0;
S0SPDR=temp;
while((S0SPSR&0x80) ==0);
IO0SET=LCD_CS;
}
WriteData(INT8U data)
{
INT16U temp=data;
temp=temp|0x100;
IO0CLR=LCD_CS;
S0SPSR=0;
S0SPDR=temp;
while((S0SPSR&0x80) ==0)
;
IO0SET=LCD_CS;
}
void PCF8833INIT()
{
PINSEL0 &= 0xFFFF003F;
IO0DIR=0X000000F0;
IO0SET=LCD_CS;
delay();
IO0CLR=LCD_RST;
delay();
IO0SET=LCD_RST;
delay();
IO0SET=LCD_DATA;
IO0SET=LCD_CLK;
delay();
SPIINIT();
WriteCommand(SOFT_RESET); //Temperature gradient set
WriteCommand(BOOSTER_ON); //Internal oscillation on
WriteCommand(SLEEP_OUT); //Sleep out
WriteCommand(COLOR_INTERFACE); //Partial display out
WriteData(COLOR_16_BIT);
WriteCommand(COLOR_SET); //256-color position set
WriteData(0x00);
WriteData(0x02);
WriteData(0x04);
WriteData(0x06);
WriteData(0x09);
WriteData(0x0B);
WriteData(0x0D);
WriteData(0x0F);
WriteData(0x00);
WriteData(0x02);
WriteData(0x04);
WriteData(0x06);
WriteData(0x09);
WriteData(0x0B);
WriteData(0x0D);
WriteData(0x0F);
WriteData(0x00);
WriteData(0x04);
WriteData(0x0B);
WriteData(0x0F);
WriteCommand(MEM_CONTROL); //Display contr
WriteData((0 << MEM_MX) | (1 << MEM_MY) | (1 << MEM_RGB) | (0 << MEM_VW) | (0 << MEM_LAO));
delay();
WriteCommand(DISPLAY_ON); //Display control
}
SetPageArea(char x1, char y1, char x2, char y2)
{
WriteCommand(SET_X_ADDR);
WriteData(x1);
WriteData(x2);
WriteCommand(SET_Y_ADDR);
WriteData(y1);
WriteData(y2);
WriteCommand(MEM_WRITE);
}
void PCF8833CLR()
{
unsigned int i;
SetPageArea(0, 0, GLCD_X_END, GLCD_Y_END);
for(i=0;i<(132*132);i++)
{
WriteData(0xFF);
WriteData(0xFF);
}
}
void PutChar(INT8U x, INT8U y, char c, INT16U f, INT16U b)
{
unsigned int i,j;
INT8U m;
INT8U fRed,fGreenBlue,bRed,bGreenBlue;
fRed = (f>>8) & 0xFF;
fGreenBlue = f & 0xFF;
bRed = (b>>8) & 0xFF;
bGreenBlue = b & 0xFF;
SetPageArea(x, y, x+8-1, y+16-1);
for(i=0; i<16;i++)
{
m=font[c*16+i];
for(j=0;j<8;j++)
{
if((m&0x80)==0x80)
{
WriteData(fRed);
WriteData(fGreenBlue);
}
else
{
WriteData(bRed);
WriteData(bGreenBlue);
}
m<<=1;
}
}
}
void PutString(INT8U x, INT8U y, char *s, INT16U f, INT16U b)
{
INT8U i=0;
while(*s)
{
PutChar(x+i*8,y,*s,f,b);
s++;i++;
if((x+i*8)>132)
{
i=0;
y=y+16;
if(y>132) y=0;
}
}
}
void PutGB1616(INT8U x, INT8U y, unsigned char *c, INT16U f,INT16U b)
{
INT32U i,j,a;
INT8U fRed,fGreenBlue,bRed,bGreenBlue;
INT8U m;
fRed = (f>>8) & 0xFF;
fGreenBlue = f & 0xFF;
bRed = (b>>8) & 0xFF;
bGreenBlue = b & 0xFF;
SetPageArea(x, y, x+16-1, y+16-1);
a=((*c-0xa1)*94+(*(c+1)-0xa1))*32;
for(i=a;i<a+32;i++)
{
m=data[i];
for(j=0;j<8;j++)
{
if((m&0x80)==0x80)
{
WriteData(fRed);
WriteData(fGreenBlue);
}
else
{
WriteData(bRed);
WriteData(bGreenBlue);
}
m<<=1;
}
}
}
void PutGBstring(INT8U x, INT8U y, unsigned char *c, INT16U f,INT16U b)
{
unsigned char s[2];
INT8U i,j;
i=0; j=0;
while(*c)
{
if((*c&0x80)!=0)
{
if((x+i*16+j*8)>112)
{
i=0;
j=0;
y=y+16;
x=0;
}
s[0]=*c;
s[1]=*(c+1);
PutGB1616(x+i*16+j*8,y,s,f,b);
i=i+1;
c=c+2;
}
else
{
if((x+i*16+j*8)>120)
{
i=0;
j=0;
y=y+16;
x=0;
}
s[0]=*c;
PutChar(x+i*16+j*8,y,*s,f,b);
j=j+1;
c=c+1;
}
if((x+i*16+j*8)>132)
{
i=0;
j=0;
y=y+16;
x=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -